what if we didn't parse the document for every token in the document

This commit is contained in:
brianush1 2023-12-10 12:45:19 -05:00
parent 584b245c8b
commit 51ad21d3e0
1 changed files with 4 additions and 3 deletions

View File

@ -57,12 +57,13 @@ public AutocompleteResponse findLocalUse(AutocompleteRequest request,
config.fileName = ""; config.fileName = "";
const(Token)[] tokenArray = getTokensForParser(cast(ubyte[]) request.sourceCode, const(Token)[] tokenArray = getTokensForParser(cast(ubyte[]) request.sourceCode,
config, &cache); config, &cache);
SymbolStuff getSymbolsAtCursor(size_t cursorPosition)
{
auto sortedTokens = assumeSorted(tokenArray); auto sortedTokens = assumeSorted(tokenArray);
auto beforeTokens = sortedTokens.lowerBound(cursorPosition);
ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray,
&rba, request.cursorPosition, moduleCache); &rba, request.cursorPosition, moduleCache);
SymbolStuff getSymbolsAtCursor(size_t cursorPosition)
{
auto beforeTokens = sortedTokens.lowerBound(cursorPosition);
auto expression = getExpression(beforeTokens); auto expression = getExpression(beforeTokens);
return SymbolStuff(getSymbolsByTokenChain(pair.scope_, expression, return SymbolStuff(getSymbolsByTokenChain(pair.scope_, expression,
cursorPosition, CompletionType.location), pair.symbol, pair.scope_); cursorPosition, CompletionType.location), pair.symbol, pair.scope_);