Skip to content

Commit

Permalink
Fix autocomplete end not working for non-local functions
Browse files Browse the repository at this point in the history
Fixes #554
  • Loading branch information
JohnnyMorganz committed Jul 13, 2024
1 parent e46bf3a commit d9f7206
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix static linking with MSVC Runtime for release binaries
- Fixed clients that do not support pull diagnostics erroring with "server not yet received configuration for diagnostics"
- Don't show children in autocomplete for `:GetPropertyChangedSignal("")`
- Fixed autocomplete end not working for non-local functions

## [1.31.1] - 2024-07-07

Expand Down
24 changes: 14 additions & 10 deletions src/operations/Completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ void WorkspaceFolder::endAutocompletion(const lsp::CompletionParams& params)
if (ancestry.size() < 2)
return;

// Search backwards for the first node that is not an Error node
size_t currentNodeIndex = ancestry.size() - 1;
while (ancestry.at(currentNodeIndex)->is<Luau::AstStatError>() || ancestry.at(currentNodeIndex)->is<Luau::AstExprError>())
{
currentNodeIndex--;
if (currentNodeIndex < 1)
return;
}
// Remove error nodes from end of ancestry chain
while (ancestry.size() > 0 && (ancestry.back()->is<Luau::AstStatError>() || ancestry.back()->is<Luau::AstExprError>()))
ancestry.pop_back();

Luau::AstNode* currentNode = ancestry.at(currentNodeIndex);
if (!currentNode)
if (ancestry.size() == 0)
return;

Luau::AstNode* currentNode = ancestry.back();

// TODO: https://github.com/luau-lang/luau/issues/1328 causes the ast ancestry to be shorter than expected
if (auto globalFunc = currentNode->as<Luau::AstStatFunction>())
{
ancestry.push_back(globalFunc->func);
ancestry.push_back(globalFunc->func->body);
currentNode = globalFunc->func->body;
}

// We should only apply it if the line just above us is the start of the unclosed statement
// Otherwise, we insert ends in weird places if theirs an unclosed stat a while away
if (!currentNode->is<Luau::AstStatBlock>())
Expand Down

0 comments on commit d9f7206

Please sign in to comment.