From e35560cd701bc2e52c4c26d44ebd4a10580964c6 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Sat, 16 Feb 2019 15:43:21 +0100 Subject: [PATCH] fix find declaration for end of identifier --- source/workspaced/com/dcd.d | 11 ++++++++--- source/workspaced/helpers.d | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/source/workspaced/com/dcd.d b/source/workspaced/com/dcd.d index 910e339..68d1fb8 100644 --- a/source/workspaced/com/dcd.d +++ b/source/workspaced/com/dcd.d @@ -16,6 +16,7 @@ import std.string; import painlessjson; import workspaced.api; +import workspaced.helpers; version (OSX) version = haveUnixSockets; version (linux) version = haveUnixSockets; @@ -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(); diff --git a/source/workspaced/helpers.d b/source/workspaced/helpers.d index 57a84a6..4fddb64 100644 --- a/source/workspaced/helpers.d +++ b/source/workspaced/helpers.d @@ -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 +}