Skip to content

Commit bbebd99

Browse files
committed
Fix documentSymbol selectionRange enclosed in range
1 parent 5452948 commit bbebd99

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- Fixed error in document symbols not conforming to specification - `selectionRange` will now be fully enclosed by `range`
12+
913
## [1.16.0] - 2023-01-29
1014

1115
### Added

src/operations/DocumentSymbol.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ struct DocumentSymbolsVisitor : public Luau::AstVisitor
2424
symbols.push_back(symbol);
2525
}
2626

27-
void createLocalSymbol(Luau::AstLocal* local)
27+
void createLocalSymbol(Luau::AstLocal* local, Luau::Location enclosingRange)
2828
{
2929
lsp::DocumentSymbol symbol;
3030
symbol.name = local->name.value;
3131
symbol.kind = lsp::SymbolKind::Variable;
32-
symbol.range = {textDocument->convertPosition(local->location.begin), textDocument->convertPosition(local->location.end)};
33-
symbol.selectionRange = symbol.range;
32+
symbol.range = {textDocument->convertPosition(enclosingRange.begin), textDocument->convertPosition(enclosingRange.end)};
33+
symbol.selectionRange = {textDocument->convertPosition(local->location.begin), textDocument->convertPosition(local->location.end)};
3434
addSymbol(symbol);
3535
}
3636

3737
bool visit(Luau::AstStatLocal* local) override
3838
{
3939
for (size_t i = 0; i < local->vars.size; ++i)
4040
{
41-
createLocalSymbol(local->vars.data[i]);
41+
createLocalSymbol(local->vars.data[i], local->location);
4242
// TODO: if the value assigned is a table, should we include its properties?
4343
}
4444
return false;
@@ -76,7 +76,7 @@ struct DocumentSymbolsVisitor : public Luau::AstVisitor
7676
symbol.name = alias->name.value;
7777
symbol.kind = lsp::SymbolKind::Interface;
7878
symbol.range = {textDocument->convertPosition(alias->location.begin), textDocument->convertPosition(alias->location.end)};
79-
symbol.selectionRange = symbol.range;
79+
symbol.selectionRange = {textDocument->convertPosition(alias->nameLocation.begin), textDocument->convertPosition(alias->nameLocation.end)};
8080
addSymbol(symbol);
8181
return false;
8282
}
@@ -91,18 +91,23 @@ struct DocumentSymbolsVisitor : public Luau::AstVisitor
9191
bool comma = false;
9292
for (auto* arg : func->args)
9393
{
94-
createLocalSymbol(arg);
94+
LUAU_ASSERT(func->argLocation);
95+
createLocalSymbol(arg, func->argLocation.value());
9596
if (comma)
9697
detail += ", ";
9798
detail += arg->name.value;
9899
comma = true;
99100
}
100101
if (func->vararg)
101102
{
103+
LUAU_ASSERT(func->argLocation);
102104
lsp::DocumentSymbol symbol;
103105
symbol.name = "...";
104106
symbol.kind = lsp::SymbolKind::Variable;
105-
symbol.range = {textDocument->convertPosition(func->varargLocation.begin), textDocument->convertPosition(func->varargLocation.end)};
107+
symbol.range = {textDocument->convertPosition(func->argLocation->begin), textDocument->convertPosition(func->argLocation->end)};
108+
symbol.selectionRange = {
109+
textDocument->convertPosition(func->varargLocation.begin), textDocument->convertPosition(func->varargLocation.end)};
110+
106111
addSymbol(symbol);
107112

108113
if (comma)

0 commit comments

Comments
 (0)