fix(server): Fix didChange and didOpen

This commit is contained in:
Myzel394 2025-03-03 21:43:16 +01:00 committed by Myzel394
parent ae840bb4ca
commit 34bc469f70
3 changed files with 32 additions and 39 deletions

View File

@ -6,7 +6,10 @@ import (
)
func ClearDiagnostics(context *glsp.Context, uri protocol.DocumentUri) {
go context.Notify(
// Diagnostics are sent synchronously, as sending them async
// could result in a race condition when we send diagnostics
// to the client.
context.Notify(
protocol.ServerTextDocumentPublishDiagnostics,
protocol.PublishDiagnosticsParams{
URI: uri,

View File

@ -18,46 +18,39 @@ func TextDocumentDidChange(context *glsp.Context, params *protocol.DidChangeText
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
content := params.ContentChanges[0].(protocol.TextDocumentContentChangeEventWhole).Text
newLanguage, err := initFile(
context,
content,
params.TextDocument.URI,
"",
)
if err != nil {
if common.ServerOptions.NoUndetectableErrors {
return nil
} else {
return err
}
}
if _, found := shared.OpenedFiles[params.TextDocument.URI]; !found {
// The file couldn't be initialized when opening it,
// so we will try it again here
if newLanguage != language {
language = newLanguage
newLanguage, err := initFile(
context,
content,
params.TextDocument.URI,
"",
)
params := &protocol.DidOpenTextDocumentParams{
TextDocument: protocol.TextDocumentItem{
URI: params.TextDocument.URI,
Text: content,
Version: params.TextDocument.Version,
LanguageID: string(*language),
},
if err != nil {
if common.ServerOptions.NoUndetectableErrors {
return nil
} else {
return err
}
}
switch *language {
case shared.LanguageFstab:
return fstab.TextDocumentDidOpen(context, params)
case shared.LanguageSSHDConfig:
return sshdconfig.TextDocumentDidOpen(context, params)
case shared.LanguageSSHConfig:
return sshconfig.TextDocumentDidOpen(context, params)
case shared.LanguageWireguard:
return wireguard.TextDocumentDidOpen(context, params)
case shared.LanguageHosts:
return hosts.TextDocumentDidOpen(context, params)
case shared.LanguageAliases:
return aliases.TextDocumentDidOpen(context, params)
if newLanguage != language {
language = newLanguage
params := &protocol.DidOpenTextDocumentParams{
TextDocument: protocol.TextDocumentItem{
URI: params.TextDocument.URI,
Text: content,
Version: params.TextDocument.Version,
LanguageID: string(*language),
},
}
return TextDocumentDidOpen(context, params)
}
}

View File

@ -61,9 +61,6 @@ func initFile(
uri protocol.DocumentUri,
advertisedLanguage string,
) (*shared.SupportedLanguage, error) {
println("Initializing the file")
println(advertisedLanguage)
println(uri)
language, err := utils.DetectLanguage(content, advertisedLanguage, uri)
if err != nil {