mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
fix(server): Fix didChange and didOpen
This commit is contained in:
parent
7a92594135
commit
cc92cacd48
@ -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,
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user