diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2021-05-06 17:08:07 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2021-05-06 17:08:07 +0200 |
| commit | 126553d5efff75d87c1a1505a42e922b5d13e9a9 (patch) | |
| tree | 469579cb3d9a0783e4efd5230748da1b52194fb4 /src/server | |
| parent | 9007c6fa37dff74c8abe2555f9da0420f0a81294 (diff) | |
started lazy creating signatures for procedures
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 10 | ||||
| -rw-r--r-- | src/server/completion.odin | 6 | ||||
| -rw-r--r-- | src/server/hover.odin | 2 | ||||
| -rw-r--r-- | src/server/signature.odin | 59 |
4 files changed, 64 insertions, 13 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index d7ac8ef..7cd4764 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1365,21 +1365,15 @@ make_symbol_procedure_from_ast :: proc(ast_context: ^AstContext, n: ^ast.Node, v arg_types := make([dynamic]^ast.Field, context.temp_allocator); if v.results != nil { - for ret in v.results.list { append(&return_types, ret); } - - symbol.returns = strings.concatenate({"(", string(ast_context.file.src[v.results.pos.offset:v.results.end.offset]), ")"}, context.temp_allocator); } if v.params != nil { - for param in v.params.list { append(&arg_types, param); } - - symbol.signature = strings.concatenate({"(", string(ast_context.file.src[v.params.pos.offset:v.params.end.offset]), ")"}, context.temp_allocator); } symbol.value = index.SymbolProcedureValue { @@ -2202,7 +2196,7 @@ get_signature :: proc(ast_context: ^AstContext, ident: ast.Ident, symbol: index. if i, ok := local.derived.(ast.Ident); ok { return get_signature(ast_context, i, symbol, true); } else { - return index.node_to_string(local); + return common.node_to_string(local); } } @@ -2210,7 +2204,7 @@ get_signature :: proc(ast_context: ^AstContext, ident: ast.Ident, symbol: index. if i, ok := global.expr.derived.(ast.Ident); ok { return get_signature(ast_context, i, symbol, true); } else { - return index.node_to_string(global.expr); + return common.node_to_string(global.expr); } } } diff --git a/src/server/completion.odin b/src/server/completion.odin index 66893e0..241548d 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -231,7 +231,7 @@ get_comp_lit_completion :: proc(ast_context: ^AstContext, position_context: ^Doc item := CompletionItem { label = resolved.name, kind = .Field, - detail = fmt.tprintf("%v.%v: %v", comp_symbol.name, resolved.name, index.node_to_string(v.types[i])), + detail = fmt.tprintf("%v.%v: %v", comp_symbol.name, resolved.name, common.node_to_string(v.types[i])), documentation = resolved.doc, }; @@ -364,7 +364,7 @@ get_selector_completion :: proc(ast_context: ^AstContext, position_context: ^Doc item := CompletionItem { label = name, kind = .Field, - detail = fmt.tprintf("%v.%v: %v", selector.name, name, index.node_to_string(v.types[i])), + detail = fmt.tprintf("%v.%v: %v", selector.name, name, common.node_to_string(v.types[i])), documentation = symbol.doc, }; @@ -374,7 +374,7 @@ get_selector_completion :: proc(ast_context: ^AstContext, position_context: ^Doc item := CompletionItem { label = symbol.name, kind = .Field, - detail = fmt.tprintf("%v: %v", name, index.node_to_string(v.types[i])), + detail = fmt.tprintf("%v: %v", name, common.node_to_string(v.types[i])), documentation = symbol.doc, }; diff --git a/src/server/hover.odin b/src/server/hover.odin index d14cd34..771c867 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -126,7 +126,7 @@ get_hover_information :: proc(document: ^Document, position: common.Position) -> if symbol, ok := resolve_type_expression(&ast_context, v.types[i]); ok { symbol.name = name; symbol.pkg = selector.name; - symbol.signature = index.node_to_string(v.types[i]); + symbol.signature = common.node_to_string(v.types[i]); hover.contents = write_hover_content(&ast_context, symbol); return hover, true; } diff --git a/src/server/signature.odin b/src/server/signature.odin index d084507..1c2f52f 100644 --- a/src/server/signature.odin +++ b/src/server/signature.odin @@ -47,6 +47,47 @@ ParameterInformation :: struct { label: string, } +/* + Lazily build the signature and returns from ast.Nodes +*/ +build_symbol_signature :: proc(symbol: ^index.Symbol) { + if value, ok := symbol.value.(index.SymbolProcedureValue); ok { + builder := strings.make_builder(context.temp_allocator); + + strings.write_string(&builder, "("); + for arg, i in value.arg_types { + strings.write_string(&builder, common.node_to_string(arg)); + if i != len(value.arg_types) - 1 { + strings.write_string(&builder, ", "); + } + } + strings.write_string(&builder, ")"); + + symbol.signature = strings.to_string(builder); + } +} + +build_symbol_return :: proc(symbol: ^index.Symbol) { + if value, ok := symbol.value.(index.SymbolProcedureValue); ok { + builder := strings.make_builder(context.temp_allocator); + + if len(value.return_types) == 0 { + return; + } + + strings.write_string(&builder, "("); + for arg, i in value.return_types { + strings.write_string(&builder, common.node_to_string(arg)); + if i != len(value.return_types) - 1 { + strings.write_string(&builder, ", "); + } + } + strings.write_string(&builder, ")"); + symbol.returns = strings.to_string(builder); + } +} + + get_signature_information :: proc(document: ^Document, position: common.Position) -> (SignatureHelp, bool) { signature_help: SignatureHelp; @@ -88,9 +129,19 @@ get_signature_information :: proc(document: ^Document, position: common.Position parameters := make([]ParameterInformation, len(value.arg_types), context.temp_allocator); for arg, i in value.arg_types { - parameters[i].label = common.get_ast_node_string(arg, document.ast.src); + + if arg.type != nil { + if _, is_ellipsis := arg.type.derived.(ast.Ellipsis); is_ellipsis { + signature_help.activeParameter = min(i, signature_help.activeParameter); + } + } + + parameters[i].label = common.node_to_string(arg); } + build_symbol_signature(&call); + build_symbol_return(&call); + info := SignatureInformation { label = concatenate_symbols_information(&ast_context, call, false), documentation = call.doc, @@ -100,6 +151,12 @@ get_signature_information :: proc(document: ^Document, position: common.Position } else if value, ok := call.value.(index.SymbolAggregateValue); ok { //function overloaded procedures for symbol in value.symbols { + + symbol := symbol; + + build_symbol_signature(&call); + build_symbol_return(&call); + info := SignatureInformation { label = concatenate_symbols_information(&ast_context, symbol, false), documentation = symbol.doc, |