diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2020-12-07 21:37:00 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2020-12-07 21:37:00 +0100 |
| commit | 9585a8c0d8f85f78696219b74e8353bbdaf3db4f (patch) | |
| tree | a6b7123663c1f301fe64e9212b3fffb6b1d48946 /src | |
| parent | 73600df80212cfcd1a9b6973da1553685f763eb8 (diff) | |
added support for relative importing
Diffstat (limited to 'src')
| -rw-r--r-- | src/index/collector.odin | 21 | ||||
| -rw-r--r-- | src/server/analysis.odin | 34 | ||||
| -rw-r--r-- | src/server/documents.odin | 26 |
3 files changed, 54 insertions, 27 deletions
diff --git a/src/index/collector.odin b/src/index/collector.odin index aeafc9b..e43b563 100644 --- a/src/index/collector.odin +++ b/src/index/collector.odin @@ -159,7 +159,7 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri forward, _ := filepath.to_slash(file.fullpath, context.temp_allocator); directory := strings.to_lower(path.dir(forward, context.temp_allocator), context.temp_allocator); - package_map := get_package_mapping(file, collection.config); + package_map := get_package_mapping(file, collection.config, uri); for decl in file.decls { @@ -262,7 +262,7 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri /* Gets the map from import alias to absolute package directory */ -get_package_mapping :: proc(file: ast.File, config: ^common.Config) -> map [string] string { +get_package_mapping :: proc(file: ast.File, config: ^common.Config, uri: string) -> map [string] string { package_map := make(map [string] string, 0, context.temp_allocator); @@ -298,6 +298,23 @@ get_package_mapping :: proc(file: ast.File, config: ^common.Config) -> map [stri else { + name: string; + + base := path.base(uri); + + full := path.join(elems = {base, imp.fullpath[1:len(imp.fullpath)-1]}, allocator = context.temp_allocator); + + full = path.clean(full, context.temp_allocator); + + if imp.name.text != "" { + name = imp.name.text; + } + + else { + name = path.base(full, false, context.temp_allocator); + } + + package_map[name] = strings.to_lower(full, context.temp_allocator); } } diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 146f8cb..b786597 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1889,6 +1889,12 @@ get_signature_information :: proc(document: ^Document, position: common.Position call: index.Symbol; call, ok = resolve_type_expression(&ast_context, position_context.call); + if symbol, ok := call.value.(index.SymbolProcedureValue); !ok { + return signature_help, true; + } + + + signature_information := make([] SignatureInformation, 1, context.temp_allocator); signature_information[0].label = concatenate_symbols_information(&ast_context, call); @@ -1996,36 +2002,16 @@ fallback_position_context_completion :: proc(document: ^Document, position: comm //log.info("FALLBACK TIME"); - log.infof("position character %c", position_context.file.src[position_context.position]); - paren_count: int; bracket_count: int; end: int; start: int; empty_dot: bool; - i := position_context.position; - - //trim whitespaces - for i >= 0 { - - c := position_context.file.src[i]; - - if c != ' ' && c != '\r' && c != '\n' { - break; - } - - i -= 1; - } - - if position_context.file.src[i] == ')' || - position_context.file.src[i] == '}' || - position_context.file.src[i] == '{' { - i -= 1; - } + i := position_context.position-1; end = i; - for i >= 0 { + for i > 0 { c := position_context.file.src[i]; @@ -2055,7 +2041,7 @@ fallback_position_context_completion :: proc(document: ^Document, position: comm bracket_count -= 1; } - if c == ' ' || c == '{' || c == ',' || c == '}' { + if c == ' ' || c == '{' || c == ',' || c == '}' || c == '\n' || c == '\r' { start = i+1; break; } @@ -2111,7 +2097,7 @@ fallback_position_context_signature :: proc(document: ^Document, position: commo first_paren: bool; i := position_context.position; - for i >= 0 { + for i > 0 { c := position_context.file.src[i]; diff --git a/src/server/documents.odin b/src/server/documents.odin index dedc74a..41700b0 100644 --- a/src/server/documents.odin +++ b/src/server/documents.odin @@ -387,6 +387,8 @@ parse_document :: proc(document: ^Document, config: ^common.Config) -> ([] Parse for imp, index in document.ast.imports { + //ERROR no completion on imp! + //collection specified if i := strings.index(imp.fullpath, ":"); i != -1 && i > 1 { @@ -402,12 +404,34 @@ parse_document :: proc(document: ^Document, config: ^common.Config) -> ([] Parse } document.imports[index].name = strings.clone(path.join(elems = {dir, p}, allocator = context.temp_allocator)); - document.imports[index].base = path.base(document.imports[index].name, false); + + if imp.name.text != "" { + document.imports[index].base = imp.name.text; + } + + else { + document.imports[index].base = path.base(document.imports[index].name, false); + } + } //relative else { + document.imports[index].name = path.join(elems = {document.package_name, imp.fullpath[1:len(imp.fullpath)-1]}, allocator = context.temp_allocator); + + document.imports[index].name = path.clean(document.imports[index].name); + + if imp.name.text != "" { + document.imports[index].base = imp.name.text; + } + + else { + document.imports[index].base = path.base(document.imports[index].name, false); + } + + //ERROR not showing signature + //log.info() } } |