aboutsummaryrefslogtreecommitdiff
path: root/src/server/documents.odin
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2025-10-05 13:04:00 +0200
committerGitHub <noreply@github.com>2025-10-05 13:04:00 +0200
commit359c6ebffa2b9781bc772297182025d00ea4af29 (patch)
tree7ac52a94ee4e06049cabd340461c0d5635f87302 /src/server/documents.odin
parent317b9b7f34b4876fa0b69591c1d31a3c0cb46f6a (diff)
parent3771a25f9ea4de11b1eb4a1545a314c04df99ad0 (diff)
Merge pull request #1040 from DanielGavin/remove-unused-imports
Add new code action: remove unused imports
Diffstat (limited to 'src/server/documents.odin')
-rw-r--r--src/server/documents.odin72
1 files changed, 22 insertions, 50 deletions
diff --git a/src/server/documents.odin b/src/server/documents.odin
index 15e7ad6..a23fdf2 100644
--- a/src/server/documents.odin
+++ b/src/server/documents.odin
@@ -30,6 +30,7 @@ Package :: struct {
base_original: string,
original: string,
range: common.Range,
+ import_decl: ^ast.Import_Decl,
}
Document :: struct {
@@ -158,8 +159,6 @@ document_open :: proc(uri_string: string, text: string, config: ^common.Config,
document_storage.documents[strings.clone(uri.path)] = document
}
- delete(uri_string)
-
return .None
}
@@ -319,52 +318,29 @@ document_refresh :: proc(document: ^Document, config: ^common.Config, writer: ^W
return .None
}
- if writer != nil && len(errors) > 0 && !config.disable_parser_errors {
- document.diagnosed_errors = true
+ remove_diagnostics(.Syntax, document.uri.uri)
+ remove_diagnostics(.Check, document.uri.uri)
- params := NotificationPublishDiagnosticsParams {
- uri = document.uri.uri,
- diagnostics = make([]Diagnostic, len(errors), context.temp_allocator),
- }
+ if writer != nil && !config.disable_parser_errors {
+ document.diagnosed_errors = true
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},
+ add_diagnostics(
+ .Syntax,
+ document.uri.uri,
+ 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,
- }
- }
-
- notifaction := Notification {
- jsonrpc = "2.0",
- method = "textDocument/publishDiagnostics",
- params = params,
+ )
}
- 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)
- }
+ push_diagnostics(writer)
}
return .None
@@ -450,6 +426,7 @@ parse_imports :: proc(document: ^Document, config: ^common.Config) {
import_.original = imp.fullpath
import_.name = strings.clone(path.join(elems = {dir, p}, allocator = context.temp_allocator))
import_.range = range
+ import_.import_decl = imp
if imp.name.text != "" {
import_.base = imp.name.text
@@ -473,6 +450,7 @@ parse_imports :: proc(document: ^Document, config: ^common.Config) {
)
import_.name = path.clean(import_.name)
import_.range = range
+ import_.import_decl = imp
if imp.name.text != "" {
import_.base = imp.name.text
@@ -499,18 +477,12 @@ get_import_range :: proc(imp: ^ast.Import_Decl, src: string) -> common.Range {
start := common.token_pos_to_position(imp.name.pos, src)
end := start
end.character += len(imp.name.text)
- return {
- start = start,
- end = end,
- }
+ 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,
- }
+ return {start = start, end = end}
}