diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2021-03-22 22:41:23 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2021-03-22 22:41:23 +0100 |
| commit | 8b7fa052b40149d6023f4f23b07116a4f3813ebc (patch) | |
| tree | 6c8cb86764140ace2b2a1d8a032f15b801d90708 /src/server | |
| parent | aab3b14f72276182412c070950dd5c6488177d21 (diff) | |
add directive completion(not context aware atm)
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 3 | ||||
| -rw-r--r-- | src/server/completion.odin | 7 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index ae7d510..62ab37c 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -41,6 +41,7 @@ DocumentPositionContext :: struct { function: ^ast.Proc_Lit, //used to help with type resolving in function scope selector: ^ast.Expr, //used for completion identifier: ^ast.Node, + tag: ^ast.Node, field: ^ast.Expr, //used for completion call: ^ast.Expr, //used for signature help returns: ^ast.Return_Stmt, //used for completion @@ -2184,6 +2185,8 @@ fallback_position_context_completion :: proc(document: ^Document, position: comm position_context.field = s.field; } else if s, ok := e.derived.(ast.Implicit_Selector_Expr); ok { position_context.implicit = true; + } else if s, ok := e.derived.(ast.Tag_Expr); ok { + position_context.tag = s.expr; } else if bad_expr, ok := e.derived.(ast.Bad_Expr); ok { //this is most likely because of use of 'in', 'context', etc. //try to go back one dot. diff --git a/src/server/completion.odin b/src/server/completion.odin index bd0e1f5..1c49fd4 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -22,6 +22,7 @@ Completion_Type :: enum { Switch_Type, Identifier, Comp_Lit, + Directive, } get_completion_list :: proc(document: ^Document, position: common.Position) -> (CompletionList, bool) { @@ -55,6 +56,10 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> ( completion_type = .Selector; } + if position_context.tag != nil { + completion_type = .Directive; + } + if position_context.switch_type_stmt != nil && position_context.case_clause != nil { if assign, ok := position_context.switch_type_stmt.tag.derived.(ast.Assign_Stmt); ok && assign.rhs != nil && len(assign.rhs) == 1 { @@ -79,6 +84,8 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> ( get_selector_completion(&ast_context, &position_context, &list); case .Switch_Type: get_type_switch_Completion(&ast_context, &position_context, &list); + case .Directive: + get_directive_completion(&ast_context, &position_context, &list); } return list, true; |