aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--.vscode/launch.json12
-rw-r--r--editors/vscode/syntaxes/odin.tmLanguage.json8
-rw-r--r--src/server/semantic_tokens.odin53
4 files changed, 59 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index 74f79da..139a2c0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,4 +14,4 @@
/ols
/odinfmt
ols.json
-
+.vscode/settings.json
diff --git a/.vscode/launch.json b/.vscode/launch.json
index e2ecda4..2749dfe 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -4,17 +4,23 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
- {
+ {
"type": "cppvsdbg",
"request": "attach",
"name": "Attach OLS",
"processId": "${command:pickProcess}"
- }
+ },
{
"type": "cppvsdbg",
"request": "launch",
"name": "Run unit",
"program": "C:\\Users\\Daniel\\Desktop\\Computer_Science\\ols\\test_unit.exe",
- }
+ },
+ {
+ "type": "lldb",
+ "request": "attach",
+ "name": "Attach lldb",
+ "pid": "${command:pickProcess}"
+ },
]
} \ No newline at end of file
diff --git a/editors/vscode/syntaxes/odin.tmLanguage.json b/editors/vscode/syntaxes/odin.tmLanguage.json
index 48f9687..3434596 100644
--- a/editors/vscode/syntaxes/odin.tmLanguage.json
+++ b/editors/vscode/syntaxes/odin.tmLanguage.json
@@ -256,14 +256,6 @@
"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"}},
diff --git a/src/server/semantic_tokens.odin b/src/server/semantic_tokens.odin
index d2240f8..732fd96 100644
--- a/src/server/semantic_tokens.odin
+++ b/src/server/semantic_tokens.odin
@@ -9,6 +9,7 @@ package server
import "core:fmt"
import "core:log"
+import "core:unicode/utf8"
import "core:odin/ast"
import "core:odin/tokenizer"
@@ -353,10 +354,7 @@ visit_node :: proc(node: ^ast.Node, builder: ^SemanticTokenBuilder) {
case ^Defer_Stmt:
visit_node(n.stmt, builder)
case ^Import_Decl:
- if n.name.text != "" {
- write_semantic_token(builder, n.name, .Namespace)
- }
-
+ visit_import_decl(n, builder)
case ^Or_Return_Expr:
visit_node(n.expr, builder)
case ^Or_Else_Expr:
@@ -501,6 +499,53 @@ visit_selector :: proc(selector: ^ast.Selector_Expr, builder: ^SemanticTokenBuil
visit_ident(selector.field, selector, {}, builder)
}
+visit_import_decl :: proc(decl: ^ast.Import_Decl, builder: ^SemanticTokenBuilder) {
+ /*
+ hightlight the namespace in the import declaration
+
+ import "pkg"
+ ^^^
+ import "core:fmt"
+ ^^^
+ import "core:odin/ast"
+ ^^^
+ import foo "core:fmt"
+ ^^^
+ */
+
+ if decl.name.text != "" {
+ write_semantic_token(builder, decl.name, .Namespace)
+ }
+ else if len(decl.relpath.text) > 2 {
+
+ start, end := 1, len(decl.relpath.text) - 1
+ i := end
+
+ for {
+ if i > start {
+ ch, w := utf8.decode_last_rune_in_string(decl.relpath.text[:i])
+
+ switch ch {
+ case ':', '/': // break
+ case:
+ i -= w
+ continue
+ }
+ }
+
+ start = i
+ break
+ }
+
+ write_semantic_at_pos(
+ builder,
+ decl.relpath.pos.offset+start,
+ end-start,
+ .Namespace,
+ )
+ }
+}
+
visit_ident :: proc(
ident: ^ast.Ident,
symbol_ptr: rawptr,