Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
/ols
/odinfmt
ols.json

.vscode/settings.json
10 changes: 8 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
"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}"
},
]
}
8 changes: 0 additions & 8 deletions editors/vscode/syntaxes/odin.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down
52 changes: 48 additions & 4 deletions src/server/semantic_tokens.odin
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package server

import "core:fmt"
import "core:log"
import "core:unicode/utf8"
import "core:odin/ast"
import "core:odin/tokenizer"

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -501,6 +499,52 @@ 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 {

end := len(decl.relpath.text) - 1
pos := end

for {
if pos > 1 {
ch, w := utf8.decode_last_rune_in_string(decl.relpath.text[:pos])

switch ch {
case ':', '/': // break
case:
pos -= w
continue
}
}

break
}

write_semantic_at_pos(
builder,
decl.relpath.pos.offset+pos,
end-pos,
.Namespace,
)
}
}

visit_ident :: proc(
ident: ^ast.Ident,
symbol_ptr: rawptr,
Expand Down