diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2021-12-02 18:20:37 +0100 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2021-12-02 18:20:37 +0100 |
| commit | 2f2ea17723be24d96e9f2f3043d668561f406b7b (patch) | |
| tree | 62689879b8abfd6910a27b50ee0b095ebd3f90c6 /src | |
| parent | 3e9f57f727123c2b2a6479493a2443aca77c3001 (diff) | |
Start working on goto with multiple locations(packages), and fix some odinfmt bugs.
Diffstat (limited to 'src')
| -rw-r--r-- | src/odin/printer/visit.odin | 18 | ||||
| -rw-r--r-- | src/server/definition.odin | 26 | ||||
| -rw-r--r-- | src/server/requests.odin | 16 | ||||
| -rw-r--r-- | src/server/types.odin | 1 |
4 files changed, 41 insertions, 20 deletions
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index e14eb8f..6c19902 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -207,9 +207,19 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) -> ^Do document = cons_with_opl(document, text_position(p, v.name.name, v.pos)) } - for path in v.fullpaths { - document = cons_with_opl(document, text(path)) + if len(v.fullpaths) > 1 { + document = cons_with_nopl(document, text("{")) + for path, i in v.fullpaths { + document = cons(document, text(path)) + if i != len(v.fullpaths) - 1 { + document = cons(document, cons(text(","), break_with_space())) + } + } + document = cons(document, text("}")) + } else if len(v.fullpaths) == 1 { + document = cons_with_nopl(document, text(v.fullpaths[0])) } + return document case Foreign_Block_Decl: document := empty() @@ -472,7 +482,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener } if uses_do && !p.config.convert_do { - document = cons(document, cons_with_opl(text("do"), visit_stmt(p, v.body, .If_Stmt, true))) + document = cons_with_nopl(document, cons_with_nopl(text("do"), visit_stmt(p, v.body, .If_Stmt, true))) } else { if uses_do { document = cons(document, newline(1)) @@ -915,7 +925,7 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) -> ^ set_source_position(p, v.body.pos) document = cons_with_nopl(document, group(visit_stmt(p, v.body, .Proc))) } else { - document = cons_with_opl(document, text("---")) + document = cons_with_nopl(document, text("---")) } return document diff --git a/src/server/definition.odin b/src/server/definition.odin index 6afd44e..6d44227 100644 --- a/src/server/definition.odin +++ b/src/server/definition.odin @@ -19,10 +19,12 @@ import "shared:common" import "shared:index" import "shared:analysis" -get_definition_location :: proc(document: ^common.Document, position: common.Position) -> (common.Location, bool) { +get_definition_location :: proc(document: ^common.Document, position: common.Position) -> ([]common.Location, bool) { using analysis; + locations := make([dynamic]common.Location, context.temp_allocator); + location: common.Location; ast_context := make_ast_context(document.ast, document.imports, document.package_name, document.uri.uri); @@ -33,7 +35,7 @@ get_definition_location :: proc(document: ^common.Document, position: common.Pos if !ok { log.warn("Failed to get position context"); - return location, false; + return {}, false; } get_globals(document.ast, &ast_context); @@ -60,9 +62,11 @@ get_definition_location :: proc(document: ^common.Document, position: common.Pos location.uri = resolved.uri; } - return location, true; + append(&locations, location); + + return locations[:], true; } else { - return location, false; + return {}, false; } } } @@ -78,7 +82,7 @@ get_definition_location :: proc(document: ^common.Document, position: common.Pos selector, ok = resolve_type_expression(&ast_context, position_context.selector); if !ok { - return location, false; + return {}, false; } field: string; @@ -107,12 +111,12 @@ get_definition_location :: proc(document: ^common.Document, position: common.Pos location.range = symbol.range; uri = symbol.uri; } else { - return location, false; + return {}, false; } } if !ok { - return location, false; + return {}, false; } } else if position_context.identifier != nil { @@ -120,10 +124,10 @@ get_definition_location :: proc(document: ^common.Document, position: common.Pos location.range = resolved.range; uri = resolved.uri; } else { - return location, false; + return {}, false; } } else { - return location, false; + return {}, false; } //if the symbol is generated by the ast we don't set the uri. @@ -133,5 +137,7 @@ get_definition_location :: proc(document: ^common.Document, position: common.Pos location.uri = uri; } - return location, true; + append(&locations, location) + + return locations[:], true; }
\ No newline at end of file diff --git a/src/server/requests.odin b/src/server/requests.odin index f80d7ea..1c9ea13 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -455,6 +455,8 @@ request_initialize :: proc (task: ^common.Task) { config.enable_hover = true; config.enable_format = true; config.enable_document_symbols = true; + config.formatter.characters = 90; + config.formatter.tabs = true; if uri, ok := common.parse_uri(project_uri, context.temp_allocator); ok { ols_config_path := path.join(elems = {uri.path, "ols.json"}, allocator = context.temp_allocator); @@ -629,17 +631,19 @@ request_definition :: proc (task: ^common.Task) { return; } - location, ok2 := get_definition_location(document, definition_params.position); + locations, ok2 := get_definition_location(document, definition_params.position); if !ok2 { log.warn("Failed to get definition location"); } - response := make_response_message( - params = location, - id = id); - - send_response(response, writer); + if len(locations) == 1 { + response := make_response_message(params = locations[0], id = id); + send_response(response, writer); + } else { + response := make_response_message(params = locations, id = id); + send_response(response, writer); + } } request_completion :: proc (task: ^common.Task) { diff --git a/src/server/types.odin b/src/server/types.odin index fe5200f..8ef11b8 100644 --- a/src/server/types.odin +++ b/src/server/types.odin @@ -19,6 +19,7 @@ ResponseParams :: union { ResponseInitializeParams, rawptr, common.Location, + []common.Location, CompletionList, SignatureHelp, []DocumentSymbol, |