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

Commit

Permalink
fix find declaration for end of identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Feb 16, 2019
1 parent e863ba4 commit e35560c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions source/workspaced/com/dcd.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import std.string;
import painlessjson;

import workspaced.api;
import workspaced.helpers;

version (OSX) version = haveUnixSockets;
version (linux) version = haveUnixSockets;
Expand Down Expand Up @@ -330,13 +331,17 @@ class DCDComponent : ComponentWrapper
threads.create({
try
{
if (!running)
if (!running || pos >= code.length)
{
ret.finish(DCDDeclaration.init);
return;
}
// Declarations should be returned for character *in front of* the cursor.
auto pipes = doClient(["-c", (pos+1).to!string, "--symbolLocation"]);

// We need to move by one character on identifier characters to ensure the start character fits.
if (!isIdentifierSeparatingChar(code[pos]))
pos++;

auto pipes = doClient(["-c", pos.to!string, "--symbolLocation"]);
scope (exit)
{
pipes.pid.wait();
Expand Down
6 changes: 6 additions & 0 deletions source/workspaced/helpers.d
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ ptrdiff_t indexOfKeyword(string code, string keyword, ptrdiff_t start = 0)
}
return index;
}

bool isIdentifierSeparatingChar(dchar c)
{
return c < 48 || (c > 57 && c < 65) || c == '[' || c == '\\' || c == ']'
|| c == '`' || (c > 122 && c < 128) || c == '\u2028' || c == '\u2029'; // line separators
}

0 comments on commit e35560c

Please sign in to comment.