aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/server/file_resolve.odin4
-rw-r--r--src/server/position_context.odin26
-rw-r--r--tests/hover_test.odin13
-rw-r--r--tests/references_test.odin18
4 files changed, 60 insertions, 1 deletions
diff --git a/src/server/file_resolve.odin b/src/server/file_resolve.odin
index 1b7a5c5..c526030 100644
--- a/src/server/file_resolve.odin
+++ b/src/server/file_resolve.odin
@@ -463,15 +463,19 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) {
data.position_context.value_decl = n
reset_position_context(data.position_context)
+ resolve_nodes(n.attributes[:], data)
resolve_nodes(n.names, data)
resolve_node(n.type, data)
resolve_nodes(n.values, data)
case ^Package_Decl:
case ^Import_Decl:
+ resolve_nodes(n.attributes[:], data)
case ^Foreign_Block_Decl:
+ resolve_nodes(n.attributes[:], data)
resolve_node(n.foreign_library, data)
resolve_node(n.body, data)
case ^Foreign_Import_Decl:
+ resolve_nodes(n.attributes[:], data)
resolve_node(n.name, data)
case ^Proc_Group:
resolve_nodes(n.args, data)
diff --git a/src/server/position_context.odin b/src/server/position_context.odin
index 33de8f3..2792194 100644
--- a/src/server/position_context.odin
+++ b/src/server/position_context.odin
@@ -1,10 +1,10 @@
package server
-import "core:strings"
import "core:log"
import "core:odin/ast"
import "core:odin/parser"
import "core:odin/tokenizer"
+import "core:strings"
import "core:unicode/utf8"
import "src:common"
@@ -63,9 +63,33 @@ DocumentPositionContext :: struct {
call_commas: []int,
}
+
+get_stmt_attrs :: proc(decl: ^ast.Stmt) -> []^ast.Attribute {
+ if decl == nil {
+ return nil
+ }
+ #partial switch v in decl.derived {
+ case ^ast.Value_Decl:
+ return v.attributes[:]
+ case ^ast.Import_Decl:
+ return v.attributes[:]
+ case ^ast.Foreign_Block_Decl:
+ return v.attributes[:]
+ case ^ast.Foreign_Import_Decl:
+ return v.attributes[:]
+ }
+ return nil
+}
+
get_document_position_decls :: proc(decls: []^ast.Stmt, position_context: ^DocumentPositionContext) -> bool {
exists_in_decl := false
for decl in decls {
+ for attr in get_stmt_attrs(decl) {
+ if position_in_node(attr, position_context.position) {
+ get_document_position(attr, position_context)
+ return true
+ }
+ }
if position_in_node(decl, position_context.position) {
get_document_position(decl, position_context)
exists_in_decl = true
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index 8a54ad4..842360b 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -5852,6 +5852,19 @@ ast_hover_propagate_docs_alias_in_package_override :: proc(t: ^testing.T) {
test.expect_hover(t, &source, "my_package.bar :: proc()\n Overridden\n\n// Comment!")
}
+@(test)
+ast_hover_deferred_attributes :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ foo :: proc() {}
+
+ @(deferred_in = fo{*}o)
+ bar :: proc() {}
+ `,
+ }
+ test.expect_hover(t, &source, "test.foo :: proc()")
+}
+
/*
Waiting for odin fix
diff --git a/tests/references_test.odin b/tests/references_test.odin
index 021033b..7bd2dcc 100644
--- a/tests/references_test.odin
+++ b/tests/references_test.odin
@@ -1520,3 +1520,21 @@ ast_references_enum_with_enumerated_array :: proc(t: ^testing.T) {
test.expect_reference_locations(t, &source, locations[:])
}
+
+@(test)
+ast_references_deferred_attributes :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ foo :: proc() {}
+
+ @(deferred_in = fo{*}o)
+ bar :: proc() {}
+ `,
+ }
+ locations := []common.Location {
+ {range = {start = {line = 1, character = 2}, end = {line = 1, character = 5}}},
+ {range = {start = {line = 3, character = 18}, end = {line = 3, character = 21}}},
+ }
+
+ test.expect_reference_locations(t, &source, locations[:])
+}