mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package lsp
|
|
|
|
import (
|
|
"config-lsp/common"
|
|
"config-lsp/handlers/hosts"
|
|
"config-lsp/handlers/hosts/analyzer"
|
|
"config-lsp/handlers/hosts/ast"
|
|
"config-lsp/handlers/hosts/indexes"
|
|
"config-lsp/utils"
|
|
|
|
"github.com/tliron/glsp"
|
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
|
)
|
|
|
|
func TextDocumentDidOpen(
|
|
context *glsp.Context,
|
|
params *protocol.DidOpenTextDocumentParams,
|
|
) error {
|
|
common.ClearDiagnostics(context, params.TextDocument.URI)
|
|
|
|
parser := ast.NewHostsParser()
|
|
i := indexes.NewHostsIndexes()
|
|
document := hosts.HostsDocument{
|
|
Parser: &parser,
|
|
Indexes: &i,
|
|
}
|
|
hosts.DocumentParserMap[params.TextDocument.URI] = &document
|
|
|
|
errors := parser.Parse(params.TextDocument.Text)
|
|
diagnostics := make([]protocol.Diagnostic, 0)
|
|
|
|
if len(errors) > 0 {
|
|
diagnostics = utils.Map(
|
|
errors,
|
|
func(err common.LSPError) protocol.Diagnostic {
|
|
return err.ToDiagnostic()
|
|
},
|
|
)
|
|
} else {
|
|
diagnostics = append(
|
|
diagnostics,
|
|
analyzer.Analyze(&document)...,
|
|
)
|
|
}
|
|
|
|
if len(diagnostics) > 0 {
|
|
common.SendDiagnostics(context, params.TextDocument.URI, diagnostics)
|
|
}
|
|
|
|
return nil
|
|
}
|