From 642a0e0a14abb40acb63f5ab63e3efe6522a883c Mon Sep 17 00:00:00 2001 From: davu Date: Sun, 16 Oct 2022 20:47:53 +0200 Subject: [PATCH] minor adjustments --- src/dcd/server/autocomplete/calltip_utils.d | 40 ------------------- src/dcd/server/autocomplete/complete.d | 2 +- src/dcd/server/autocomplete/ufcs.d | 9 ++--- src/dcd/server/autocomplete/util.d | 9 ++--- tests/tc_ufcs_completions/fooutils/fooutils.d | 29 ++++---------- 5 files changed, 16 insertions(+), 73 deletions(-) delete mode 100644 src/dcd/server/autocomplete/calltip_utils.d diff --git a/src/dcd/server/autocomplete/calltip_utils.d b/src/dcd/server/autocomplete/calltip_utils.d deleted file mode 100644 index 200a696..0000000 --- a/src/dcd/server/autocomplete/calltip_utils.d +++ /dev/null @@ -1,40 +0,0 @@ -module dcd.server.autocomplete.calltip_utils; -import std.string; -import std.regex; -import std.range : empty; -import std.experimental.logger; -import std.algorithm : canFind; - -string removeFirstArgumentOfFunction(string callTip) -{ - auto parentheseSplit = callTip.split('('); - // has only one argument - if (!callTip.canFind(',')) - { - return parentheseSplit[0] ~ "()"; - } - auto commaSplit = parentheseSplit[1].split(','); - string newCallTip = callTip.replace((commaSplit[0] ~ ", "), ""); - return newCallTip; - -} - -unittest -{ - auto result = removeFirstArgumentOfFunction("void fooFunction(const(immutable(Foo)) foo)"); - assert(result, "void fooFunction()"); -} - -unittest -{ - auto result = removeFirstArgumentOfFunction( - "void fooFunction(const(immutable(Foo)) foo), string message"); - assert(result, "void fooFunction(string message)"); -} - -unittest -{ - auto result = removeFirstArgumentOfFunction( - "void fooFunction(const(immutable(Foo)) foo), string message, ref int age"); - assert(result, "void fooFunction(string message, ref int age)"); -} diff --git a/src/dcd/server/autocomplete/complete.d b/src/dcd/server/autocomplete/complete.d index 3086238..79bfa08 100644 --- a/src/dcd/server/autocomplete/complete.d +++ b/src/dcd/server/autocomplete/complete.d @@ -202,7 +202,7 @@ AutocompleteResponse dotCompletion(T)(T beforeTokens, const(Token)[] tokenArray, } else if (beforeTokens.length >= 2 && beforeTokens[$ - 1] == tok!".") significantTokenType = beforeTokens[$ - 2].type; - else + else return response; switch (significantTokenType) diff --git a/src/dcd/server/autocomplete/ufcs.d b/src/dcd/server/autocomplete/ufcs.d index 34d4e6c..f48893e 100644 --- a/src/dcd/server/autocomplete/ufcs.d +++ b/src/dcd/server/autocomplete/ufcs.d @@ -12,10 +12,7 @@ import dsymbol.builtin.names; import std.string; import dparse.lexer : tok; import std.regex; -import dcd.server.autocomplete.calltip_utils; import containers.hashset : HashSet; -import std.experimental.logger; -import std.algorithm.iteration : map; void lookupUFCS(Scope* completionScope, DSymbol* beforeDotSymbol, size_t cursorPosition, ref AutocompleteResponse response) { @@ -26,8 +23,7 @@ void lookupUFCS(Scope* completionScope, DSymbol* beforeDotSymbol, size_t cursorP AutocompleteResponse.Completion createCompletionForUFCS(const DSymbol* symbol) { - return AutocompleteResponse.Completion(symbol.name, symbol.kind, "(UFCS) " ~ removeFirstArgumentOfFunction( - symbol.callTip), symbol + return AutocompleteResponse.Completion(symbol.name, symbol.kind, "(UFCS) " ~ symbol.callTip, symbol .symbolFile, symbol .location, symbol .doc); @@ -59,7 +55,8 @@ bool isInvalidForUFCSCompletion(const(DSymbol)* beforeDotSymbol) */ DSymbol*[] getSymbolsForUFCS(Scope* completionScope, const(DSymbol)* beforeDotSymbol, size_t cursorPosition) { - if (beforeDotSymbol.isInvalidForUFCSCompletion) { + if (beforeDotSymbol.isInvalidForUFCSCompletion) + { return null; } diff --git a/src/dcd/server/autocomplete/util.d b/src/dcd/server/autocomplete/util.d index 7ba4cbb..f03bf04 100644 --- a/src/dcd/server/autocomplete/util.d +++ b/src/dcd/server/autocomplete/util.d @@ -146,11 +146,10 @@ SymbolStuff getSymbolsForCompletion(const AutocompleteRequest request, auto expression = getExpression(beforeTokens); auto symbols = getSymbolsByTokenChain(pair.scope_, expression, request.cursorPosition, type); - if (symbols.length == 0 && doUFCSSearch(stringToken(beforeTokens.front), stringToken(beforeTokens.back))) { - // Let search for UFCS, since we got no hit - symbols ~= getSymbolsByTokenChain(pair.scope_, getExpression([beforeTokens.back]), - request.cursorPosition, type); - } + if (symbols.length == 0 && doUFCSSearch(stringToken(beforeTokens.front), stringToken(beforeTokens.back))) { + // Let search for UFCS, since we got no hit + symbols ~= getSymbolsByTokenChain(pair.scope_, getExpression([beforeTokens.back]), request.cursorPosition, type); + } return SymbolStuff(symbols, pair.symbol, pair.scope_); } diff --git a/tests/tc_ufcs_completions/fooutils/fooutils.d b/tests/tc_ufcs_completions/fooutils/fooutils.d index 187f39d..4b06cfc 100644 --- a/tests/tc_ufcs_completions/fooutils/fooutils.d +++ b/tests/tc_ufcs_completions/fooutils/fooutils.d @@ -1,30 +1,17 @@ module fooutils; struct Foo { - void fooHey(){ } + void fooHey(){} } -void u(Foo foo) { -} - -void ufcsHello(ref Foo foo) -{ -} - -void ufcsBar(Foo foo, string mama) -{ -} - -void ufcsBarRef(ref Foo foo, string mama) -{ -} - -void ufcsBarRefConst(ref const Foo foo, string mama) -{ -} +void u(Foo foo) {} +void ufcsHello(ref Foo foo) {} +void ufcsBar(Foo foo, string mama) {} +void ufcsBarRef(ref Foo foo, string mama) {} +void ufcsBarRefConst(ref const Foo foo, string mama) {} void ufcsBarRefConstWrapped(ref const(Foo) foo, string mama) {} void ufcsBarRefImmuttableWrapped(ref immutable(Foo) foo, string mama) {} void ufcsBarScope(ref scope Foo foo, string mama) {} void ufcsBarReturnScope(return scope Foo foo, string mama) {} -private void privateUfcsBar(Foo foo, string message) {} -void notUfcsBar(string message) {} \ No newline at end of file +private void ufcsBarPrivate(Foo foo, string message) {} +void helloBar(string message) {} \ No newline at end of file