aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2021-05-03 23:33:25 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2021-05-03 23:33:25 +0200
commitea0457da00f49fb758337e8456a3fe3965e2d2fa (patch)
treeaa4d9f73e2c140b3c8a6c6baad9801e54fe5e554
parent9aa4f1eb9dacde2b25c5cf426742795e9ec02d70 (diff)
fix type showing correctly on package selection
-rw-r--r--src/server/completion.odin2
-rw-r--r--src/testing/testing.odin52
-rw-r--r--tests/completions_test.odin52
-rw-r--r--tests/hover_test.odin2
-rw-r--r--tests/signatures_test.odin26
5 files changed, 100 insertions, 34 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 8965ca7..66893e0 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -392,7 +392,7 @@ get_selector_completion :: proc(ast_context: ^AstContext, position_context: ^Doc
item := CompletionItem {
label = search.symbol.name,
- kind = .Field,
+ kind = cast(CompletionItemKind)search.symbol.type,
detail = fmt.tprintf("%v.%v: %v", path.base(search.symbol.pkg, false, context.temp_allocator), search.symbol.name, search.symbol.signature),
documentation = search.symbol.doc,
};
diff --git a/src/testing/testing.odin b/src/testing/testing.odin
index 5bb8d63..e74fb0e 100644
--- a/src/testing/testing.odin
+++ b/src/testing/testing.odin
@@ -4,19 +4,22 @@ import "core:testing"
import "core:mem"
import "core:fmt"
import "core:strings"
+import "core:path/filepath"
+import "core:odin/parser"
+import "core:odin/ast"
import "shared:server"
import "shared:index"
import "shared:common"
-Package_Source :: struct {
- pkg_name: string,
+Package :: struct {
+ pkg: string,
source: string,
}
Source :: struct {
main: string,
- source_packages: Package_Source,
+ packages: [] Package,
document: ^server.Document,
collections: map[string]string,
config: common.Config,
@@ -66,6 +69,49 @@ setup :: proc(src: ^Source) {
last = current;
}
+ /*
+ There is a lot code here that is used in the real code, then i'd like to see.
+ */
+
+ index.indexer.dynamic_index = index.make_memory_index(index.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);
+
+ fullpath := uri.path;
+
+ p := parser.Parser {
+ err = index.log_error_handler,
+ warn = index.log_warning_handler,
+ };
+
+ dir := filepath.base(filepath.dir(fullpath, context.temp_allocator));
+
+ pkg := new(ast.Package);
+ pkg.kind = .Normal;
+ pkg.fullpath = fullpath;
+ pkg.name = dir;
+
+ if dir == "runtime" {
+ pkg.kind = .Runtime;
+ }
+
+ file := ast.File {
+ fullpath = fullpath,
+ src = transmute([]u8)src_pkg.source,
+ pkg = pkg,
+ };
+
+ ok := parser.parse_file(&p, &file);
+
+ if !ok {
+ return;
+ }
+
+ if ret := index.collect_symbols(&index.indexer.dynamic_index.collection, file, uri.uri); ret != .None {
+ return;
+ }
+ }
}
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 a2aa4ad..c091209 100644
--- a/tests/completions_test.odin
+++ b/tests/completions_test.odin
@@ -21,7 +21,7 @@ ast_simple_struct_completion :: proc(t: ^testing.T) {
my_struct.*
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_completion_details(t, &source, ".", {"My_Struct.one: int", "My_Struct.two: int", "My_Struct.three: int"});
@@ -43,7 +43,7 @@ ast_index_array_completion :: proc(t: ^testing.T) {
my_struct[2].*
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_completion_details(t, &source, ".", {"My_Struct.one: int", "My_Struct.two: int", "My_Struct.three: int"});
@@ -65,7 +65,7 @@ ast_struct_pointer_completion :: proc(t: ^testing.T) {
my_struct.*
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_completion_details(t, &source, ".", {"My_Struct.one: int", "My_Struct.two: int", "My_Struct.three: int"});
@@ -88,7 +88,7 @@ ast_struct_take_address_completion :: proc(t: ^testing.T) {
my_pointer.*
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_completion_details(t, &source, ".", {"My_Struct.one: int", "My_Struct.two: int", "My_Struct.three: int"});
@@ -111,7 +111,7 @@ ast_struct_deref_completion :: proc(t: ^testing.T) {
my_deref.*
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_completion_details(t, &source, ".", {"My_Struct.one: int", "My_Struct.two: int", "My_Struct.three: int"});
@@ -137,7 +137,7 @@ ast_range_map :: proc(t: ^testing.T) {
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_completion_details(t, &source, ".", {"My_Struct.one: int", "My_Struct.two: int", "My_Struct.three: int"});
@@ -163,7 +163,7 @@ ast_range_array :: proc(t: ^testing.T) {
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_completion_details(t, &source, ".", {"My_Struct.one: int", "My_Struct.two: int", "My_Struct.three: int"});
@@ -192,7 +192,7 @@ ast_completion_identifier_proc_group :: proc(t: ^testing.T) {
grou*
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_completion_details(t, &source, "", {"test.group_function: proc"});
@@ -216,7 +216,7 @@ index_completion_in_comp_lit_type :: proc(t: ^testing.T) {
};
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_completion_details(t, &source, "", {"test.My_Struct: struct"});
@@ -240,7 +240,7 @@ ast_completion_range_struct_selector_strings :: proc(t: ^testing.T) {
}
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_completion_details(t, &source, "", {"test.value: string"});
@@ -267,12 +267,42 @@ ast_completion_selector_on_indexed_array :: proc(t: ^testing.T) {
my_struct.array[len(my_struct.array)-1].*
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_completion_details(t, &source, ".", {"My_Foo.a: int", "My_Foo.b: int"});
}
+@(test)
+ast_package_completion :: proc(t: ^testing.T) {
+
+ packages := make([dynamic]test.Package);
+
+ append(&packages, test.Package{
+ pkg = "my_package",
+ source = `package my_package
+ My_Struct :: struct {
+ one: int,
+ two: int,
+ three: int,
+ }
+ `,
+ });
+
+ source := test.Source {
+ main = `package test
+
+ import "my_package"
+
+ main :: proc() {
+ my_package.*
+ }
+ `,
+ packages = packages[:],
+ };
+
+ test.expect_completion_details(t, &source, ".", {"my_package.My_Struct: struct"});
+}
/*
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index 5daa3e2..97f9b90 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -16,7 +16,7 @@ ast_hover_default_intialized_parameter :: proc(t: ^testing.T) {
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_hover(t, &source, "test.a: bool");
diff --git a/tests/signatures_test.odin b/tests/signatures_test.odin
index c00b845..d5c9da2 100644
--- a/tests/signatures_test.odin
+++ b/tests/signatures_test.odin
@@ -13,7 +13,7 @@ ast_declare_proc_signature :: proc(t: ^testing.T) {
main = `package test
main :: proc(*)
`,
- source_packages = {},
+ packages = {},
};
test.expect_signature_labels(t, &source, {});
@@ -25,14 +25,13 @@ ast_simple_proc_signature :: proc(t: ^testing.T) {
source := test.Source {
main = `package test
cool_function :: proc(a: int) {
-
}
main :: proc() {
cool_function(*)
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_signature_labels(t, &source, {"test.cool_function: proc(a: int)"});
@@ -44,11 +43,9 @@ ast_proc_group_signature_empty_call :: proc(t: ^testing.T) {
source := test.Source {
main = `package test
int_function :: proc(a: int) {
-
}
bool_function :: proc(a: bool) {
-
}
group_function :: proc {
@@ -60,7 +57,7 @@ ast_proc_group_signature_empty_call :: proc(t: ^testing.T) {
group_function(*)
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_signature_labels(t, &source, {"test.int_function: proc(a: int)", "test.bool_function: proc(a: bool)"});
@@ -81,7 +78,7 @@ ast_proc_signature_generic :: proc(t: ^testing.T) {
clone_array(*)
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_signature_labels(t, &source, {"test.clone_array: proc (array: $A/[]^$T, allocator: mem.Allocator, unique_strings: ^map[string]string) -> (A)"});
@@ -93,11 +90,9 @@ ast_proc_group_signature_basic_types :: proc(t: ^testing.T) {
source := test.Source {
main = `package test
int_function :: proc(a: int, b: bool, c: int) {
-
}
bool_function :: proc(a: bool, b: bool, c: bool) {
-
}
group_function :: proc {
@@ -109,7 +104,7 @@ ast_proc_group_signature_basic_types :: proc(t: ^testing.T) {
group_function(2, true, *)
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_signature_labels(t, &source, {"test.int_function: proc(a: int, b: bool, c: int)"});
@@ -125,11 +120,9 @@ ast_proc_group_signature_distinct_basic_types :: proc(t: ^testing.T) {
My_Int :: distinct int;
distinct_function :: proc(a: My_Int, c: int) {
-
}
int_function :: proc(a: int, c: int) {
-
}
group_function :: proc {
@@ -144,7 +137,7 @@ ast_proc_group_signature_distinct_basic_types :: proc(t: ^testing.T) {
group_function(a, *)
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_signature_labels(t, &source, {"test.distinct_function: proc(a: My_Int, c: int)"});
@@ -165,15 +158,12 @@ ast_proc_group_signature_struct :: proc(t: ^testing.T) {
}
distinct_function :: proc(a: My_Int, c: int) {
-
}
int_function :: proc(a: int, c: int) {
-
}
struct_function :: proc(a: int, b: My_Struct, c: int) {
-
}
group_function :: proc {
@@ -188,8 +178,8 @@ ast_proc_group_signature_struct :: proc(t: ^testing.T) {
group_function(a, b, *)
}
`,
- source_packages = {},
+ packages = {},
};
test.expect_signature_labels(t, &source, {"test.struct_function: proc(a: int, b: My_Struct, c: int)"});
-} \ No newline at end of file
+}