aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2022-06-11 22:50:18 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2022-06-11 22:50:18 +0200
commit4dcbd44dbf63f2b365c315f481b70ecc946e9f56 (patch)
treeab7bf9872e4b70490cbdf97e0edc5435e12aac91
parent70d5bcf8eca474440020c31239cd827cf3bb3415 (diff)
Fix hover bug
-rw-r--r--src/common/position.odin15
-rw-r--r--src/common/types.odin1
-rw-r--r--src/server/analysis.odin6
-rw-r--r--src/server/completion.odin6
-rw-r--r--src/server/documents.odin56
-rw-r--r--src/server/hover.odin4
-rw-r--r--src/server/memory_index.odin8
-rw-r--r--src/server/semantic_tokens.odin4
8 files changed, 52 insertions, 48 deletions
diff --git a/src/common/position.odin b/src/common/position.odin
index 3a600ab..e8c5ff2 100644
--- a/src/common/position.odin
+++ b/src/common/position.odin
@@ -64,7 +64,6 @@ get_relative_token_position :: proc(offset: int, document_text: []u8, current_st
position: Position
for i + start_index < offset {
-
r, w := utf8.decode_rune(data[i:])
if r == '\n' { //\r?
@@ -94,7 +93,6 @@ get_token_range :: proc(node: ast.Node, document_text: string) -> Range {
range: Range
go_backwards_to_endline :: proc(offset: int, document_text: []u8) -> int {
-
index := offset
for index > 0 && document_text[index] != '\n' && document_text[index] != '\r' {
@@ -113,19 +111,18 @@ get_token_range :: proc(node: ast.Node, document_text: string) -> Range {
offset := go_backwards_to_endline(pos_offset, transmute([]u8)document_text)
- range.start.line = node.pos.line - 1
+ range.start.line = node.pos.line - 1
range.start.character = get_character_offset_u8_to_u16(node.pos.column - 1, transmute([]u8)document_text[offset:])
- offset = go_backwards_to_endline(end_offset, transmute([]u8)document_text)
+ offset = go_backwards_to_endline(end_offset - 1, transmute([]u8)document_text)
- range.end.line = node.end.line - 1
+ range.end.line = node.end.line - 1
range.end.character = get_character_offset_u8_to_u16(node.end.column - 1, transmute([]u8)document_text[offset:])
return range
}
get_absolute_range :: proc(range: Range, document_text: []u8) -> (AbsoluteRange, bool) {
-
absolute: AbsoluteRange
if len(document_text) == 0 {
@@ -160,7 +157,6 @@ get_absolute_range :: proc(range: Range, document_text: []u8) -> (AbsoluteRange,
}
get_index_at_line :: proc(current_index: ^int, current_line: ^int, last: ^u8, document_text: []u8, end_line: int) -> bool {
-
if end_line == 0 {
current_index^ = 0
return true
@@ -171,7 +167,6 @@ get_index_at_line :: proc(current_index: ^int, current_line: ^int, last: ^u8, do
}
for ; current_index^ < len(document_text); current_index^ += 1 {
-
current := document_text[current_index^]
if last^ == '\r' {
@@ -199,12 +194,10 @@ get_index_at_line :: proc(current_index: ^int, current_line: ^int, last: ^u8, do
}
get_character_offset_u16_to_u8 :: proc(character_offset: int, document_text: []u8) -> int {
-
utf8_idx := 0
utf16_idx := 0
for utf16_idx < character_offset {
-
r, w := utf8.decode_rune(document_text[utf8_idx:])
if r == '\n' || r == '\r' {
@@ -224,12 +217,10 @@ get_character_offset_u16_to_u8 :: proc(character_offset: int, document_text: []u
}
get_character_offset_u8_to_u16 :: proc(character_offset: int, document_text: []u8) -> int {
-
utf8_idx := 0
utf16_idx := 0
for utf8_idx < character_offset {
-
r, w := utf8.decode_rune(document_text[utf8_idx:])
if r == '\n' || r == '\r' {
diff --git a/src/common/types.odin b/src/common/types.odin
index 51affaa..231a42b 100644
--- a/src/common/types.odin
+++ b/src/common/types.odin
@@ -30,6 +30,7 @@ Package :: struct {
Document :: struct {
uri: Uri,
+ fullpath: string,
text: []u8,
used_text: int, //allow for the text to be reallocated with more data than needed
client_owned: bool,
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index a4ec13b..bd700fe 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1204,9 +1204,6 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (S
#partial switch v in local.derived {
case ^Ident:
- if v.name == node.name {
- return {}, false
- }
return_symbol, ok = resolve_type_identifier(ast_context, v^)
case ^Union_Type:
return_symbol, ok = make_symbol_union_from_ast(ast_context, v^, node.name), true
@@ -1273,9 +1270,6 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (S
#partial switch v in global.expr.derived {
case ^Ident:
- if v.name == node.name {
- return {}, false
- }
return_symbol, ok = resolve_type_identifier(ast_context, v^)
case ^Struct_Type:
return_symbol, ok = make_symbol_struct_from_ast(ast_context, v^, node.name), true
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 093c9e3..f42fbb3 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -354,10 +354,10 @@ get_selector_completion :: proc(ast_context: ^AstContext, position_context: ^Doc
documentation = symbol.doc,
}
- if symbol.pkg == ast_context.document_package || base == "runtime" {
- item.label = fmt.aprintf("(%v%v)", common.repeat("^", symbol.pointers, context.temp_allocator), symbol.name)
+ if symbol.pkg == ast_context.document_package || base == "runtime" || base == "$builtin" {
+ item.label = fmt.aprintf("(%v%v)", common.repeat("^", symbol.pointers, context.temp_allocator), common.node_to_string(type))
} else {
- item.label = fmt.aprintf("(%v%v.%v)", common.repeat("^", symbol.pointers, context.temp_allocator), path.base(symbol.pkg, false, context.temp_allocator), symbol.name)
+ item.label = fmt.aprintf("(%v%v.%v)", common.repeat("^", symbol.pointers, context.temp_allocator), path.base(symbol.pkg, false, context.temp_allocator), common.node_to_string(type))
}
append(&items, item)
diff --git a/src/server/documents.odin b/src/server/documents.odin
index 62cc1ba..8750720 100644
--- a/src/server/documents.odin
+++ b/src/server/documents.odin
@@ -108,6 +108,8 @@ document_open :: proc(uri_string: string, text: string, config: ^common.Config,
document.used_text = len(document.text)
document.allocator = document_get_allocator()
+ document_setup(document)
+
if err := document_refresh(document, config, writer); err != .None {
return err
}
@@ -120,6 +122,8 @@ document_open :: proc(uri_string: string, text: string, config: ^common.Config,
allocator = document_get_allocator(),
}
+ document_setup(&document)
+
if err := document_refresh(&document, config, writer); err != .None {
return err
}
@@ -132,6 +136,34 @@ document_open :: proc(uri_string: string, text: string, config: ^common.Config,
return .None
}
+document_setup :: proc(document: ^common.Document) {
+ //Right now not all clients return the case correct windows path, and that causes issues with indexing, so we ensure that it's case correct.
+ when ODIN_OS == .Windows {
+ package_name := path.dir(document.uri.path, context.temp_allocator)
+ forward, _ := filepath.to_slash(common.get_case_sensitive_path(package_name), context.temp_allocator)
+ if forward == "" {
+ document.package_name = package_name
+ } else {
+ document.package_name = strings.clone(forward)
+ }
+ } else {
+ document.package_name = path.dir(document.uri.path)
+ }
+
+ when ODIN_OS == .Windows {
+ correct := common.get_case_sensitive_path(document.uri.path)
+ fullpath: string
+ if correct == "" {
+ //This is basically here to handle the tests where the physical file doesn't actual exist.
+ document.fullpath, _ = filepath.to_slash(document.uri.path)
+ } else {
+ document.fullpath, _ = filepath.to_slash(correct)
+ }
+ } else {
+ document.fullpath = document.uri.path
+ }
+}
+
/*
Function that applies changes to the given document through incremental syncronization
*/
@@ -330,18 +362,12 @@ parse_document :: proc(document: ^common.Document, config: ^common.Config) -> ([
context.allocator = common.scratch_allocator(document.allocator)
- when ODIN_OS == .Windows {
- fullpath, _ := filepath.to_slash(common.get_case_sensitive_path(document.uri.path))
- } else {
- fullpath := document.uri.path
- }
-
pkg := new(ast.Package)
pkg.kind = .Normal
- pkg.fullpath = fullpath
+ pkg.fullpath = document.fullpath
document.ast = ast.File {
- fullpath = fullpath,
+ fullpath = document.fullpath,
src = string(document.text[:document.used_text]),
pkg = pkg,
}
@@ -352,7 +378,6 @@ parse_document :: proc(document: ^common.Document, config: ^common.Config) -> ([
log.error(document.ast.decls[0])
}
-
parse_imports(document, config)
return current_errors[:], true
@@ -360,19 +385,6 @@ parse_document :: proc(document: ^common.Document, config: ^common.Config) -> ([
parse_imports :: proc(document: ^common.Document, config: ^common.Config) {
imports := make([dynamic]common.Package)
-
- //Right now not all clients return the case correct windows path, and that causes issues with indexing, so we ensure that it's case correct.
- when ODIN_OS == .Windows {
- package_name := path.dir(document.uri.path, context.temp_allocator)
- forward, _ := filepath.to_slash(common.get_case_sensitive_path(package_name), context.temp_allocator)
- if forward == "" {
- document.package_name = package_name
- } else {
- document.package_name = strings.clone(forward)
- }
- } else {
- document.package_name = path.dir(document.uri.path)
- }
for imp, index in document.ast.imports {
if i := strings.index(imp.fullpath, "\""); i == -1 {
diff --git a/src/server/hover.odin b/src/server/hover.odin
index 1fdecd5..25975c0 100644
--- a/src/server/hover.odin
+++ b/src/server/hover.odin
@@ -73,7 +73,6 @@ get_hover_information :: proc(document: ^common.Document, position: common.Posit
if position_context.selector != nil && position_context.identifier != nil {
hover.range = common.get_token_range(position_context.identifier^, ast_context.file.src)
-
ast_context.use_locals = true
ast_context.use_globals = true
ast_context.current_package = ast_context.document_package
@@ -114,8 +113,7 @@ get_hover_information :: proc(document: ^common.Document, position: common.Posit
}
}
- hover.range = common.get_token_range(position_context.identifier^, document.ast.src)
-
+
#partial switch v in selector.value {
case SymbolStructValue:
for name, i in v.names {
diff --git a/src/server/memory_index.odin b/src/server/memory_index.odin
index 22b901f..a6866d1 100644
--- a/src/server/memory_index.odin
+++ b/src/server/memory_index.odin
@@ -41,6 +41,14 @@ memory_index_lookup :: proc(index: ^MemoryIndex, name: string, pkg: string) -> (
return {}, false
}
+memory_reference_lookup :: proc(index: ^MemoryIndex, name: string, pkg: string) -> (Reference, bool) {
+ if pkg, ok := &index.collection.references[pkg]; ok {
+ return pkg[name]
+ }
+
+ return {}, false
+}
+
memory_index_fuzzy_search :: proc(index: ^MemoryIndex, name: string, pkgs: []string) -> ([]FuzzyResult, bool) {
symbols := make([dynamic]FuzzyResult, 0, context.temp_allocator)
diff --git a/src/server/semantic_tokens.odin b/src/server/semantic_tokens.odin
index be103a2..321858e 100644
--- a/src/server/semantic_tokens.odin
+++ b/src/server/semantic_tokens.odin
@@ -170,10 +170,10 @@ visit_node :: proc(node: ^ast.Node, builder: ^SemanticTokenBuilder, ast_context:
visit(n.expr, builder, ast_context)
case ^Ident:
if symbol_and_node, ok := builder.symbols[cast(uintptr)node]; ok {
- if symbol_and_node.symbol.type == .Variable {
+ if symbol_and_node.symbol.type == .Variable || symbol_and_node.symbol.type == .Constant {
write_semantic_node(builder, node, ast_context.file.src, .Variable, .None)
return
- }
+ }
#partial switch v in symbol_and_node.symbol.value {
case SymbolPackageValue: