diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-05 13:25:11 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-05 13:32:46 -0400 |
| commit | 8a39fc31fc63d1100660566b6e2d8c92adf8bd16 (patch) | |
| tree | 10af8151648b76c3fb5cded64ad72df450f9b74e /src | |
| parent | f48480bdcac8062608c666e1b1e01cad04758f80 (diff) | |
Differentiate between `range` and `selectionRange` with document symbols
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/document_symbols.odin | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/server/document_symbols.odin b/src/server/document_symbols.odin index 6817cbd..5489207 100644 --- a/src/server/document_symbols.odin +++ b/src/server/document_symbols.odin @@ -38,8 +38,10 @@ get_document_symbols :: proc(document: ^Document) -> []DocumentSymbol { for k, global in ast_context.globals { symbol: DocumentSymbol - symbol.range = common.get_token_range(global.name_expr, ast_context.file.src) - symbol.selectionRange = symbol.range + symbol.selectionRange = common.get_token_range(global.name_expr, ast_context.file.src) + symbol.range = common.get_token_range(global.expr, ast_context.file.src) + // selection range must be contained with range, so we set the range start to be the selection range start + symbol.range.start = symbol.selectionRange.start symbol.name = k #partial switch v in global.expr.derived { @@ -78,11 +80,21 @@ get_document_symbols :: proc(document: ^Document) -> []DocumentSymbol { symbol.kind = .Enum case ^ast.Comp_Lit: if s, ok := resolve_type_expression(&ast_context, v); ok { - name_map := make(map[string]common.Range) + ranges :: struct { + range: common.Range, + selectionRange: common.Range, + } + name_map := make(map[string]ranges) for elem in v.elems { if field_value, ok := elem.derived.(^ast.Field_Value); ok { if name, ok := field_value.field.derived.(^ast.Ident); ok { - name_map[name.name] = common.get_token_range(name, ast_context.file.src) + selectionRange := common.get_token_range(name, ast_context.file.src) + range := common.get_token_range(field_value, ast_context.file.src) + range.start = selectionRange.start + name_map[name.name] = { + range = range, + selectionRange = selectionRange, + } } } } @@ -92,8 +104,8 @@ get_document_symbols :: proc(document: ^Document) -> []DocumentSymbol { for name, i in v.names { child: DocumentSymbol if range, ok := name_map[name]; ok { - child.range = range - child.selectionRange = range + child.range = range.range + child.selectionRange = range.selectionRange child.name = name child.kind = .Field append(&children, child) @@ -105,8 +117,8 @@ get_document_symbols :: proc(document: ^Document) -> []DocumentSymbol { for name, i in v.names { child: DocumentSymbol if range, ok := name_map[name]; ok { - child.range = range - child.selectionRange = range + child.range = range.range + child.selectionRange = range.selectionRange child.name = name child.kind = .Field append(&children, child) |