From aa8f2f45569fc25739d2a0496b363b1efd8f3505 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Thu, 30 Jun 2016 17:56:06 -0700 Subject: [PATCH] #326 --- containers | 2 +- libdparse | 2 +- src/client/client.d | 25 +++++++++++++++++++------ src/common/messages.d | 7 +++++-- src/server/autocomplete.d | 14 +++++++------- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/containers b/containers index c99dd0b..d3ce885 160000 --- a/containers +++ b/containers @@ -1 +1 @@ -Subproject commit c99dd0b83afe80d3b647f73e400fa4bb8e48aace +Subproject commit d3ce885de5a838347254cc41d702ffa53bbb3a5e diff --git a/libdparse b/libdparse index 99527e4..01d4217 160000 --- a/libdparse +++ b/libdparse @@ -1 +1 @@ -Subproject commit 99527e49cd194a2cf72da2154cc8b0d9ba30816d +Subproject commit 01d42177ca8fab5a0fea22f3f20873bc81e8257a diff --git a/src/client/client.d b/src/client/client.d index 7b98d82..2bd502a 100644 --- a/src/client/client.d +++ b/src/client/client.d @@ -49,6 +49,7 @@ int main(string[] args) bool query; bool printVersion; bool listImports; + bool getIdentifier; string search; version(Windows) { @@ -68,7 +69,8 @@ int main(string[] args) "clearCache", &clearCache, "symbolLocation|l", &symbolLocation, "doc|d", &doc, "query|status|q", &query, "search|s", &search, "version", &printVersion, "listImports", &listImports, - "tcp", &useTCP, "socketFile", &socketFile); + "tcp", &useTCP, "socketFile", &socketFile, + "getIdentifier", &getIdentifier); } catch (ConvException e) { @@ -204,11 +206,11 @@ int main(string[] args) request.cursorPosition = cursorPos; request.searchName = search; - if (symbolLocation) + if (symbolLocation | getIdentifier) request.kind |= RequestKind.symbolLocation; else if (doc) request.kind |= RequestKind.doc; - else if(search) + else if (search) request.kind |= RequestKind.search; else request.kind |= RequestKind.autocomplete; @@ -223,6 +225,8 @@ int main(string[] args) if (symbolLocation) printLocationResponse(response); + else if (getIdentifier) + printIdentifierResponse(response); else if (doc) printDocResponse(response); else if (search !is null) @@ -325,13 +329,22 @@ Socket createSocket(string socketFile, ushort port) return socket; } -void printDocResponse(AutocompleteResponse response) +void printDocResponse(ref const AutocompleteResponse response) { import std.array: join; response.docComments.join("\n").writeln; } -void printLocationResponse(AutocompleteResponse response) +void printIdentifierResponse(ref const AutocompleteResponse response) +{ + if (response.completions.length == 0) + return; + write(response.completions[0]); + write("\t"); + writeln(response.symbolIdentifier); +} + +void printLocationResponse(ref const AutocompleteResponse response) { if (response.symbolFilePath is null) writeln("Not found"); @@ -339,7 +352,7 @@ void printLocationResponse(AutocompleteResponse response) writefln("%s\t%d", response.symbolFilePath, response.symbolLocation); } -void printCompletionResponse(AutocompleteResponse response) +void printCompletionResponse(ref const AutocompleteResponse response) { if (response.completions.length > 0) { diff --git a/src/common/messages.d b/src/common/messages.d index 02a4f38..8dadfd7 100644 --- a/src/common/messages.d +++ b/src/common/messages.d @@ -55,7 +55,6 @@ enum CompletionType : string enum RequestKind : ushort { // dfmt off - uninitialized = 0b00000000_00000000, /// Autocompletion autocomplete = 0b00000000_00000001, @@ -75,7 +74,6 @@ enum RequestKind : ushort search = 0b00000000_10000000, /// List import directories listImports = 0b00000001_00000000, - // dfmt on } @@ -160,6 +158,11 @@ struct AutocompleteResponse * Import paths that are registered by the server. */ string[] importPaths; + + /** + * Symbol identifier + */ + ulong symbolIdentifier; } /** diff --git a/src/server/autocomplete.d b/src/server/autocomplete.d index 9a2c952..75e5169 100644 --- a/src/server/autocomplete.d +++ b/src/server/autocomplete.d @@ -783,7 +783,7 @@ DSymbol*[] getSymbolsByTokenChain(T)(Scope* completionScope, if (shouldSwapWithType(completionType, symbols[0].kind, 0, tokens.length - 1)) { - symbols = symbols[0].type is null ? [] : [symbols[0].type]; + symbols = symbols[0].type is null || symbols[0].type is symbols[0] ? [] : [symbols[0].type]; if (symbols.length == 0) return []; } @@ -849,7 +849,7 @@ DSymbol*[] getSymbolsByTokenChain(T)(Scope* completionScope, || symbols[0].kind == CompletionKind.importSymbol || symbols[0].kind == CompletionKind.aliasName) { - symbols = symbols[0].type is null ? [] : [symbols[0].type]; + symbols = symbols[0].type is null || symbols[0].type is symbols[0] ? [] : [symbols[0].type]; if (symbols.length == 0) break loop; } @@ -865,7 +865,7 @@ DSymbol*[] getSymbolsByTokenChain(T)(Scope* completionScope, } if (shouldSwapWithType(completionType, symbols[0].kind, i, tokens.length - 1)) { - symbols = symbols[0].type is null ? [] : [symbols[0].type]; + symbols = symbols[0].type is null || symbols[0].type is symbols[0] ? [] : [symbols[0].type]; if (symbols.length == 0) break loop; } @@ -874,7 +874,7 @@ DSymbol*[] getSymbolsByTokenChain(T)(Scope* completionScope, && (completionType == CompletionType.identifiers || i + 1 < tokens.length)) { - symbols = symbols[0].type is null ? [] : [symbols[0].type]; + symbols = symbols[0].type is null || symbols[0].type is symbols[0] ? [] : [symbols[0].type]; } if (symbols.length == 0) break loop; @@ -892,14 +892,14 @@ DSymbol*[] getSymbolsByTokenChain(T)(Scope* completionScope, skip(); if (!isSliceExpression(tokens, i)) { - symbols = symbols[0].type is null ? [] : [symbols[0].type]; + symbols = symbols[0].type is null || symbols[0].type is symbols[0] ? [] : [symbols[0].type]; if (symbols.length == 0) break loop; } } else if (symbols[0].qualifier == SymbolQualifier.assocArray) { - symbols = symbols[0].type is null ? [] : [symbols[0].type]; + symbols = symbols[0].type is null || symbols[0].type is symbols[0] ? [] : [symbols[0].type]; skip(); } else @@ -1001,7 +1001,7 @@ void setCompletions(T)(ref AutocompleteResponse response, { if (symbols[0].kind == CompletionKind.aliasName) { - if (symbols[0].type is null) + if (symbols[0].type is null || symbols[0].type is symbols[0]) return; symbols = [symbols[0].type]; }