mirror of
https://github.com/dlang-community/DCD.git
synced 2025-04-27 13:49:53 +03:00
minor adjustments
This commit is contained in:
parent
78740cc1b1
commit
642a0e0a14
5 changed files with 16 additions and 73 deletions
|
@ -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)");
|
|
||||||
}
|
|
|
@ -202,7 +202,7 @@ AutocompleteResponse dotCompletion(T)(T beforeTokens, const(Token)[] tokenArray,
|
||||||
}
|
}
|
||||||
else if (beforeTokens.length >= 2 && beforeTokens[$ - 1] == tok!".")
|
else if (beforeTokens.length >= 2 && beforeTokens[$ - 1] == tok!".")
|
||||||
significantTokenType = beforeTokens[$ - 2].type;
|
significantTokenType = beforeTokens[$ - 2].type;
|
||||||
else
|
else
|
||||||
return response;
|
return response;
|
||||||
|
|
||||||
switch (significantTokenType)
|
switch (significantTokenType)
|
||||||
|
|
|
@ -12,10 +12,7 @@ import dsymbol.builtin.names;
|
||||||
import std.string;
|
import std.string;
|
||||||
import dparse.lexer : tok;
|
import dparse.lexer : tok;
|
||||||
import std.regex;
|
import std.regex;
|
||||||
import dcd.server.autocomplete.calltip_utils;
|
|
||||||
import containers.hashset : HashSet;
|
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)
|
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)
|
AutocompleteResponse.Completion createCompletionForUFCS(const DSymbol* symbol)
|
||||||
{
|
{
|
||||||
return AutocompleteResponse.Completion(symbol.name, symbol.kind, "(UFCS) " ~ removeFirstArgumentOfFunction(
|
return AutocompleteResponse.Completion(symbol.name, symbol.kind, "(UFCS) " ~ symbol.callTip, symbol
|
||||||
symbol.callTip), symbol
|
|
||||||
.symbolFile, symbol
|
.symbolFile, symbol
|
||||||
.location, symbol
|
.location, symbol
|
||||||
.doc);
|
.doc);
|
||||||
|
@ -59,7 +55,8 @@ bool isInvalidForUFCSCompletion(const(DSymbol)* beforeDotSymbol)
|
||||||
*/
|
*/
|
||||||
DSymbol*[] getSymbolsForUFCS(Scope* completionScope, const(DSymbol)* beforeDotSymbol, size_t cursorPosition)
|
DSymbol*[] getSymbolsForUFCS(Scope* completionScope, const(DSymbol)* beforeDotSymbol, size_t cursorPosition)
|
||||||
{
|
{
|
||||||
if (beforeDotSymbol.isInvalidForUFCSCompletion) {
|
if (beforeDotSymbol.isInvalidForUFCSCompletion)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,11 +146,10 @@ SymbolStuff getSymbolsForCompletion(const AutocompleteRequest request,
|
||||||
auto expression = getExpression(beforeTokens);
|
auto expression = getExpression(beforeTokens);
|
||||||
auto symbols = getSymbolsByTokenChain(pair.scope_, expression,
|
auto symbols = getSymbolsByTokenChain(pair.scope_, expression,
|
||||||
request.cursorPosition, type);
|
request.cursorPosition, type);
|
||||||
if (symbols.length == 0 && doUFCSSearch(stringToken(beforeTokens.front), stringToken(beforeTokens.back))) {
|
if (symbols.length == 0 && doUFCSSearch(stringToken(beforeTokens.front), stringToken(beforeTokens.back))) {
|
||||||
// Let search for UFCS, since we got no hit
|
// Let search for UFCS, since we got no hit
|
||||||
symbols ~= getSymbolsByTokenChain(pair.scope_, getExpression([beforeTokens.back]),
|
symbols ~= getSymbolsByTokenChain(pair.scope_, getExpression([beforeTokens.back]), request.cursorPosition, type);
|
||||||
request.cursorPosition, type);
|
}
|
||||||
}
|
|
||||||
return SymbolStuff(symbols, pair.symbol, pair.scope_);
|
return SymbolStuff(symbols, pair.symbol, pair.scope_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,17 @@
|
||||||
module fooutils;
|
module fooutils;
|
||||||
|
|
||||||
struct Foo {
|
struct Foo {
|
||||||
void fooHey(){ }
|
void fooHey(){}
|
||||||
}
|
}
|
||||||
|
|
||||||
void u(Foo foo) {
|
void u(Foo foo) {}
|
||||||
}
|
void ufcsHello(ref Foo foo) {}
|
||||||
|
void ufcsBar(Foo foo, string mama) {}
|
||||||
void ufcsHello(ref Foo foo)
|
void ufcsBarRef(ref Foo foo, string mama) {}
|
||||||
{
|
void ufcsBarRefConst(ref const Foo foo, string mama) {}
|
||||||
}
|
|
||||||
|
|
||||||
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 ufcsBarRefConstWrapped(ref const(Foo) foo, string mama) {}
|
||||||
void ufcsBarRefImmuttableWrapped(ref immutable(Foo) foo, string mama) {}
|
void ufcsBarRefImmuttableWrapped(ref immutable(Foo) foo, string mama) {}
|
||||||
void ufcsBarScope(ref scope Foo foo, string mama) {}
|
void ufcsBarScope(ref scope Foo foo, string mama) {}
|
||||||
void ufcsBarReturnScope(return scope Foo foo, string mama) {}
|
void ufcsBarReturnScope(return scope Foo foo, string mama) {}
|
||||||
private void privateUfcsBar(Foo foo, string message) {}
|
private void ufcsBarPrivate(Foo foo, string message) {}
|
||||||
void notUfcsBar(string message) {}
|
void helloBar(string message) {}
|
Loading…
Add table
Add a link
Reference in a new issue