aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2024-04-22 19:45:37 +0200
committerDanielGavin <danielgavin5@hotmail.com>2024-04-22 19:45:37 +0200
commit21d3473bacfbd8dc81fa855d085a9bb67cc5be01 (patch)
treee4864ecff42ce303677352f5373939c5ee5943a4
parent6ce95de7909837c4e03b0338400f0b38ae8c912a (diff)
parent9147dc2f31f38148daaeebd083f7120bb8d6bab0 (diff)
Merge branch 'master' of https://github.com/DanielGavin/ols
-rw-r--r--editors/vscode/.npmrc1
-rw-r--r--editors/vscode/package-lock.json4
-rw-r--r--editors/vscode/syntaxes/odin.tmLanguage.json28
-rw-r--r--src/common/allocator.odin3
-rw-r--r--src/main.odin4
-rw-r--r--src/server/build.odin3
-rw-r--r--src/server/check.odin5
-rw-r--r--src/server/clone.odin4
-rw-r--r--src/server/collector.odin5
-rw-r--r--src/server/completion.odin37
-rw-r--r--src/server/documents.odin4
-rw-r--r--src/server/marshal.odin3
-rw-r--r--src/server/methods.odin47
-rw-r--r--src/server/references.odin6
-rw-r--r--src/server/rename.odin5
-rw-r--r--src/server/requests.odin6
-rw-r--r--src/server/unmarshal.odin3
-rw-r--r--tools/odinfmt/flag/flag.odin5
18 files changed, 131 insertions, 42 deletions
diff --git a/editors/vscode/.npmrc b/editors/vscode/.npmrc
new file mode 100644
index 0000000..ec84bd8
--- /dev/null
+++ b/editors/vscode/.npmrc
@@ -0,0 +1 @@
+install-strategy=hoisted \ No newline at end of file
diff --git a/editors/vscode/package-lock.json b/editors/vscode/package-lock.json
index 6d2309e..da86bd6 100644
--- a/editors/vscode/package-lock.json
+++ b/editors/vscode/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "ols",
- "version": "0.1.26",
+ "version": "0.1.27",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ols",
- "version": "0.1.26",
+ "version": "0.1.27",
"dependencies": {
"adm-zip": "^0.5.9",
"https-proxy-agent": "^5.0.0",
diff --git a/editors/vscode/syntaxes/odin.tmLanguage.json b/editors/vscode/syntaxes/odin.tmLanguage.json
index bd41c02..7f8ec14 100644
--- a/editors/vscode/syntaxes/odin.tmLanguage.json
+++ b/editors/vscode/syntaxes/odin.tmLanguage.json
@@ -4,6 +4,7 @@
"name": "Odin",
"patterns": [
{ "include": "#package-name-declaration" },
+ { "include": "#import-declaration" },
{ "include": "#statements" }
],
"repository": {
@@ -217,6 +218,33 @@
"2": { "name": "entity.name.type.module.odin" }
}
},
+ "import-declaration": {
+ "name": "meta.import.odin",
+ "begin": "\\b(import|foreign\\s+import)\\b",
+ "beginCaptures": {"0": {"name": "keyword.control.import.odin"}},
+ "end": "(?=^|;)",
+ "patterns": [
+ { "name": "string.import.odin",
+ "match": "([\"`])([\\w\\.]*[/:])*([A-Za-z_]\\w*)([\"`])",
+ "captures": {
+ "1": {"name": "punctuation.definition.string.begin.odin"},
+ "3": {"name": "entity.name.namespace.odin"},
+ "4": {"name": "punctuation.definition.string.end.odin"}
+ }
+ },
+ { "name": "entity.name.alias.odin",
+ "begin": "\\b[A-Za-z_]\\w*",
+ "beginCaptures": {"0": {"name": "entity.name.namespace.odin"}},
+ "end": "(?=^|;)",
+ "patterns": [
+ {"include": "#strings"},
+ {"include": "#comments"}
+ ]
+ },
+ {"include": "#strings"},
+ {"include": "#comments"}
+ ]
+ },
"map-bitset": {
"begin": "\\b(bit_set|map)\\b",
"beginCaptures": { "0": { "name": "storage.type.odin" } },
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 47f1d9a..895d890 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/collector.odin b/src/server/collector.odin
index fde4f30..fe103cf 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,
)
@@ -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]
diff --git a/src/server/completion.odin b/src/server/completion.odin
index f917498..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(
@@ -345,6 +357,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 +378,7 @@ get_selector_completion :: proc(
selector,
position_context,
&items,
+ receiver,
)
}
@@ -1586,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, ":")
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/methods.odin b/src/server/methods.odin
index 5eca99e..4b8efa8 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,17 +104,27 @@ 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 := ""
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,
@@ -122,7 +133,25 @@ append_method_completion :: proc(
symbol.name,
)
} else {
- new_text = fmt.tprintf("%v($0)", symbol.name)
+ 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 {
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..b10f981 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"
@@ -103,7 +104,7 @@ parse_args :: proc(ctx: ^Flag_Context, args: []string) -> Flag_Error {
}
case Type_Info_String:
raw_string := cast(^mem.Raw_String)flag.data;
- raw_string.data = strings.ptr_from_string(value);
+ raw_string.data = raw_data(value);
raw_string.len = len(value);
case Type_Info_Float:
switch flag.type.size {