From 1d08fd17f6e0c250152b66c63dbfeaaafb496ef9 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Tue, 16 Apr 2024 18:15:10 -0400 Subject: Fix column off-by-1 error in check --- src/server/check.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/server/check.odin b/src/server/check.odin index a3804df..d624f79 100644 --- a/src/server/check.odin +++ b/src/server/check.odin @@ -268,7 +268,7 @@ check :: proc(paths: []string, writer: ^Writer, config: ^common.Config) { severity = .Error, range = { start = { - character = error.column, + character = error.column - 1, line = error.line - 1, }, end = {character = 0, line = error.line}, -- cgit v1.2.3 From 88ec53bed3a487a26d747d84015ae2bd0ecafd4a Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:23:20 -0400 Subject: Move packages to new base collection --- src/common/allocator.odin | 3 ++- src/main.odin | 4 ++-- src/server/build.odin | 3 ++- src/server/check.odin | 5 +++-- src/server/clone.odin | 4 +++- src/server/documents.odin | 4 ++-- src/server/marshal.odin | 3 ++- src/server/references.odin | 6 +++--- src/server/rename.odin | 5 +++-- src/server/requests.odin | 6 +++--- src/server/unmarshal.odin | 3 ++- tools/odinfmt/flag/flag.odin | 3 ++- 12 files changed, 29 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/common/allocator.odin b/src/common/allocator.odin index 21499a1..452f729 100644 --- a/src/common/allocator.odin +++ b/src/common/allocator.odin @@ -1,7 +1,8 @@ package common +import "base:runtime" + import "core:mem" -import "core:runtime" Scratch_Allocator :: struct { data: []byte, diff --git a/src/main.odin b/src/main.odin index f497557..7f399a6 100644 --- a/src/main.odin +++ b/src/main.odin @@ -1,5 +1,7 @@ package main +import "base:intrinsics" + import "core:encoding/json" import "core:fmt" import "core:log" @@ -12,8 +14,6 @@ import "core:strings" import "core:sync" import "core:thread" -import "core:intrinsics" - import "src:common" import "src:server" diff --git a/src/server/build.odin b/src/server/build.odin index 48b7cf1..9d0d550 100644 --- a/src/server/build.odin +++ b/src/server/build.odin @@ -1,5 +1,7 @@ package server +import "base:runtime" + import "core:fmt" import "core:log" import "core:mem" @@ -9,7 +11,6 @@ import "core:odin/tokenizer" import "core:os" import "core:path/filepath" import path "core:path/slashpath" -import "core:runtime" import "core:strings" import "core:time" diff --git a/src/server/check.odin b/src/server/check.odin index a3804df..5f2bdc7 100644 --- a/src/server/check.odin +++ b/src/server/check.odin @@ -1,14 +1,15 @@ package server +import "base:intrinsics" +import "base:runtime" + import "core:encoding/json" import "core:fmt" -import "core:intrinsics" import "core:log" import "core:mem" import "core:os" import "core:path/filepath" import path "core:path/slashpath" -import "core:runtime" import "core:slice" import "core:strconv" import "core:strings" diff --git a/src/server/clone.odin b/src/server/clone.odin index d535d19..2057c98 100644 --- a/src/server/clone.odin +++ b/src/server/clone.odin @@ -1,13 +1,15 @@ package server +import "base:intrinsics" + import "core:fmt" -import "core:intrinsics" import "core:log" import "core:mem" import "core:odin/ast" import "core:odin/tokenizer" import "core:reflect" import "core:strings" + _ :: intrinsics new_type :: proc( diff --git a/src/server/documents.odin b/src/server/documents.odin index 7b3cba4..d78a0d2 100644 --- a/src/server/documents.odin +++ b/src/server/documents.odin @@ -1,5 +1,7 @@ package server +import "base:intrinsics" + import "core:fmt" import "core:log" import "core:mem" @@ -11,8 +13,6 @@ import "core:path/filepath" import path "core:path/slashpath" import "core:strings" -import "core:intrinsics" - import "src:common" ParserError :: struct { diff --git a/src/server/marshal.odin b/src/server/marshal.odin index 932e337..1f18545 100644 --- a/src/server/marshal.odin +++ b/src/server/marshal.odin @@ -1,8 +1,9 @@ package server +import "base:runtime" + import "core:mem" import "core:math/bits" -import "core:runtime" import "core:strconv" import "core:strings" import "core:reflect" diff --git a/src/server/references.odin b/src/server/references.odin index 2016351..49d95bf 100644 --- a/src/server/references.odin +++ b/src/server/references.odin @@ -1,7 +1,6 @@ package server - -import "src:common" +import "base:runtime" import "core:fmt" import "core:log" @@ -11,9 +10,10 @@ import "core:odin/parser" import "core:os" import "core:path/filepath" import path "core:path/slashpath" -import "core:runtime" import "core:strings" +import "src:common" + fullpaths: [dynamic]string walk_directories :: proc( diff --git a/src/server/rename.odin b/src/server/rename.odin index b936d40..252ebaa 100644 --- a/src/server/rename.odin +++ b/src/server/rename.odin @@ -1,13 +1,14 @@ package server -import "src:common" +import "base:runtime" import "core:log" import "core:mem" import "core:odin/ast" -import "core:runtime" import "core:strings" +import "src:common" + get_rename :: proc( document: ^Document, new_text: string, diff --git a/src/server/requests.odin b/src/server/requests.odin index 330fd14..0a203ec 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -1,8 +1,10 @@ package server +import "base:intrinsics" +import "base:runtime" + import "core:encoding/json" import "core:fmt" -import "core:intrinsics" import "core:log" import "core:mem" import "core:odin/ast" @@ -19,8 +21,6 @@ import "core:time" import "src:common" -import "base:runtime" - Header :: struct { content_length: int, content_type: string, diff --git a/src/server/unmarshal.odin b/src/server/unmarshal.odin index ef29801..7ad68c6 100644 --- a/src/server/unmarshal.odin +++ b/src/server/unmarshal.odin @@ -1,8 +1,9 @@ package server +import "base:runtime" + import "core:encoding/json" import "core:strings" -import "core:runtime" import "core:mem" import "core:fmt" diff --git a/tools/odinfmt/flag/flag.odin b/tools/odinfmt/flag/flag.odin index 010a48b..a2f1c81 100644 --- a/tools/odinfmt/flag/flag.odin +++ b/tools/odinfmt/flag/flag.odin @@ -1,6 +1,7 @@ package flag -import "core:runtime" +import "base:runtime" + import "core:strings" import "core:reflect" import "core:fmt" -- cgit v1.2.3 From 15d21f8dbfc5dfac134e8da3662e9cf0e046189e Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:29:48 -0400 Subject: Look for intrinsics in base instead of core --- src/server/collector.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/server/collector.odin b/src/server/collector.odin index fde4f30..8279f55 100644 --- a/src/server/collector.odin +++ b/src/server/collector.odin @@ -772,7 +772,7 @@ collect_symbols :: proc( symbol.pkg = "$builtin" } else if strings.contains(uri, "intrinsics.odin") { path := filepath.join( - elems = {common.config.collections["core"], "/intrinsics"}, + elems = {common.config.collections["base"], "/intrinsics"}, allocator = context.temp_allocator, ) -- cgit v1.2.3 From 9d90c60db5c137a20fb3f4100048635459f92cd2 Mon Sep 17 00:00:00 2001 From: Harold Brenes Date: Thu, 18 Apr 2024 12:36:22 -0400 Subject: Emit proc "receiver" when using fake methods. --- src/server/completion.odin | 5 +++++ src/server/methods.odin | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/server/completion.odin b/src/server/completion.odin index f917498..5cae51e 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -345,6 +345,10 @@ get_selector_completion :: proc( } } + receiver_start := position_context.selector.expr_base.pos.offset + receiver_end := position_context.selector.expr_base.end.offset + receiver := position_context.file.src[receiver_start:receiver_end] + if s, ok := selector.value.(SymbolProcedureValue); ok { if len(s.return_types) == 1 { if selector, ok = resolve_type_expression( @@ -362,6 +366,7 @@ get_selector_completion :: proc( selector, position_context, &items, + receiver, ) } diff --git a/src/server/methods.odin b/src/server/methods.odin index 5eca99e..5190533 100644 --- a/src/server/methods.odin +++ b/src/server/methods.odin @@ -49,11 +49,12 @@ create_remove_edit :: proc( append_method_completion :: proc( ast_context: ^AstContext, - symbol: Symbol, + selector_symbol: Symbol, position_context: ^DocumentPositionContext, items: ^[dynamic]CompletionItem, + receiver: string, ) { - if symbol.type != .Variable { + if selector_symbol.type != .Variable && selector_symbol.type != .Struct { return } @@ -65,8 +66,8 @@ append_method_completion :: proc( for k, v in indexer.index.collection.packages { method := Method { - name = symbol.name, - pkg = symbol.pkg, + name = selector_symbol.name, + pkg = selector_symbol.pkg, } if symbols, ok := &v.methods[method]; ok { for &symbol in symbols { @@ -103,10 +104,20 @@ append_method_completion :: proc( continue } - pointers_to_add := first_arg.pointers - symbol.pointers + pointers_to_add := + first_arg.pointers - selector_symbol.pointers - if pointers_to_add != 1 { - pointers_to_add = 0 + references := "" + dereferences := "" + + if pointers_to_add > 0 { + for i in 0 ..< pointers_to_add { + references = fmt.tprintf("%v&", references) + } + } else if pointers_to_add < 0 { + for i in pointers_to_add ..< 0 { + dereferences = fmt.tprintf("%v^", dereferences) + } } new_text := "" @@ -122,7 +133,23 @@ append_method_completion :: proc( symbol.name, ) } else { - new_text = fmt.tprintf("%v($0)", symbol.name) + if len(symbol.value.(SymbolProcedureValue).arg_types) > 1 { + new_text = fmt.tprintf( + "%v(%v%v%v$0)", + symbol.name, + references, + receiver, + dereferences, + ) + } else { + new_text = fmt.tprintf( + "%v(%v%v%v)$0", + symbol.name, + references, + receiver, + dereferences, + ) + } } item := CompletionItem { -- cgit v1.2.3 From bbd6f7fc5226a2b28f7aa15211f957e85f5418f1 Mon Sep 17 00:00:00 2001 From: Harold Brenes Date: Thu, 18 Apr 2024 14:12:37 -0400 Subject: Fix procs in external packages not getting receiver completion. --- src/server/methods.odin | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/server/methods.odin b/src/server/methods.odin index 5190533..4b8efa8 100644 --- a/src/server/methods.odin +++ b/src/server/methods.odin @@ -124,7 +124,7 @@ append_method_completion :: proc( if symbol.pkg != ast_context.document_package { new_text = fmt.tprintf( - "%v.%v($0)", + "%v.%v", path.base( get_symbol_pkg_name(ast_context, symbol), false, @@ -133,23 +133,25 @@ append_method_completion :: proc( symbol.name, ) } else { - if len(symbol.value.(SymbolProcedureValue).arg_types) > 1 { - new_text = fmt.tprintf( - "%v(%v%v%v$0)", - symbol.name, - references, - receiver, - dereferences, - ) - } else { - new_text = fmt.tprintf( - "%v(%v%v%v)$0", - symbol.name, - references, - receiver, - dereferences, - ) - } + new_text = fmt.tprintf("%v", symbol.name) + } + + if len(symbol.value.(SymbolProcedureValue).arg_types) > 1 { + new_text = fmt.tprintf( + "%v(%v%v%v$0)", + new_text, + references, + receiver, + dereferences, + ) + } else { + new_text = fmt.tprintf( + "%v(%v%v%v)$0", + new_text, + references, + receiver, + dereferences, + ) } item := CompletionItem { -- cgit v1.2.3 From e953ebd2436ecaf645eaee83a18873a9dc590e75 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Fri, 19 Apr 2024 14:18:07 -0400 Subject: Fix crash caused by slicing incomplete import --- src/server/collector.odin | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/server/collector.odin b/src/server/collector.odin index 8279f55..fe103cf 100644 --- a/src/server/collector.odin +++ b/src/server/collector.odin @@ -854,7 +854,8 @@ get_package_mapping :: proc( if len(imp.fullpath) < 2 { continue } - if i := strings.index(imp.fullpath, ":"); i != -1 { + + if i := strings.index(imp.fullpath, ":"); i != -1 && i != len(imp.fullpath) - 1 { collection := imp.fullpath[1:i] p := imp.fullpath[i + 1:len(imp.fullpath) - 1] -- cgit v1.2.3 From 6c6a5031d351bb5a06f48e97b745ef93599b56c0 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Fri, 19 Apr 2024 14:27:11 -0400 Subject: Fix autocomplete for import --- src/server/completion.odin | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/server/completion.odin b/src/server/completion.odin index 5cae51e..8fe924e 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -52,9 +52,21 @@ get_completion_list :: proc( return list, true } - if position_context.import_stmt == nil && - strings.contains_any(completion_context.triggerCharacter, "/:\"") { - return list, true + if position_context.import_stmt == nil { + if strings.contains_any(completion_context.triggerCharacter, "/:\"") { + return list, true + } + } else { + // Check only when the import fullpath length is > 1, to allow + // completion of modules when the initial '"' quote is entered. + if len(position_context.import_stmt.fullpath) > 1 && + position_context.position == position_context.import_stmt.end.offset && + completion_context.triggerCharacter == "\"" { + // The completion was called for an import statement where the + // cursor is on the ending quote, so abort early to prevent + // performing another completion. + return list, true + } } ast_context := make_ast_context( @@ -1591,14 +1603,18 @@ get_package_completion :: proc( list.isIncomplete = false - fullpath_length := len(position_context.import_stmt.fullpath) + without_quotes := position_context.import_stmt.fullpath - if fullpath_length <= 1 { - return + // Strip the opening quote, if one exists. + if len(without_quotes) > 0 && without_quotes[0] == '"' { + without_quotes = without_quotes[1:] + } + + // Strip the closing quote, if one exists. + if len(without_quotes) > 0 && without_quotes[len(without_quotes) - 1] == '"' { + without_quotes = without_quotes[:len(without_quotes) - 1] } - without_quotes := position_context.import_stmt.fullpath[1:fullpath_length - - 1] absolute_path := without_quotes colon_index := strings.index(without_quotes, ":") -- cgit v1.2.3