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) { 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.ServerTextDocumentPublishDiagnostics,
protocol.PublishDiagnosticsParams{ protocol.PublishDiagnosticsParams{
URI: uri, URI: uri,

View File

@ -18,6 +18,11 @@ func TextDocumentDidChange(context *glsp.Context, params *protocol.DidChangeText
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI) language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
content := params.ContentChanges[0].(protocol.TextDocumentContentChangeEventWhole).Text content := params.ContentChanges[0].(protocol.TextDocumentContentChangeEventWhole).Text
if _, found := shared.OpenedFiles[params.TextDocument.URI]; !found {
// The file couldn't be initialized when opening it,
// so we will try it again here
newLanguage, err := initFile( newLanguage, err := initFile(
context, context,
content, content,
@ -45,19 +50,7 @@ func TextDocumentDidChange(context *glsp.Context, params *protocol.DidChangeText
}, },
} }
switch *language { return TextDocumentDidOpen(context, params)
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)
} }
} }

View File

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