Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moving ufcs logic to dsymbol #723

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module dcd.server.autocomplete.ufcs;
module dsymbol.ufcs;

import dcd.server.autocomplete.util;
import dsymbol.symbol;
import dsymbol.scope_;
import dcd.common.messages;
import std.functional : unaryFun;
import std.algorithm;
import std.array;
Expand All @@ -28,21 +26,6 @@ enum string[string] INTEGER_PROMOTIONS = [

enum MAX_RECURSION_DEPTH = 50;

void lookupUFCS(Scope* completionScope, DSymbol* beforeDotSymbol, size_t cursorPosition, ref AutocompleteResponse response)
{
// UFCS completion
DSymbol*[] ufcsSymbols = getSymbolsForUFCS(completionScope, beforeDotSymbol, cursorPosition);
response.completions ~= map!(s => createCompletionForUFCS(s))(ufcsSymbols).array;
}

AutocompleteResponse.Completion createCompletionForUFCS(const DSymbol* symbol)
{
return AutocompleteResponse.Completion(symbol.name, CompletionKind.ufcsName, symbol.callTip, symbol
.symbolFile, symbol
.location, symbol
.doc);
}

// Check if beforeDotSymbol is null or void
bool isInvalidForUFCSCompletion(const(DSymbol)* beforeDotSymbol)
{
Expand Down Expand Up @@ -210,12 +193,6 @@ struct FilteredAppender(alias predicate, T:
assert(app.data == [1, 3, 5, 7, 9]);
}

bool doUFCSSearch(string beforeToken, string lastToken)
{
// we do the search if they are different from eachother
return beforeToken != lastToken;
}

void getUFCSParenCompletion(ref DSymbol*[] symbols, Scope* completionScope, istring firstToken, istring nextToken, size_t cursorPosition)
{
DSymbol* firstSymbol = completionScope.getFirstSymbolByNameAndCursor(
Expand Down
2 changes: 1 addition & 1 deletion src/dcd/server/autocomplete/complete.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import std.string;
import std.typecons;

import dcd.server.autocomplete.util;
import dcd.server.autocomplete.ufcs;

import dparse.lexer;
import dparse.rollback_allocator;
Expand All @@ -42,6 +41,7 @@ import dsymbol.modulecache;
import dsymbol.scope_;
import dsymbol.string_interning;
import dsymbol.symbol;
import dsymbol.ufcs;

import dcd.common.constants;
import dcd.common.messages;
Expand Down
23 changes: 22 additions & 1 deletion src/dcd/server/autocomplete/util.d
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import dsymbol.modulecache;
import dsymbol.scope_;
import dsymbol.string_interning;
import dsymbol.symbol;
import dcd.server.autocomplete.ufcs;
import dsymbol.ufcs;

enum ImportKind : ubyte
{
Expand Down Expand Up @@ -772,3 +772,24 @@ AutocompleteResponse.Completion makeSymbolCompletionInfo(const DSymbol* symbol,
return AutocompleteResponse.Completion(symbol.name, kind, definition,
symbol.symbolFile, symbol.location, symbol.doc);
}

void lookupUFCS(Scope* completionScope, DSymbol* beforeDotSymbol, size_t cursorPosition, ref AutocompleteResponse response)
{
// UFCS completion
DSymbol*[] ufcsSymbols = getSymbolsForUFCS(completionScope, beforeDotSymbol, cursorPosition);
response.completions ~= map!(s => createCompletionForUFCS(s))(ufcsSymbols).array;
}

AutocompleteResponse.Completion createCompletionForUFCS(const DSymbol* symbol)
{
return AutocompleteResponse.Completion(symbol.name, CompletionKind.ufcsName, symbol.callTip, symbol
.symbolFile, symbol
.location, symbol
.doc);
}

bool doUFCSSearch(string beforeToken, string lastToken)
{
// we do the search if they are different from eachother
return beforeToken != lastToken;
}