aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBradley Lewis <22850972+BradLewis@users.noreply.github.com>2025-09-08 21:10:15 -0400
committerGitHub <noreply@github.com>2025-09-08 21:10:15 -0400
commit976f77a125611fdd440f8e130378ce45f1dcbfa9 (patch)
tree2a7f11c7707c04e6c7f0d8b9aef68fc875414699 /src
parent6a10502edbc83373344ac252869a1e33e8032e0e (diff)
parent0749dd2d42145f2abf9e11825448a14a9bee5f62 (diff)
Merge pull request #986 from BradLewis/fix/ensure-selection-range-within-range
Ensure selection range is within the range for document symbols
Diffstat (limited to 'src')
-rw-r--r--src/server/document_symbols.odin28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/server/document_symbols.odin b/src/server/document_symbols.odin
index 5489207..2198eab 100644
--- a/src/server/document_symbols.odin
+++ b/src/server/document_symbols.odin
@@ -40,8 +40,7 @@ get_document_symbols :: proc(document: ^Document) -> []DocumentSymbol {
symbol: DocumentSymbol
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
+ ensure_selection_range_contained(&symbol.range, symbol.selectionRange)
symbol.name = k
#partial switch v in global.expr.derived {
@@ -82,18 +81,18 @@ get_document_symbols :: proc(document: ^Document) -> []DocumentSymbol {
if s, ok := resolve_type_expression(&ast_context, v); ok {
ranges :: struct {
range: common.Range,
- selectionRange: common.Range,
+ selection_range: 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 {
- selectionRange := common.get_token_range(name, ast_context.file.src)
+ selection_range := common.get_token_range(name, ast_context.file.src)
range := common.get_token_range(field_value, ast_context.file.src)
- range.start = selectionRange.start
+ ensure_selection_range_contained(&range, selection_range)
name_map[name.name] = {
range = range,
- selectionRange = selectionRange,
+ selection_range = selection_range,
}
}
}
@@ -105,7 +104,7 @@ get_document_symbols :: proc(document: ^Document) -> []DocumentSymbol {
child: DocumentSymbol
if range, ok := name_map[name]; ok {
child.range = range.range
- child.selectionRange = range.selectionRange
+ child.selectionRange = range.selection_range
child.name = name
child.kind = .Field
append(&children, child)
@@ -118,7 +117,7 @@ get_document_symbols :: proc(document: ^Document) -> []DocumentSymbol {
child: DocumentSymbol
if range, ok := name_map[name]; ok {
child.range = range.range
- child.selectionRange = range.selectionRange
+ child.selectionRange = range.selection_range
child.name = name
child.kind = .Field
append(&children, child)
@@ -137,3 +136,16 @@ get_document_symbols :: proc(document: ^Document) -> []DocumentSymbol {
return symbols[:]
}
+
+@(private="file")
+ensure_selection_range_contained :: proc(range: ^common.Range, selection_range: common.Range) {
+ // selection range must be contained with range, so we set the range start to be the selection range start
+ range.start = selection_range.start
+
+ // if the range end is somehow before the selection_range end, we set it to the end of the selection range
+ if range.end.line < selection_range.end.line {
+ range.end = selection_range.end
+ } else if range.end.line == selection_range.end.line && range.end.character < selection_range.end.character {
+ range.end = selection_range.end
+ }
+}