aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2022-08-18 20:38:11 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2022-08-18 20:38:11 +0200
commitc2d22e05604e47aad77d0305385880687508912c (patch)
tree107df9cd9291b32788526ea7040666f50c6957e4 /src
parent20bcae6c14773217c6e9a3217150ac4468036e64 (diff)
Change resolve structure to fix debug crash in Odin
Diffstat (limited to 'src')
-rw-r--r--src/odin/printer/visit.odin28
-rw-r--r--src/server/caches.odin25
-rw-r--r--src/server/documents.odin2
-rw-r--r--src/server/requests.odin12
4 files changed, 48 insertions, 19 deletions
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin
index acc9021..e59cd35 100644
--- a/src/odin/printer/visit.odin
+++ b/src/odin/printer/visit.odin
@@ -374,6 +374,28 @@ is_values_nestable_assign :: proc(list: []^ast.Expr) -> bool {
return false
}
+//Should the return stmt list behave like a call expression.
+@(private)
+is_values_return_stmt_callable :: proc(list: []^ast.Expr) -> bool {
+ if len(list) > 1 {
+ return false
+ }
+
+ for expr in list {
+ result := expr
+ if paren, is_paren := expr.derived.(^ast.Paren_Expr); is_paren {
+ result = paren.expr
+ }
+
+ #partial switch v in result.derived {
+ case ^ast.Call_Expr:
+ return false
+ }
+ }
+ return true
+}
+
+
@(private)
is_values_nestable_if_break_assign :: proc(list: []^ast.Expr) -> bool {
@@ -677,8 +699,10 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
if_document = cons_with_nopl(if_document, cons(group(visit_stmt(p, v.init)), text(";")))
}
- if v.cond != nil {
+ if v.cond != nil && v.init != nil {
if_document = cons_with_opl(if_document, group(visit_expr(p, v.cond)))
+ } else if v.cond != nil {
+ if_document = cons_with_nopl(if_document, group(visit_expr(p, v.cond)))
}
document = cons(document, group(hang(3, if_document)))
@@ -858,7 +882,7 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener
break
}
- if len(v.results) == 1 {
+ if is_values_return_stmt_callable(v.results) {
result := v.results[0]
if paren, is_paren := result.derived.(^ast.Paren_Expr); is_paren {
diff --git a/src/server/caches.odin b/src/server/caches.odin
index 4acc3af..80128f4 100644
--- a/src/server/caches.odin
+++ b/src/server/caches.odin
@@ -5,26 +5,33 @@ import "shared:common"
import "core:time"
//Used in semantic tokens and inlay hints to handle the entire file being resolved.
+
+FileResolve :: struct {
+ symbols: map[uintptr]SymbolAndNode,
+}
+
+
FileResolveCache :: struct {
- files: map[string]map[uintptr]SymbolAndNode,
+ files: map[string]FileResolve,
}
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] = resolve_entire_file(
- document,
- "",
- .None,
- common.scratch_allocator(document.allocator),
- )
+ file_resolve_cache.files[document.uri.uri] = FileResolve {
+ symbols = resolve_entire_file(
+ document,
+ "",
+ .None,
+ common.scratch_allocator(document.allocator),
+ ),
+ }
}
- return file_resolve_cache.files[document.uri.uri];
+ return file_resolve_cache.files[document.uri.uri].symbols;
}
-
BuildCache :: struct {
loaded_pkgs: map[string]PackageCacheInfo,
}
diff --git a/src/server/documents.odin b/src/server/documents.odin
index d5b0f09..52309ed 100644
--- a/src/server/documents.odin
+++ b/src/server/documents.odin
@@ -378,9 +378,7 @@ parse_document :: proc(document: ^Document, config: ^common.Config) -> ([]Parser
current_errors = make([dynamic]ParserError, context.temp_allocator)
if document.uri.uri in file_resolve_cache.files {
- key := file_resolve_cache.files[document.uri.uri]
delete_key(&file_resolve_cache.files, document.uri.uri)
- delete(key)
}
free_all(common.scratch_allocator(document.allocator))
diff --git a/src/server/requests.odin b/src/server/requests.odin
index cd2677f..29e78c1 100644
--- a/src/server/requests.odin
+++ b/src/server/requests.odin
@@ -889,8 +889,8 @@ request_semantic_token_full :: proc (params: json.Value, id: RequestId, config:
if config.enable_semantic_tokens {
resolve_entire_file_cached(document)
- if cache_symbols, ok := file_resolve_cache.files[document.uri.uri]; ok {
- symbols = get_semantic_tokens(document, range, cache_symbols)
+ if file, ok := file_resolve_cache.files[document.uri.uri]; ok {
+ symbols = get_semantic_tokens(document, range, file.symbols)
}
}
@@ -923,8 +923,8 @@ request_semantic_token_range :: proc (params: json.Value, id: RequestId, config:
symbols: SemanticTokens
if config.enable_semantic_tokens {
- if cache_symbols, ok := file_resolve_cache.files[document.uri.uri]; ok {
- symbols = get_semantic_tokens(document, semantic_params.range, cache_symbols)
+ if file, ok := file_resolve_cache.files[document.uri.uri]; ok {
+ symbols = get_semantic_tokens(document, semantic_params.range, file.symbols)
}
}
@@ -1025,8 +1025,8 @@ request_inlay_hint :: proc (params: json.Value, id: RequestId, config: ^common.C
resolve_entire_file_cached(document)
- if cache_symbols, ok := file_resolve_cache.files[document.uri.uri]; ok {
- hints, ok = get_inlay_hints(document, cache_symbols)
+ if file, ok := file_resolve_cache.files[document.uri.uri]; ok {
+ hints, ok = get_inlay_hints(document, file.symbols)
}
if !ok {