Skip to content
This repository was archived by the owner on Mar 1, 2022. It is now read-only.

Commit e35560c

Browse files
committed
fix find declaration for end of identifier
1 parent e863ba4 commit e35560c

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

source/workspaced/com/dcd.d

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import std.string;
1616
import painlessjson;
1717

1818
import workspaced.api;
19+
import workspaced.helpers;
1920

2021
version (OSX) version = haveUnixSockets;
2122
version (linux) version = haveUnixSockets;
@@ -330,13 +331,17 @@ class DCDComponent : ComponentWrapper
330331
threads.create({
331332
try
332333
{
333-
if (!running)
334+
if (!running || pos >= code.length)
334335
{
335336
ret.finish(DCDDeclaration.init);
336337
return;
337338
}
338-
// Declarations should be returned for character *in front of* the cursor.
339-
auto pipes = doClient(["-c", (pos+1).to!string, "--symbolLocation"]);
339+
340+
// We need to move by one character on identifier characters to ensure the start character fits.
341+
if (!isIdentifierSeparatingChar(code[pos]))
342+
pos++;
343+
344+
auto pipes = doClient(["-c", pos.to!string, "--symbolLocation"]);
340345
scope (exit)
341346
{
342347
pipes.pid.wait();

source/workspaced/helpers.d

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ ptrdiff_t indexOfKeyword(string code, string keyword, ptrdiff_t start = 0)
5050
}
5151
return index;
5252
}
53+
54+
bool isIdentifierSeparatingChar(dchar c)
55+
{
56+
return c < 48 || (c > 57 && c < 65) || c == '[' || c == '\\' || c == ']'
57+
|| c == '`' || (c > 122 && c < 128) || c == '\u2028' || c == '\u2029'; // line separators
58+
}

0 commit comments

Comments
 (0)