mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package lsp
|
|
|
|
import (
|
|
"config-lsp/common"
|
|
sshconfig "config-lsp/handlers/ssh_config"
|
|
"config-lsp/handlers/ssh_config/analyzer"
|
|
"config-lsp/utils"
|
|
|
|
"github.com/tliron/glsp"
|
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
|
)
|
|
|
|
func TextDocumentDidChange(
|
|
context *glsp.Context,
|
|
params *protocol.DidChangeTextDocumentParams,
|
|
) error {
|
|
content := params.ContentChanges[0].(protocol.TextDocumentContentChangeEventWhole).Text
|
|
common.ClearDiagnostics(context, params.TextDocument.URI)
|
|
|
|
document := sshconfig.DocumentParserMap[params.TextDocument.URI]
|
|
document.Config.Clear()
|
|
|
|
diagnostics := make([]protocol.Diagnostic, 0)
|
|
errors := document.Config.Parse(content)
|
|
|
|
if len(errors) > 0 {
|
|
diagnostics = append(diagnostics, utils.Map(
|
|
errors,
|
|
func(err common.LSPError) protocol.Diagnostic {
|
|
return err.ToDiagnostic()
|
|
},
|
|
)...)
|
|
}
|
|
|
|
diagnostics = append(diagnostics, analyzer.Analyze(document)...)
|
|
|
|
if len(diagnostics) > 0 {
|
|
common.SendDiagnostics(context, params.TextDocument.URI, diagnostics)
|
|
}
|
|
|
|
return nil
|
|
}
|