aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2022-08-15 13:31:13 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2022-08-15 13:31:13 +0200
commit440af34d87e4e92bd9968f677c1fd552054f476e (patch)
treecd3df39e0db3510ef70c07845fbca6d5a33a6e3d
parent1063fa3a6556bc15f374318d901e68e16526a14f (diff)
Fix hover and go to issue where selector base was the same name as field.
-rw-r--r--src/server/analysis.odin31
-rw-r--r--src/server/definition.odin2
-rw-r--r--src/server/hover.odin11
3 files changed, 23 insertions, 21 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index f82b907..0873be4 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1361,27 +1361,30 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (S
value = SymbolPackageValue {},
}
- return symbol, true
- } else {
- //part of the ast so we check the imports of the document
- for imp in ast_context.imports {
- if strings.compare(imp.base, node.name) == 0 {
- symbol := Symbol {
- type = .Package,
- pkg = imp.name,
- value = SymbolPackageValue {},
- }
+ try_build_package(symbol.pkg)
- return symbol, true
- }
- }
- }
+ return symbol, true
+ }
//last option is to check the index
if symbol, ok := lookup(node.name, ast_context.current_package); ok {
return resolve_symbol_return(ast_context, symbol)
}
+ for imp in ast_context.imports {
+ if strings.compare(imp.base, node.name) == 0 {
+ symbol := Symbol {
+ type = .Package,
+ pkg = imp.name,
+ value = SymbolPackageValue {},
+ }
+
+ try_build_package(symbol.pkg)
+
+ return symbol, true
+ }
+ }
+
//If we are resolving a symbol that is in the document package, then we'll check the builtin packages.
if ast_context.current_package == ast_context.document_package {
if symbol, ok := lookup(node.name, "$builtin"); ok {
diff --git a/src/server/definition.odin b/src/server/definition.odin
index 9a4660e..ad9e7a8 100644
--- a/src/server/definition.odin
+++ b/src/server/definition.odin
@@ -43,7 +43,7 @@ get_definition_location :: proc(document: ^Document, position: common.Position)
if base, ok := position_context.selector.derived.(^ast.Ident); ok && position_context.identifier != nil {
ident := position_context.identifier.derived.(^ast.Ident)
- if ident.name == base.name {
+ if position_in_node(base, position_context.position) {
if resolved, ok := resolve_location_identifier(&ast_context, ident^); ok {
location.range = resolved.range
diff --git a/src/server/hover.odin b/src/server/hover.odin
index 0a419dd..0e00fa0 100644
--- a/src/server/hover.odin
+++ b/src/server/hover.odin
@@ -98,11 +98,10 @@ get_hover_information :: proc(document: ^Document, position: common.Position) ->
ast_context.current_package = ast_context.document_package
//if the base selector is the client wants to go to.
- if base, ok := position_context.selector.derived.(^ast.Ident); ok && position_context.identifier != nil && position_in_node(position_context.selector, position_context.position) {
+ if base, ok := position_context.selector.derived.(^ast.Ident); ok && position_context.identifier != nil {
ident := position_context.identifier.derived.(^ast.Ident)^
- if ident.name == base.name {
-
+ if position_in_node(base, position_context.position) {
if resolved, ok := resolve_type_identifier(&ast_context, ident); ok {
resolved.signature = get_signature(&ast_context, ident, resolved)
resolved.name = ident.name
@@ -133,11 +132,12 @@ get_hover_information :: proc(document: ^Document, position: common.Position) ->
}
}
-
+ ast_context.current_package = selector.pkg
+
#partial switch v in selector.value {
case SymbolStructValue:
for name, i in v.names {
- if strings.compare(name, field) == 0 {
+ if name == field {
if symbol, ok := resolve_type_expression(&ast_context, v.types[i]); ok {
symbol.name = name //TODO refractor - never set symbol name after creation - change writer_hover_content
symbol.pkg = selector.name
@@ -150,7 +150,6 @@ get_hover_information :: proc(document: ^Document, position: common.Position) ->
case SymbolPackageValue:
if position_context.field != nil {
if ident, ok := position_context.field.derived.(^ast.Ident); ok {
- ast_context.current_package = selector.pkg
if symbol, ok := resolve_type_identifier(&ast_context, ident^); ok {
hover.contents = write_hover_content(&ast_context, symbol)
return hover, true, true