Skip to content

Commit

Permalink
Make sure not to return $ for identifiers.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGavin committed Oct 3, 2024
1 parent 0c2c02a commit 28982c5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 143 deletions.
8 changes: 7 additions & 1 deletion src/server/completion.odin
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ get_identifier_completion :: proc(
CombinedResult {
score = score * 1.7,
type = symbol.type,
name = ident.name,
name = clean_ident(ident.name),
doc = symbol.doc,
flags = symbol.flags,
pkg = symbol.pkg,
Expand Down Expand Up @@ -1534,6 +1534,12 @@ get_package_completion :: proc(
list.items = items[:]
}

clean_ident :: proc(ident: string) -> string {
//Identifiers can be attached with $ for poly types, but we don't want to show those on completion.
name, _ := strings.replace(ident, "$", "", 1, context.temp_allocator)
return name
}

search_for_packages :: proc(fullpath: string) -> []string {
packages := make([dynamic]string, context.temp_allocator)

Expand Down
195 changes: 58 additions & 137 deletions src/testing/testing.odin
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,14 @@ Source :: struct {
setup :: proc(src: ^Source) {
src.main = strings.clone(src.main, context.temp_allocator)
src.document = new(server.Document, context.temp_allocator)
src.document.uri = common.create_uri(
"test/test.odin",
context.temp_allocator,
)
src.document.uri = common.create_uri("test/test.odin", context.temp_allocator)
src.document.client_owned = true
src.document.text = transmute([]u8)src.main
src.document.used_text = len(src.document.text)
src.document.allocator = new(
common.Scratch_Allocator,
context.temp_allocator,
)
src.document.allocator = new(common.Scratch_Allocator, context.temp_allocator)
src.document.package_name = "test"

common.scratch_allocator_init(
src.document.allocator,
mem.Kilobyte * 2000,
context.temp_allocator,
)
common.scratch_allocator_init(src.document.allocator, mem.Kilobyte * 2000, context.temp_allocator)

//no unicode in tests currently
current, last: u8
Expand All @@ -62,8 +52,7 @@ setup :: proc(src: ^Source) {
} else if current == '\n' {
current_line += 1
current_character = 0
} else if len(src.main) > current_index + 3 &&
src.main[current_index:current_index + 3] == "{*}" {
} else if len(src.main) > current_index + 3 && src.main[current_index:current_index + 3] == "{*}" {
dst_slice := transmute([]u8)src.main[current_index:]
src_slice := transmute([]u8)src.main[current_index + 3:]
copy(dst_slice, src_slice)
Expand All @@ -86,10 +75,7 @@ setup :: proc(src: ^Source) {
for src_pkg in src.packages {
context.allocator = common.scratch_allocator(src.document.allocator)

uri := common.create_uri(
fmt.aprintf("test/%v/package.odin", src_pkg.pkg),
context.temp_allocator,
)
uri := common.create_uri(fmt.aprintf("test/%v/package.odin", src_pkg.pkg), context.temp_allocator)

fullpath := uri.path

Expand Down Expand Up @@ -123,11 +109,7 @@ setup :: proc(src: ^Source) {
panic("Parser error in test package source")
}

if ret := server.collect_symbols(
&server.indexer.index.collection,
file,
uri.uri,
); ret != .None {
if ret := server.collect_symbols(&server.indexer.index.collection, file, uri.uri); ret != .None {
return
}
}
Expand All @@ -151,11 +133,7 @@ teardown :: proc(src: ^Source) {
common.scratch_allocator_destroy(src.document.allocator)
}

expect_signature_labels :: proc(
t: ^testing.T,
src: ^Source,
expect_labels: []string,
) {
expect_signature_labels :: proc(t: ^testing.T, src: ^Source, expect_labels: []string) {
setup(src)
defer teardown(src)

Expand All @@ -166,10 +144,7 @@ expect_signature_labels :: proc(
}

if len(expect_labels) == 0 && len(help.signatures) > 0 {
log.errorf(
"Expected empty signature label, but received %v",
help.signatures,
)
log.errorf("Expected empty signature label, but received %v", help.signatures)
}

flags := make([]int, len(expect_labels), context.temp_allocator)
Expand All @@ -184,63 +159,39 @@ expect_signature_labels :: proc(

for flag, i in flags {
if flag != 1 {
log.errorf(
"Expected signature label %v, but received %v",
expect_labels[i],
help.signatures,
)
log.errorf("Expected signature label %v, but received %v", expect_labels[i], help.signatures)
}
}

}

expect_signature_parameter_position :: proc(
t: ^testing.T,
src: ^Source,
position: int,
) {
expect_signature_parameter_position :: proc(t: ^testing.T, src: ^Source, position: int) {
setup(src)
defer teardown(src)

help, ok := server.get_signature_information(src.document, src.position)

if help.activeParameter != position {
log.errorf(
"expected parameter position %v, but received %v",
position,
help.activeParameter,
)
log.errorf("expected parameter position %v, but received %v", position, help.activeParameter)
}
}

expect_completion_labels :: proc(
t: ^testing.T,
src: ^Source,
trigger_character: string,
expect_labels: []string,
) {
expect_completion_labels :: proc(t: ^testing.T, src: ^Source, trigger_character: string, expect_labels: []string) {
setup(src)
defer teardown(src)

completion_context := server.CompletionContext {
triggerCharacter = trigger_character,
}

completion_list, ok := server.get_completion_list(
src.document,
src.position,
completion_context,
)
completion_list, ok := server.get_completion_list(src.document, src.position, completion_context)

if !ok {
log.error("Failed get_completion_list")
}

if len(expect_labels) == 0 && len(completion_list.items) > 0 {
log.errorf(
"Expected empty completion label, but received %v",
completion_list.items,
)
log.errorf("Expected empty completion label, but received %v", completion_list.items)
}

flags := make([]int, len(expect_labels), context.temp_allocator)
Expand All @@ -255,43 +206,27 @@ expect_completion_labels :: proc(

for flag, i in flags {
if flag != 1 {
log.errorf(
"Expected completion detail %v, but received %v",
expect_labels[i],
completion_list.items,
)
log.errorf("Expected completion detail %v, but received %v", expect_labels[i], completion_list.items)
}
}
}

expect_completion_details :: proc(
t: ^testing.T,
src: ^Source,
trigger_character: string,
expect_details: []string,
) {
expect_completion_details :: proc(t: ^testing.T, src: ^Source, trigger_character: string, expect_details: []string) {
setup(src)
defer teardown(src)

completion_context := server.CompletionContext {
triggerCharacter = trigger_character,
}

completion_list, ok := server.get_completion_list(
src.document,
src.position,
completion_context,
)
completion_list, ok := server.get_completion_list(src.document, src.position, completion_context)

if !ok {
log.error("Failed get_completion_list")
}

if len(expect_details) == 0 && len(completion_list.items) > 0 {
log.errorf(
"Expected empty completion label, but received %v",
completion_list.items,
)
log.errorf("Expected empty completion label, but received %v", completion_list.items)
}

flags := make([]int, len(expect_details), context.temp_allocator)
Expand All @@ -306,50 +241,35 @@ expect_completion_details :: proc(

for flag, i in flags {
if flag != 1 {
log.errorf(
"Expected completion label %v, but received %v",
expect_details[i],
completion_list.items,
)
log.errorf("Expected completion label %v, but received %v", expect_details[i], completion_list.items)
}
}
}

expect_hover :: proc(
t: ^testing.T,
src: ^Source,
expect_hover_string: string,
) {
expect_hover :: proc(t: ^testing.T, src: ^Source, expect_hover_string: string) {
setup(src)
defer teardown(src)

hover, _, ok := server.get_hover_information(src.document, src.position)
hover, valid, ok := server.get_hover_information(src.document, src.position)

if !ok {
log.error(t, "Failed get_hover_information")
return
}

if !valid {
log.error(t, "Failed get_hover_information")
return
}

/*
```odin\n
content\n
```
*/
content_without_markdown := hover.contents.value[8:len(hover.contents.value)-5]
content_without_markdown := hover.contents.value[8:len(hover.contents.value) - 5]

if content_without_markdown != expect_hover_string {
log.errorf(
"Expected hover string:\n%q, but received:\n%q",
expect_hover_string,
content_without_markdown,
)
log.errorf("Expected hover string:\n%q, but received:\n%q", expect_hover_string, content_without_markdown)
}
}

expect_definition_locations :: proc(
t: ^testing.T,
src: ^Source,
expect_locations: []common.Location,
) {
expect_definition_locations :: proc(t: ^testing.T, src: ^Source, expect_locations: []common.Location) {
setup(src)
defer teardown(src)

Expand All @@ -375,20 +295,12 @@ expect_definition_locations :: proc(

for flag, i in flags {
if flag != 1 {
log.errorf(
"Expected location %v, but received %v",
expect_locations[i].range,
locations,
)
log.errorf("Expected location %v, but received %v", expect_locations[i].range, locations)
}
}
}

expect_reference_locations :: proc(
t: ^testing.T,
src: ^Source,
expect_locations: []common.Location,
) {
expect_reference_locations :: proc(t: ^testing.T, src: ^Source, expect_locations: []common.Location) {
setup(src)
defer teardown(src)

Expand All @@ -415,35 +327,44 @@ expect_reference_locations :: proc(
}
}

expect_semantic_tokens :: proc(
t: ^testing.T,
src: ^Source,
expected: []server.SemanticToken,
) {
expect_semantic_tokens :: proc(t: ^testing.T, src: ^Source, expected: []server.SemanticToken) {
setup(src)
defer teardown(src)


resolve_flag: server.ResolveReferenceFlag
symbols_and_nodes := server.resolve_entire_file(
src.document,
resolve_flag,
context.temp_allocator,
)
symbols_and_nodes := server.resolve_entire_file(src.document, resolve_flag, context.temp_allocator)

range := common.Range{end = {line = 9000000}} //should be enough
range := common.Range {
end = {line = 9000000},
} //should be enough
tokens := server.get_semantic_tokens(src.document, range, symbols_and_nodes)

testing.expectf(t, len(expected) == len(tokens), "\nExpected %d tokens, but received %d", len(expected), len(tokens))
testing.expectf(
t,
len(expected) == len(tokens),
"\nExpected %d tokens, but received %d",
len(expected),
len(tokens),
)

for i in 0..<min(len(expected), len(tokens)) {
for i in 0 ..< min(len(expected), len(tokens)) {
e, a := expected[i], tokens[i]
testing.expectf(t,
testing.expectf(
t,
e == a,
"\n[%d]: Expected \n(%d, %d, %d, %v, %w)\nbut received\n(%d, %d, %d, %v, %w)",
i,
e.delta_line, e.delta_char, e.len, e.type, e.modifiers,
a.delta_line, a.delta_char, a.len, a.type, a.modifiers,
e.delta_line,
e.delta_char,
e.len,
e.type,
e.modifiers,
a.delta_line,
a.delta_char,
a.len,
a.type,
a.modifiers,
)
}
}
Loading

0 comments on commit 28982c5

Please sign in to comment.