From 7aacf0861e4d960cde7e62e0660c0e5a8b3f63e0 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Mon, 4 Dec 2023 10:23:19 +0100 Subject: [PATCH] inlay hint chores --- README.md | 2 +- src/dcd/client/client.d | 19 ++++++++++++++----- src/dcd/server/autocomplete/inlayhints.d | 1 + tests/tc_inlay_hints/expected.txt | 1 + tests/tc_inlay_hints/file.d | 17 +++++++++++++++++ tests/tc_inlay_hints/run.sh | 5 +++++ 6 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 tests/tc_inlay_hints/expected.txt create mode 100644 tests/tc_inlay_hints/file.d create mode 100755 tests/tc_inlay_hints/run.sh diff --git a/README.md b/README.md index 17c6102..1bc4397 100644 --- a/README.md +++ b/README.md @@ -326,7 +326,7 @@ more is planned. #### Example output - 42 ->MyAlias->MyType + l ->MyAlias->MyType 42 # Server diff --git a/src/dcd/client/client.d b/src/dcd/client/client.d index a798db8..207264e 100644 --- a/src/dcd/client/client.d +++ b/src/dcd/client/client.d @@ -86,7 +86,8 @@ int runClient(string[] args) getopt(args, "cursorPos|c", &cursorPos, "I", &addedImportPaths, "R", &removedImportPaths, "port|p", &port, "help|h", &help, "shutdown", &shutdown, "clearCache", &clearCache, - "symbolLocation|l", &symbolLocation, "doc|d", &doc, "inlayHints", &inlayHints, + "symbolLocation|l", &symbolLocation, "doc|d", &doc, + "inlayHints", &inlayHints, "query|status|q", &query, "search|s", &search, "version", &printVersion, "listImports", &listImports, "tcp", &useTCP, "socketFile", &socketFile, @@ -182,7 +183,7 @@ int runClient(string[] args) printImportList(response); return 0; } - else if (search == null && cursorPos == size_t.max) + else if (search == null && !inlayHints && cursorPos == size_t.max) { // cursor position is a required argument printHelp(args[0]); @@ -300,6 +301,10 @@ Options: Gets documentation comments associated with the symbol at the cursor location. + --inlayHints + For all supported variable usages, show value types. Currently shows + alias definitions. + --search | -s symbolName Searches for symbolName in both stdin / the given file name as well as others files cached by the server. @@ -393,9 +398,13 @@ void printInlayHintsResponse(ref const AutocompleteResponse response) { auto app = appender!(string[])(); foreach (ref completion; response.completions) - { - app.put(makeTabSeparated(completion.symbolLocation.to!string, completion.identifier)); - } + { + app.put(makeTabSeparated( + completion.kind == char.init ? "" : "" ~ completion.kind, + completion.identifier, + completion.symbolLocation.to!string + )); + } foreach (line; app.data) writeln(line); } diff --git a/src/dcd/server/autocomplete/inlayhints.d b/src/dcd/server/autocomplete/inlayhints.d index dc1aece..b5cd466 100644 --- a/src/dcd/server/autocomplete/inlayhints.d +++ b/src/dcd/server/autocomplete/inlayhints.d @@ -78,6 +78,7 @@ public AutocompleteResponse getInlayHints(const AutocompleteRequest request, { AutocompleteResponse.Completion c; c.symbolLocation = it.location - 1; + c.kind = CompletionKind.aliasName; DSymbol* type = it.type; diff --git a/tests/tc_inlay_hints/expected.txt b/tests/tc_inlay_hints/expected.txt new file mode 100644 index 0000000..a01907c --- /dev/null +++ b/tests/tc_inlay_hints/expected.txt @@ -0,0 +1 @@ +l ->Point 208 diff --git a/tests/tc_inlay_hints/file.d b/tests/tc_inlay_hints/file.d new file mode 100644 index 0000000..8df2e2f --- /dev/null +++ b/tests/tc_inlay_hints/file.d @@ -0,0 +1,17 @@ +// when extending the inlayHints capabilities, don't forget to update the --help +// text inside client.d + +import point; +import point : P = Point; + +void foo(int x, int y) {} +void foo(Point point) {} +void bar(P point, int z = 1) {} + +void main() +{ + P p; + foo(1, 2); + foo(p); + bar(p, 3); +} diff --git a/tests/tc_inlay_hints/run.sh b/tests/tc_inlay_hints/run.sh new file mode 100755 index 0000000..c35089d --- /dev/null +++ b/tests/tc_inlay_hints/run.sh @@ -0,0 +1,5 @@ +set -e +set -u + +../../bin/dcd-client $1 --inlayHints file.d > actual.txt +diff actual.txt expected.txt --strip-trailing-cr