aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2022-04-11 21:08:01 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2022-04-11 21:08:01 +0200
commit789daf0a87994f9b131308c52cea70df21de4d61 (patch)
tree5284ad84917faaa11409d4ba462af359145fc651
parent144d2b3e36d3dca77b8531dc0136ba084b530d54 (diff)
Fix windows issue with package lower and uppercase
-rw-r--r--src/common/ast.odin1
-rw-r--r--src/server/analysis.odin23
-rw-r--r--src/server/build.odin3
-rw-r--r--src/server/collector.odin58
-rw-r--r--src/server/completion.odin7
-rw-r--r--src/server/documents.odin10
-rw-r--r--src/server/inlay_hints.odin1
-rw-r--r--src/server/on_typing.odin1
-rw-r--r--src/server/reference.odin8
-rw-r--r--src/server/references.odin41
-rw-r--r--src/testing/testing.odin14
-rw-r--r--tests/completions_test.odin35
12 files changed, 124 insertions, 78 deletions
diff --git a/src/common/ast.odin b/src/common/ast.odin
index 3f5dfed..c8398ae 100644
--- a/src/common/ast.odin
+++ b/src/common/ast.odin
@@ -62,6 +62,7 @@ keyword_map: map[string]bool = {
"quaternion64" = true,
"quaternion128" = true,
"quaternion256" = true,
+ "uintptr" = true,
}
GlobalExpr :: struct {
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 3ef9733..7ad405b 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1019,7 +1019,11 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (S
ast_context.current_package = selector.pkg
if v.field != nil {
- return resolve_symbol_return(ast_context, lookup(v.field.name, selector.pkg))
+ when ODIN_OS == .Windows {
+ return resolve_symbol_return(ast_context, lookup(v.field.name, strings.to_lower(selector.pkg, context.temp_allocator)))
+ } else {
+ return resolve_symbol_return(ast_context, lookup(v.field.name, selector.pkg))
+ }
} else {
return Symbol {}, false
}
@@ -1368,21 +1372,6 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (S
return Symbol {}, false
}
-resolve_ident_is_package :: proc(ast_context: ^AstContext, node: ast.Ident) -> bool {
- if strings.contains(node.name, "/") {
- return true
- } else {
- for imp in ast_context.imports {
-
- if imp.base == node.name {
- return true
- }
- }
- }
-
- return false
-}
-
expand_struct_usings :: proc(ast_context: ^AstContext, symbol: Symbol, value: SymbolStructValue) -> SymbolStructValue {
names := slice.to_dynamic(value.names, ast_context.allocator)
types := slice.to_dynamic(value.types, ast_context.allocator)
@@ -1629,9 +1618,7 @@ get_using_packages :: proc(ast_context: ^AstContext) -> []string {
//probably map instead
for u, i in ast_context.usings {
-
for imp in ast_context.imports {
-
if strings.compare(imp.base, u) == 0 {
usings[i] = imp.name
}
diff --git a/src/server/build.odin b/src/server/build.odin
index c9edf93..b4a6238 100644
--- a/src/server/build.odin
+++ b/src/server/build.odin
@@ -195,6 +195,9 @@ build_static_index :: proc(allocator := context.allocator, config: ^common.Confi
delete(fullpath, allocator)
}
+
+
+ log.error(symbol_collection.references)
delete(files)
delete(temp_arena.data)
diff --git a/src/server/collector.odin b/src/server/collector.odin
index e049c66..cf7e629 100644
--- a/src/server/collector.odin
+++ b/src/server/collector.odin
@@ -54,6 +54,13 @@ delete_symbol_collection :: proc(collection: SymbolCollection) {
}
}
+ for k, v in collection.references {
+ for k2, v2 in v {
+ common.free_ast(v2.identifiers, collection.allocator)
+ common.free_ast(v2.selectors, collection.allocator)
+ }
+ }
+
for k, v in collection.unique_strings {
delete(v, collection.allocator)
}
@@ -62,6 +69,11 @@ delete_symbol_collection :: proc(collection: SymbolCollection) {
delete(v)
}
+ for k, v in collection.references {
+ delete(v)
+ }
+
+ delete(collection.references)
delete(collection.packages)
delete(collection.unique_strings)
}
@@ -362,7 +374,6 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
symbol.range = common.get_token_range(token, file.src)
symbol.name = get_index_unique_string(collection, name)
- symbol.pkg = get_index_unique_string(collection, directory)
symbol.type = token_type
symbol.doc = common.get_doc(expr.docs, collection.allocator)
@@ -408,6 +419,51 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
return .None
}
+Reference :: struct {
+ identifiers: [dynamic]^ast.Ident,
+ selectors: [dynamic]^ast.Selector_Expr,
+}
+
+collect_references :: proc(collection: ^SymbolCollection, file: ast.File, uri: string) -> common.Error {
+ document := common.Document {
+ ast = file,
+ }
+
+ uri, ok := common.parse_uri(uri, context.temp_allocator)
+
+ if !ok {
+ return .ParseError
+ }
+
+ document.uri = uri
+ document.text = transmute([]u8)file.src
+ document.used_text = len(file.src)
+ document.allocator = document_get_allocator()
+
+ context.allocator = common.scratch_allocator(document.allocator)
+
+ parse_imports(&document, &common.config)
+
+ symbols_and_nodes := resolve_entire_file(&document, common.scratch_allocator(document.allocator))
+
+ for k, v in symbols_and_nodes {
+ if pkg, ok := &collection.references[v.symbol.pkg]; ok {
+ if ref, ok := &pkg[v.symbol.name]; ok {
+ if ident, ok := v.node.derived.(^ast.Ident); ok {
+ //append(&ref.identifiers, cast(^ast.Ident)clone_type(ident, collection.allocator, nil))
+ } else if selector, ok := v.node.derived.(^ast.Selector_Expr); ok {
+ //append(&ref.selectors, cast(^ast.Selector_Expr)clone_type(selector, collection.allocator, nil))
+ }
+ }
+ }
+ }
+
+ document_free_allocator(document.allocator)
+
+ return .None
+}
+
+
/*
Gets the map from import alias to absolute package directory
*/
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 40018b1..d5bdb6e 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -33,7 +33,6 @@ Completion_Type :: enum {
}
get_completion_list :: proc(document: ^common.Document, position: common.Position, completion_context: CompletionContext) -> (CompletionList, bool) {
-
list: CompletionList
position_context, ok := get_document_position_context(document, position, .Completion)
@@ -51,7 +50,7 @@ get_completion_list :: proc(document: ^common.Document, position: common.Positio
get_globals(document.ast, &ast_context)
ast_context.current_package = ast_context.document_package
- ast_context.value_decl = position_context.value_decl
+ ast_context.value_decl = position_context.value_decl
if position_context.function != nil {
get_locals(document.ast, position_context.function, &ast_context, &position_context)
@@ -202,7 +201,6 @@ get_comp_lit_completion :: proc(ast_context: ^AstContext, position_context: ^Doc
}
get_selector_completion :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext, list: ^CompletionList) {
-
items := make([dynamic]CompletionItem, context.temp_allocator)
ast_context.current_package = ast_context.document_package
@@ -780,7 +778,6 @@ get_implicit_completion :: proc(ast_context: ^AstContext, position_context: ^Doc
}
get_identifier_completion :: proc(ast_context: ^AstContext, position_context: ^DocumentPositionContext, list: ^CompletionList) {
-
items := make([dynamic]CompletionItem, context.temp_allocator)
list.isIncomplete = true
@@ -1252,7 +1249,7 @@ append_magic_map_completion :: proc(position_context: ^DocumentPositionContext,
detail = "for",
additionalTextEdits = additionalTextEdits,
textEdit = TextEdit {
- newText = fmt.tprintf("for k, v in %v {{\n\t$0 \n}}", symbol.name),
+ newText = fmt.tprintf("for ${{1:k}}, ${{2:v}} in %v {{\n\t$0 \n}}", symbol.name),
range = {
start = range.end,
end = range.end,
diff --git a/src/server/documents.odin b/src/server/documents.odin
index 0c18249..dfcf9fd 100644
--- a/src/server/documents.odin
+++ b/src/server/documents.odin
@@ -342,6 +342,12 @@ parse_document :: proc(document: ^common.Document, config: ^common.Config) -> ([
parser.parse_file(&p, &document.ast)
+ parse_imports(document, config)
+
+ return current_errors[:], true
+}
+
+parse_imports :: proc(document: ^common.Document, config: ^common.Config) {
imports := make([dynamic]common.Package)
when ODIN_OS == .Windows {
@@ -407,6 +413,4 @@ parse_document :: proc(document: ^common.Document, config: ^common.Config) -> ([
}
document.imports = imports[:]
-
- return current_errors[:], true
-}
+} \ No newline at end of file
diff --git a/src/server/inlay_hints.odin b/src/server/inlay_hints.odin
index b8f4024..eb93075 100644
--- a/src/server/inlay_hints.odin
+++ b/src/server/inlay_hints.odin
@@ -5,7 +5,6 @@ import "core:fmt"
import "shared:common"
-//document
get_inlay_hints :: proc(document: ^common.Document, symbols: map[uintptr]SymbolAndNode) -> ([]InlayHint, bool) {
hints := make([dynamic]InlayHint, context.temp_allocator)
diff --git a/src/server/on_typing.odin b/src/server/on_typing.odin
deleted file mode 100644
index abb4e43..0000000
--- a/src/server/on_typing.odin
+++ /dev/null
@@ -1 +0,0 @@
-package server
diff --git a/src/server/reference.odin b/src/server/reference.odin
new file mode 100644
index 0000000..bd2f566
--- /dev/null
+++ b/src/server/reference.odin
@@ -0,0 +1,8 @@
+package server
+
+
+import "shared:common"
+
+import "core:strings"
+import "core:odin/ast"
+import path "core:path/slashpath"
diff --git a/src/server/references.odin b/src/server/references.odin
deleted file mode 100644
index 86645b1..0000000
--- a/src/server/references.odin
+++ /dev/null
@@ -1,41 +0,0 @@
-package server
-
-
-import "shared:common"
-
-import "core:strings"
-import "core:odin/ast"
-import path "core:path/slashpath"
-
-
-Reference :: struct {
- identifiers: [dynamic]^ast.Ident,
- selectors: [dynamic]^ast.Selector_Expr,
-}
-
-collect_references :: proc(collection: ^SymbolCollection, file: ast.File, uri: string) -> common.Error {
- document := common.Document {
- ast = file,
- }
-
- uri, ok := common.parse_uri(uri, context.temp_allocator)
-
- if !ok {
- return .ParseError
- }
-
- when ODIN_OS == .Windows {
- document.package_name = strings.to_lower(path.dir(document.uri.path, context.temp_allocator))
- } else {
- document.package_name = path.dir(document.uri.path)
- }
-
- document.uri = uri
-
-
-
- return {}
-
-}
-
-
diff --git a/src/testing/testing.odin b/src/testing/testing.odin
index 4f5e704..356c457 100644
--- a/src/testing/testing.odin
+++ b/src/testing/testing.odin
@@ -9,9 +9,7 @@ import "core:odin/parser"
import "core:odin/ast"
import "shared:server"
-import "shared:index"
import "shared:common"
-import "shared:analysis"
Package :: struct {
pkg: string,
@@ -73,9 +71,9 @@ setup :: proc(src: ^Source) {
There is a lot code here that is used in the real code, then i'd like to see.
*/
- index.build_static_index(context.allocator, &common.config);
+ server.build_static_index(context.allocator, &common.config);
- index.indexer.dynamic_index = index.make_memory_index(index.make_symbol_collection(context.allocator, &common.config));
+ server.indexer.dynamic_index = server.make_memory_index(server.make_symbol_collection(context.allocator, &common.config));
for src_pkg in src.packages {
uri := common.create_uri(fmt.aprintf("test/%v/package.odin", src_pkg.pkg), context.temp_allocator);
@@ -84,8 +82,8 @@ setup :: proc(src: ^Source) {
p := parser.Parser {
//err = parser.default_error_handler,
- err = index.log_error_handler,
- warn = index.log_warning_handler,
+ err = server.log_error_handler,
+ warn = server.log_warning_handler,
};
dir := filepath.base(filepath.dir(fullpath, context.temp_allocator));
@@ -112,7 +110,7 @@ setup :: proc(src: ^Source) {
panic("Parser error in test package source");
}
- if ret := index.collect_symbols(&index.indexer.static_index.collection, file, uri.uri); ret != .None {
+ if ret := server.collect_symbols(&server.indexer.static_index.collection, file, uri.uri); ret != .None {
return;
}
}
@@ -120,7 +118,7 @@ setup :: proc(src: ^Source) {
@private
teardown :: proc(src: ^Source) {
- index.free_static_index()
+ server.free_static_index()
}
expect_signature_labels :: proc(t: ^testing.T, src: ^Source, expect_labels: []string) {
diff --git a/tests/completions_test.odin b/tests/completions_test.odin
index 70fc965..cc8ded0 100644
--- a/tests/completions_test.odin
+++ b/tests/completions_test.odin
@@ -1380,4 +1380,39 @@ ast_comp_lit_with_all_symbols_indexed_enum_implicit :: proc(t: ^testing.T) {
}
test.expect_completion_details(t, &source, ".", {"TWO", "ONE"})
+}
+
+@(test)
+ast_package_uppercase_test :: proc(t: ^testing.T) {
+ packages := make([dynamic]test.Package)
+
+ append(&packages, test.Package {
+ pkg = "My_package",
+ source = `package My_package
+ Foo :: enum {
+ ONE,
+ TWO,
+ }
+
+ Bar :: struct {
+ a: int,
+ b: int,
+ c: Foo,
+ }
+ `,
+ })
+
+ source := test.Source {
+ main = `package main
+ import "My_package"
+ main :: proc() {
+ a := My_package.Bar {
+ c = .*
+ }
+ }
+ `,
+ packages = packages[:],
+ }
+
+ test.expect_completion_details(t, &source, ".", {"TWO", "ONE"})
} \ No newline at end of file