aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/position.odin2
-rw-r--r--tests/definition_test.odin27
-rw-r--r--tests/hover_test.odin18
-rw-r--r--tests/references_test.odin23
4 files changed, 69 insertions, 1 deletions
diff --git a/src/common/position.odin b/src/common/position.odin
index fca82b0..1eecfdc 100644
--- a/src/common/position.odin
+++ b/src/common/position.odin
@@ -43,7 +43,7 @@ get_absolute_position :: proc(position: Position, document_text: []u8) -> (Absol
}
line_count := 0
- index := 1
+ index := 0
last := document_text[0]
if !get_index_at_line(&index, &line_count, &last, document_text, position.line) {
diff --git a/tests/definition_test.odin b/tests/definition_test.odin
index 8718f3a..1c51b8e 100644
--- a/tests/definition_test.odin
+++ b/tests/definition_test.odin
@@ -446,3 +446,30 @@ ast_goto_variable_field_definition_with_selector_expr :: proc(t: ^testing.T) {
test.expect_definition_locations(t, &source, {location})
}
+
+
+@(test)
+ast_goto_struct_definition_with_empty_line_at_top_of_file :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `
+ package test
+
+ Foo :: struct {
+ bar: int,
+ }
+
+ main :: proc() {
+ foo := F{*}oo{}
+ }
+ `
+ }
+
+ location := common.Location {
+ range = {
+ start = {line = 3, character = 2},
+ end = {line = 3, character = 5},
+ },
+ }
+
+ test.expect_definition_locations(t, &source, {location})
+}
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index 9cc1d5b..fc3b730 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -895,6 +895,24 @@ ast_hover_struct_field_use :: proc(t: ^testing.T) {
test.expect_hover(t, &source, "Bar.foo: test.Foo :: struct {\n\tvalue: int,\n}")
}
+
+@(test)
+ast_hover_empty_line_at_top_of_file :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `
+ package test
+ Foo :: struct {
+ bar: int,
+ }
+
+ main :: proc() {
+ foo := F{*}oo{}
+ }
+ `
+ }
+
+ test.expect_hover(t, &source, "test.Foo: struct {\n\tbar: int,\n}")
+}
/*
Waiting for odin fix
diff --git a/tests/references_test.odin b/tests/references_test.odin
index 3bc0862..84de7a5 100644
--- a/tests/references_test.odin
+++ b/tests/references_test.odin
@@ -30,6 +30,29 @@ reference_variables_in_function :: proc(t: ^testing.T) {
}
@(test)
+reference_variables_in_function_with_empty_line_at_top_of_file :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `
+ package test
+ my_function :: proc() {
+ a := 2
+ b := a
+ c := 2 + b{*}
+ }
+ `,
+ }
+
+ test.expect_reference_locations(
+ t,
+ &source,
+ {
+ {range = {start = {line = 4, character = 3}, end = {line = 4, character = 4}}},
+ {range = {start = {line = 5, character = 12}, end = {line = 5, character = 13}}},
+ },
+ )
+}
+
+@(test)
reference_variables_in_function_parameters :: proc(t: ^testing.T) {
source := test.Source {
main = `package test