feat(lsp): pull diagnostics, include links and folding ranges
Assisted-by: GLM 5.3 Flash
This commit is contained in:
+16
-18
@@ -12,9 +12,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"sourcedock.dev/petrbalvin/gasm-devkit/arch"
|
||||
"sourcedock.dev/petrbalvin/gasm-devkit/lint"
|
||||
"sourcedock.dev/petrbalvin/gasm-devkit/parser"
|
||||
"sourcedock.dev/petrbalvin/gasm-devkit/token"
|
||||
)
|
||||
|
||||
@@ -136,6 +134,9 @@ func (s *Server) dispatch(msg *rpcMessage) (exit bool) {
|
||||
CodeActionProvider: true,
|
||||
SignatureHelpProvider: map[string]any{"triggerCharacters": []string{"("}},
|
||||
WorkspaceSymbolProvider: true,
|
||||
DiagnosticProvider: map[string]any{"interFileDependencies": false, "workspaceDiagnostics": false},
|
||||
DocumentLinkProvider: map[string]any{},
|
||||
FoldingRangeProvider: true,
|
||||
},
|
||||
ServerInfo: map[string]string{"name": "gasm", "version": "0.31.1"},
|
||||
})
|
||||
@@ -229,6 +230,18 @@ func (s *Server) dispatch(msg *rpcMessage) (exit bool) {
|
||||
json.Unmarshal(msg.Params, &p)
|
||||
s.respond(msg.ID, s.semanticTokens(p))
|
||||
|
||||
case "textDocument/diagnostic":
|
||||
var p diagnosticParams
|
||||
json.Unmarshal(msg.Params, &p)
|
||||
s.respond(msg.ID, documentDiagnosticReport{Kind: "full", Items: s.diagnosticsFor(p.TextDocument.URI)})
|
||||
case "textDocument/documentLink":
|
||||
var p documentLinkParams
|
||||
json.Unmarshal(msg.Params, &p)
|
||||
s.respond(msg.ID, s.documentLinks(p.TextDocument.URI))
|
||||
case "textDocument/foldingRange":
|
||||
var p foldingRangeParams
|
||||
json.Unmarshal(msg.Params, &p)
|
||||
s.respond(msg.ID, s.foldingRanges(p.TextDocument.URI))
|
||||
case "workspace/symbol":
|
||||
var p workspaceSymbolParams
|
||||
json.Unmarshal(msg.Params, &p)
|
||||
@@ -250,22 +263,7 @@ func (s *Server) dispatch(msg *rpcMessage) (exit bool) {
|
||||
|
||||
// publish parses and lints a document and pushes the diagnostics to the client.
|
||||
func (s *Server) publish(uri string) {
|
||||
text := s.docs[uri]
|
||||
f, _ := parser.Parse(uri, text)
|
||||
cfg := lint.Config{Arch: arch.FromFilename(uriPath(uri))}
|
||||
diags := lint.File(f, cfg)
|
||||
|
||||
out := make([]Diagnostic, 0, len(diags))
|
||||
for _, d := range diags {
|
||||
out = append(out, Diagnostic{
|
||||
Range: toRange(d.Pos.Line, d.Pos.Column, d.End),
|
||||
Severity: lintSeverity(d.Severity),
|
||||
Code: d.Code,
|
||||
Source: "gasm",
|
||||
Message: d.Message,
|
||||
})
|
||||
}
|
||||
s.notify("textDocument/publishDiagnostics", publishDiagnosticsParams{URI: uri, Diagnostics: out})
|
||||
s.notify("textDocument/publishDiagnostics", publishDiagnosticsParams{URI: uri, Diagnostics: s.diagnosticsFor(uri)})
|
||||
}
|
||||
|
||||
// toRange converts one-based line/column plus an optional end position into an
|
||||
|
||||
Reference in New Issue
Block a user