Skip to content

Commit

Permalink
Sync to upstream Luau 0.599
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyMorganz committed Oct 14, 2023
1 parent 0de2260 commit c0aa1cb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed

- Sync to upstream Luau 0.597
- Sync to upstream Luau 0.599
- Prioritise `game:GetService()` as the first autocompletion entry when typing `game:`
- Code blocks in hover and documentation now use `luau` as the syntax highlighting

Expand Down
2 changes: 1 addition & 1 deletion luau
Submodule luau updated from 1d0b44 to 24fdac
71 changes: 58 additions & 13 deletions src/operations/Completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "LSP/LuauExt.hpp"
#include "LSP/DocumentationParser.hpp"

LUAU_FASTFLAG(LuauClipExtraHasEndProps);
LUAU_FASTFLAG(LuauAutocompleteDoEnd);

/// Defining sort text levels assigned to completion items
/// Note that sort text is lexicographically
namespace SortText
Expand Down Expand Up @@ -100,24 +103,66 @@ void WorkspaceFolder::endAutocompletion(const lsp::CompletionParams& params)
return;

auto unclosedBlock = false;
for (auto it = ancestry.rbegin(); it != ancestry.rend(); ++it)
if (FFlag::LuauClipExtraHasEndProps)
{
if (auto* statForIn = (*it)->as<Luau::AstStatForIn>(); statForIn && !statForIn->hasEnd)
unclosedBlock = true;
if (auto* statFor = (*it)->as<Luau::AstStatFor>(); statFor && !statFor->hasEnd)
unclosedBlock = true;
if (auto* statIf = (*it)->as<Luau::AstStatIf>(); statIf && !statIf->hasEnd)
unclosedBlock = true;
if (auto* statWhile = (*it)->as<Luau::AstStatWhile>(); statWhile && !statWhile->hasEnd)
unclosedBlock = true;
if (auto* statBlock = (*it)->as<Luau::AstStatBlock>(); statBlock && !statBlock->hasEnd)
unclosedBlock = true;
if (auto* exprFunction = (*it)->as<Luau::AstExprFunction>(); exprFunction && !exprFunction->hasEnd)
unclosedBlock = true;
for (auto it = ancestry.rbegin(); it != ancestry.rend(); ++it)
{
if (auto* statForIn = (*it)->as<Luau::AstStatForIn>(); statForIn && !statForIn->body->hasEnd)
unclosedBlock = true;
else if (auto* statFor = (*it)->as<Luau::AstStatFor>(); statFor && !statFor->body->hasEnd)
unclosedBlock = true;
else if (auto* statIf = (*it)->as<Luau::AstStatIf>())
{
bool hasEnd = statIf->thenbody->hasEnd;
if (statIf->elsebody)
{
if (auto* elseBlock = statIf->elsebody->as<Luau::AstStatBlock>())
hasEnd = elseBlock->hasEnd;
}

if (!hasEnd)
unclosedBlock = true;
}
else if (auto* statWhile = (*it)->as<Luau::AstStatWhile>(); statWhile && !statWhile->body->hasEnd)
unclosedBlock = true;
else if (auto* exprFunction = (*it)->as<Luau::AstExprFunction>(); exprFunction && !exprFunction->body->hasEnd)
unclosedBlock = true;
if (FFlag::LuauAutocompleteDoEnd)
{
if (auto* exprBlock = (*it)->as<Luau::AstStatBlock>(); exprBlock && !exprBlock->hasEnd)
unclosedBlock = true;

// FIX: if the unclosedBlock came from a repeat, then don't autocomplete, as it will be wrong!
if (auto* statRepeat = (*it)->as<Luau::AstStatRepeat>(); statRepeat && !statRepeat->body->hasEnd)
unclosedBlock = false;
}
}
}
else
{
for (auto it = ancestry.rbegin(); it != ancestry.rend(); ++it)
{
if (auto* statForIn = (*it)->as<Luau::AstStatForIn>(); statForIn && !statForIn->DEPRECATED_hasEnd)
unclosedBlock = true;
if (auto* statFor = (*it)->as<Luau::AstStatFor>(); statFor && !statFor->DEPRECATED_hasEnd)
unclosedBlock = true;
if (auto* statIf = (*it)->as<Luau::AstStatIf>(); statIf && !statIf->DEPRECATED_hasEnd)
unclosedBlock = true;
if (auto* statWhile = (*it)->as<Luau::AstStatWhile>(); statWhile && !statWhile->DEPRECATED_hasEnd)
unclosedBlock = true;
if (FFlag::LuauAutocompleteDoEnd)
{
if (auto* statBlock = (*it)->as<Luau::AstStatBlock>(); statBlock && !statBlock->hasEnd)
unclosedBlock = true;
}
if (auto* exprFunction = (*it)->as<Luau::AstExprFunction>(); exprFunction && !exprFunction->DEPRECATED_hasEnd)
unclosedBlock = true;
}
}

// TODO: we could potentially extend this further that just `hasEnd`
// by inserting `then`, `until` `do` etc. It seems Studio does this
// NOTE: `until` can be inserted if `hasEnd` in a repeat block is false

if (unclosedBlock)
{
Expand Down

0 comments on commit c0aa1cb

Please sign in to comment.