diff options
| author | Bradley Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-12-06 21:47:10 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-06 21:47:10 +1100 |
| commit | 265db94b731bdb7388e0d6af52fd8d9a0d93c01c (patch) | |
| tree | a1deac3120a803228317ec11c681a424f3f5ca0d /src/server/position_context.odin | |
| parent | 84e77e089c17a07bb5920b64083c2d983e9c654e (diff) | |
| parent | 59753fbf1f14b2aa2a211addc96730bbceef9a32 (diff) | |
Merge pull request #1205 from BradLewis/feat/add-attributes-to-position-context
Add attributes to position context
Diffstat (limited to 'src/server/position_context.odin')
| -rw-r--r-- | src/server/position_context.odin | 26 |
1 files changed, 25 insertions, 1 deletions
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 |