aboutsummaryrefslogtreecommitdiff
path: root/src/server/documents.odin
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/documents.odin')
-rw-r--r--src/server/documents.odin28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/server/documents.odin b/src/server/documents.odin
index dee90d5..b513da6 100644
--- a/src/server/documents.odin
+++ b/src/server/documents.odin
@@ -29,6 +29,7 @@ Package :: struct {
base: string,
base_original: string,
original: string,
+ range: common.Range,
}
Document :: struct {
@@ -75,7 +76,7 @@ document_get_allocator :: proc() -> ^virtual.Arena {
return pop(&document_storage.free_allocators)
} else {
allocator := new(virtual.Arena)
- _ = virtual.arena_init_growing(allocator)
+ _ = virtual.arena_init_growing(allocator)
return allocator
}
}
@@ -427,6 +428,8 @@ parse_imports :: proc(document: ^Document, config: ^common.Config) {
if i := strings.index(imp.fullpath, "\""); i == -1 {
continue
}
+ // TODO: Breakdown this range like with semantic tokens
+ range := get_import_range(imp, string(document.text))
//collection specified
if i := strings.index(imp.fullpath, ":"); i != -1 && i > 1 && i < len(imp.fullpath) - 1 {
@@ -446,6 +449,7 @@ parse_imports :: proc(document: ^Document, config: ^common.Config) {
import_: Package
import_.original = imp.fullpath
import_.name = strings.clone(path.join(elems = {dir, p}, allocator = context.temp_allocator))
+ import_.range = range
if imp.name.text != "" {
import_.base = imp.name.text
@@ -468,6 +472,7 @@ parse_imports :: proc(document: ^Document, config: ^common.Config) {
allocator = context.temp_allocator,
)
import_.name = path.clean(import_.name)
+ import_.range = range
if imp.name.text != "" {
import_.base = imp.name.text
@@ -488,3 +493,24 @@ parse_imports :: proc(document: ^Document, config: ^common.Config) {
document.imports = imports[:]
}
+
+get_import_range :: proc(imp: ^ast.Import_Decl, src: string) -> common.Range {
+ if imp.name.text != "" {
+ start := common.token_pos_to_position(imp.name.pos, src)
+ end := start
+ end.character += len(imp.name.text)
+ return {
+ start = start,
+ end = end,
+ }
+ }
+
+ start := common.token_pos_to_position(imp.relpath.pos, src)
+ end := start
+ text_len := len(imp.relpath.text)
+ end.character += text_len
+ return {
+ start = start,
+ end = end,
+ }
+}