aboutsummaryrefslogtreecommitdiff
path: root/src/server/documents.odin
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2025-09-22 22:33:28 +0200
committerDanielGavin <danielgavin5@hotmail.com>2025-09-22 22:33:28 +0200
commit0cc6300920f1a8b8f5191f30f9f5eae1b301959d (patch)
tree0c1827fc11d9c12071fe02a4ae66f4dbd1b418b6 /src/server/documents.odin
parent28d540bb5f838815e23622d97cd5d3a55776414d (diff)
Add support for graying out unused imports
Diffstat (limited to 'src/server/documents.odin')
-rw-r--r--src/server/documents.odin65
1 files changed, 35 insertions, 30 deletions
diff --git a/src/server/documents.odin b/src/server/documents.odin
index cf8a344..591c56c 100644
--- a/src/server/documents.odin
+++ b/src/server/documents.odin
@@ -76,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
}
}
@@ -319,26 +319,50 @@ document_refresh :: proc(document: ^Document, config: ^common.Config, writer: ^W
return .None
}
- if writer != nil && len(errors) > 0 && !config.disable_parser_errors {
+ if writer != nil && !config.disable_parser_errors {
document.diagnosed_errors = true
+ diagnostics := make([dynamic]Diagnostic, 0, len(errors), context.temp_allocator)
+
params := NotificationPublishDiagnosticsParams {
- uri = document.uri.uri,
- diagnostics = make([]Diagnostic, len(errors), context.temp_allocator),
+ uri = document.uri.uri,
}
for error, i in errors {
- params.diagnostics[i] = Diagnostic {
- range = common.Range {
- start = common.Position{line = error.line - 1, character = 0},
- end = common.Position{line = error.line, character = 0},
+ append(
+ &diagnostics,
+ Diagnostic {
+ range = common.Range {
+ start = common.Position{line = error.line - 1, character = 0},
+ end = common.Position{line = error.line, character = 0},
+ },
+ severity = DiagnosticSeverity.Error,
+ code = "Syntax",
+ message = error.message,
},
- severity = DiagnosticSeverity.Error,
- code = "Syntax",
- message = error.message,
+ )
+ }
+
+ if config.enable_unused_imports_reporting {
+ unused_imports := find_unused_imports(document, context.temp_allocator)
+
+ for imp in unused_imports {
+ append(
+ &diagnostics,
+ Diagnostic {
+ range = common.get_token_range(imp.import_decl, document.ast.src),
+ severity = DiagnosticSeverity.Hint,
+ code = "Unused",
+ message = "unused import",
+ tags = {.Unnecessary},
+ },
+ )
}
+
}
+ params.diagnostics = diagnostics[:]
+
notifaction := Notification {
jsonrpc = "2.0",
method = "textDocument/publishDiagnostics",
@@ -348,25 +372,6 @@ document_refresh :: proc(document: ^Document, config: ^common.Config, writer: ^W
send_notification(notifaction, writer)
}
- if writer != nil && len(errors) == 0 {
- //send empty diagnosis to remove the clients errors
- if document.diagnosed_errors {
-
- notifaction := Notification {
- jsonrpc = "2.0",
- method = "textDocument/publishDiagnostics",
- params = NotificationPublishDiagnosticsParams {
- uri = document.uri.uri,
- diagnostics = make([]Diagnostic, len(errors), context.temp_allocator),
- },
- }
-
- document.diagnosed_errors = false
-
- send_notification(notifaction, writer)
- }
- }
-
return .None
}