aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Tarnawski <gthetarnav@gmail.com>2025-10-01 14:19:48 +0200
committerDamian Tarnawski <gthetarnav@gmail.com>2025-10-01 14:19:48 +0200
commitd64c916e7b4faf278b3991adb3f3c1b3fd9dec31 (patch)
tree55add650b1e14021611700b3d3c43371a4836da0
parent029e0a1fb4bb006c6fd059e05439239486b9976a (diff)
Use document range in get_inlay_hints
-rw-r--r--src/server/caches.odin25
-rw-r--r--src/server/inlay_hints.odin9
-rw-r--r--src/server/requests.odin11
-rw-r--r--src/testing/testing.odin8
4 files changed, 39 insertions, 14 deletions
diff --git a/src/server/caches.odin b/src/server/caches.odin
index f1cdc2e..a65de48 100644
--- a/src/server/caches.odin
+++ b/src/server/caches.odin
@@ -25,14 +25,31 @@ FileResolveCache :: struct {
@(thread_local)
file_resolve_cache: FileResolveCache
-resolve_entire_file_cached :: proc(document: ^Document) -> map[uintptr]SymbolAndNode {
- if document.uri.uri not_in file_resolve_cache.files {
- file_resolve_cache.files[document.uri.uri] = FileResolve {
+resolve_entire_file_cached :: proc(document: ^Document) -> FileResolve {
+
+ file, cashed := file_resolve_cache.files[document.uri.uri]
+
+ if !cashed {
+ file = {
symbols = resolve_entire_file(document, .None, virtual.arena_allocator(document.allocator)),
}
+ file_resolve_cache.files[document.uri.uri] = file
+ }
+
+ return file
+}
+
+resolve_ranged_file_cached :: proc(document: ^Document, range: common.Range, allocator := context.allocator) -> FileResolve {
+
+ file, cashed := file_resolve_cache.files[document.uri.uri]
+
+ if !cashed {
+ file = {
+ symbols = resolve_ranged_file(document, range, allocator),
+ }
}
- return file_resolve_cache.files[document.uri.uri].symbols
+ return file
}
BuildCache :: struct {
diff --git a/src/server/inlay_hints.odin b/src/server/inlay_hints.odin
index a91cd7a..a62a708 100644
--- a/src/server/inlay_hints.odin
+++ b/src/server/inlay_hints.odin
@@ -9,6 +9,7 @@ import "src:common"
get_inlay_hints :: proc(
document: ^Document,
+ range: common.Range,
symbols: map[uintptr]SymbolAndNode,
config: ^common.Config,
) -> (
@@ -17,6 +18,7 @@ get_inlay_hints :: proc(
) {
Visitor_Data :: struct {
document: ^Document,
+ range: common.Range,
symbols: map[uintptr]SymbolAndNode,
config: ^common.Config,
hints: [dynamic]InlayHint,
@@ -31,6 +33,7 @@ get_inlay_hints :: proc(
data := Visitor_Data{
document = document,
+ range = range,
symbols = symbols,
config = config,
procs = make([dynamic]Proc_Data, context.temp_allocator),
@@ -51,6 +54,12 @@ get_inlay_hints :: proc(
return nil
}
+ margin := 20 // skip nodes outside the range
+ if data.range.start.line - margin > node.end.line &&
+ data.range.end.line + margin < node.pos.line {
+ return nil
+ }
+
data.depth += 1
add_param_hints(node, data)
diff --git a/src/server/requests.odin b/src/server/requests.odin
index 860e8c4..511832a 100644
--- a/src/server/requests.odin
+++ b/src/server/requests.odin
@@ -1212,9 +1212,9 @@ request_semantic_token_range :: proc(
tokens_params: SemanticTokensResponseParams
if config.enable_semantic_tokens {
- symbols := resolve_ranged_file(document, semantic_params.range, context.temp_allocator)
+ file := resolve_ranged_file_cached(document, semantic_params.range, context.temp_allocator)
- tokens := get_semantic_tokens(document, semantic_params.range, symbols)
+ tokens := get_semantic_tokens(document, semantic_params.range, file.symbols)
tokens_params = semantic_tokens_to_response_params(tokens)
}
@@ -1314,12 +1314,9 @@ request_inlay_hint :: proc(
document := document_get(inlay_params.textDocument.uri)
if document == nil do return .InternalError
- resolve_ranged_file(document, inlay_params.range, context.temp_allocator)
+ file := resolve_ranged_file_cached(document, inlay_params.range, context.temp_allocator)
- file, file_ok := file_resolve_cache.files[document.uri.uri]
- if !file_ok do return .InternalError
-
- hints, hints_ok := get_inlay_hints(document, file.symbols, config)
+ hints, hints_ok := get_inlay_hints(document, inlay_params.range, file.symbols, config)
if !hints_ok do return .InternalError
response := make_response_message(params = hints, id = id)
diff --git a/src/testing/testing.odin b/src/testing/testing.odin
index 66ed992..4cb9484 100644
--- a/src/testing/testing.odin
+++ b/src/testing/testing.odin
@@ -584,10 +584,12 @@ expect_inlay_hints :: proc(t: ^testing.T, src: ^Source) {
setup(src)
defer teardown(src)
- resolve_flag: server.ResolveReferenceFlag
- symbols_and_nodes := server.resolve_entire_file(src.document, resolve_flag, )
+ symbols_and_nodes := server.resolve_entire_file(src.document, allocator=context.temp_allocator)
- hints, hints_ok := server.get_inlay_hints(src.document, symbols_and_nodes, &src.config)
+ range := common.Range {
+ end = {line = 9000000},
+ } //should be enough
+ hints, hints_ok := server.get_inlay_hints(src.document, range, symbols_and_nodes, &src.config)
if !hints_ok {
log.error("Failed get_inlay_hints")
return