diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2021-12-25 13:43:58 +0100 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2021-12-25 13:43:58 +0100 |
| commit | bb1379a911f43134b8dc5ed9ec2eebb889b800fb (patch) | |
| tree | 8eb5090124d0bb4c18d353e1daf1d09d50531f8d /src/server/inlay_hints.odin | |
| parent | 74d5978d86d8da1e2f74727965d7d3d3b16c71f1 (diff) | |
add temp work
Diffstat (limited to 'src/server/inlay_hints.odin')
| -rw-r--r-- | src/server/inlay_hints.odin | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/server/inlay_hints.odin b/src/server/inlay_hints.odin new file mode 100644 index 0000000..7d96c84 --- /dev/null +++ b/src/server/inlay_hints.odin @@ -0,0 +1,82 @@ +package server + +import "core:odin/ast" +import "core:fmt" + +import "shared:common" +import "shared:analysis" +import "shared:index" + +//document +get_inlay_hints :: proc(document: ^common.Document) -> ([]InlayHint, bool) { + + using analysis; + + hints := make([dynamic]InlayHint, context.temp_allocator); + + ast_context := make_ast_context(document.ast, document.imports, document.package_name, document.uri.uri); + + Visit_Data :: struct { + calls: [dynamic]ast.Call_Expr, + } + + data := Visit_Data { + calls = make([dynamic]ast.Call_Expr, context.temp_allocator), + }; + + visit :: proc(visitor: ^ast.Visitor, node: ^ast.Node) -> ^ast.Visitor { + if node == nil || visitor == nil { + return nil; + } + + data := cast(^Visit_Data)visitor.data; + + if call, ok := node.derived.(ast.Call_Expr); ok { + append(&data.calls, call); + } + + return visitor; + } + + visitor := ast.Visitor { + data = &data, + visit = visit, + } + + for decl in document.ast.decls { + ast.walk(&visitor, decl); + } + + loop: for call in &data.calls { + symbol_arg_count := 0 + for arg in call.args { + if _, ok := arg.derived.(ast.Field); ok { + continue loop; + } + } + + if symbol, ok := resolve_type_expression(&ast_context, &call); ok { + if symbol_call, ok := symbol.value.(index.SymbolProcedureValue); ok { + for arg in symbol_call.arg_types { + for name in arg.names { + if symbol_arg_count >= len(call.args) { + continue loop; + } + + if ident, ok := name.derived.(ast.Ident); ok { + hint := InlayHint { + kind = "parameter", + label = fmt.tprintf("%v:", ident.name), + range = common.get_token_range(call.args[symbol_arg_count], string(document.text)), + } + append(&hints, hint); + } + symbol_arg_count += 1; + } + } + } + } + } + + return hints[:], true; +}
\ No newline at end of file |