diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2022-12-05 22:43:06 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2022-12-05 22:43:06 +0100 |
| commit | 983410d5821c98a05e4ce0a768cfaca908558487 (patch) | |
| tree | e937cde8a4808a749921dac866a9ce8bd35dd1e1 /src/server | |
| parent | 604cd2b24e67b207e3f976d642b347225103b177 (diff) | |
Begin adding support for goto on import stmt
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/check.odin | 4 | ||||
| -rw-r--r-- | src/server/definition.odin | 40 | ||||
| -rw-r--r-- | src/server/documents.odin | 7 | ||||
| -rw-r--r-- | src/server/hover.odin | 4 |
4 files changed, 48 insertions, 7 deletions
diff --git a/src/server/check.odin b/src/server/check.odin index 056783a..7d0c6ff 100644 --- a/src/server/check.odin +++ b/src/server/check.odin @@ -18,10 +18,6 @@ import "core:text/scanner" import "shared:common" -is_package :: proc(file: string, pkg: string) { - -} - check :: proc(uri: common.Uri, writer: ^Writer, config: ^common.Config) { data := make([]byte, mem.Kilobyte * 10, context.temp_allocator) diff --git a/src/server/definition.odin b/src/server/definition.odin index fbea155..786b676 100644 --- a/src/server/definition.odin +++ b/src/server/definition.odin @@ -16,6 +16,36 @@ import "core:os" import "shared:common" +get_all_package_file_locations :: proc( + document: ^Document, + import_decl: ^ast.Import_Decl, + locations: ^[dynamic]common.Location, +) -> bool { + path := "" + + for imp in document.imports { + if imp.original == import_decl.fullpath { + path = imp.name + } + } + + matches, err := filepath.glob( + fmt.tprintf("%v/*.odin", path), + context.temp_allocator, + ) + + for match in matches { + uri := common.create_uri(match, context.temp_allocator) + location := common.Location { + uri = uri.uri, + } + append(locations, location) + } + + return false + +} + get_definition_location :: proc( document: ^Document, position: common.Position, @@ -59,7 +89,15 @@ get_definition_location :: proc( ) } - if position_context.selector_expr != nil { + if position_context.import_stmt != nil { + if get_all_package_file_locations( + document, + position_context.import_stmt, + &locations, + ) { + return locations[:], true + } + } else if position_context.selector_expr != nil { //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 { diff --git a/src/server/documents.odin b/src/server/documents.odin index 7f99e52..1c281c0 100644 --- a/src/server/documents.odin +++ b/src/server/documents.odin @@ -24,8 +24,9 @@ ParserError :: struct { } Package :: struct { - name: string, //the entire absolute path to the directory - base: string, + name: string, //the entire absolute path to the directory + base: string, + original: string, } Document :: struct { @@ -471,6 +472,7 @@ parse_imports :: proc(document: ^Document, config: ^common.Config) { } import_: Package + import_.original = imp.fullpath import_.name = strings.clone( path.join( elems = {dir, p}, @@ -492,6 +494,7 @@ parse_imports :: proc(document: ^Document, config: ^common.Config) { } import_: Package + import_.original = imp.fullpath import_.name = path.join( elems = { document.package_name, diff --git a/src/server/hover.odin b/src/server/hover.odin index 602258d..635659e 100644 --- a/src/server/hover.odin +++ b/src/server/hover.odin @@ -96,6 +96,10 @@ get_hover_information :: proc( ) } + if position_context.import_stmt != nil { + return {}, false, true + } + if position_context.identifier != nil { if ident, ok := position_context.identifier.derived.(^ast.Ident); ok { if _, ok := common.keyword_map[ident.name]; ok { |