mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
feat(server): Show code action to add a language
This commit is contained in:
parent
ec4deeb59f
commit
9378392927
43
server/root-handler/code-actions.go
Normal file
43
server/root-handler/code-actions.go
Normal file
@ -0,0 +1,43 @@
|
||||
package roothandler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func fetchAddLanguageActions(uri protocol.DocumentUri) ([]protocol.CodeAction, error) {
|
||||
actions := make([]protocol.CodeAction, 0, len(AllSupportedLanguages))
|
||||
|
||||
kind := protocol.CodeActionKindQuickFix
|
||||
isPreferred := true
|
||||
|
||||
for _, language := range AllSupportedLanguages {
|
||||
actions = append(actions, protocol.CodeAction{
|
||||
Title: fmt.Sprintf("Use %s for this file", language),
|
||||
Kind: &kind,
|
||||
IsPreferred: &isPreferred,
|
||||
Edit: &protocol.WorkspaceEdit{
|
||||
Changes: map[protocol.DocumentUri][]protocol.TextEdit{
|
||||
uri: {
|
||||
{
|
||||
Range: protocol.Range{
|
||||
Start: protocol.Position{
|
||||
Line: 0,
|
||||
Character: 0,
|
||||
},
|
||||
End: protocol.Position{
|
||||
Line: 0,
|
||||
Character: 0,
|
||||
},
|
||||
},
|
||||
NewText: fmt.Sprintf("#?lsp.language=%s\n", language),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return actions, nil
|
||||
}
|
@ -83,9 +83,14 @@ var filenameToLanguageMap = map[string]SupportedLanguage{
|
||||
"sshd_config": LanguageSSHDConfig,
|
||||
"sshdconfig": LanguageSSHDConfig,
|
||||
"sshd": LanguageSSHDConfig,
|
||||
"sshd_conf": LanguageSSHDConfig,
|
||||
"sshdconf": LanguageSSHDConfig,
|
||||
|
||||
"ssh_config": LanguageSSHConfig,
|
||||
"sshconfig": LanguageSSHConfig,
|
||||
"ssh": LanguageSSHConfig,
|
||||
"ssh_conf": LanguageSSHConfig,
|
||||
"sshconf": LanguageSSHConfig,
|
||||
|
||||
"fstab": LanguageFstab,
|
||||
|
||||
@ -93,15 +98,10 @@ var filenameToLanguageMap = map[string]SupportedLanguage{
|
||||
|
||||
"aliases": LanguageAliases,
|
||||
"mailaliases": LanguageAliases,
|
||||
|
||||
"wg": LanguageWireguard,
|
||||
"wg.conf": LanguageWireguard,
|
||||
"wg0.conf": LanguageWireguard,
|
||||
"wg0": LanguageWireguard,
|
||||
}
|
||||
|
||||
var typeOverwriteRegex = regexp.MustCompile(`#\?\s*lsp\.language\s*=\s*(\w+)\s*`)
|
||||
var wireguardPattern = regexp.MustCompile(`/wg\d+\.conf$`)
|
||||
var wireguardPattern = regexp.MustCompile(`wg(\d+)?(\.conf)?$`)
|
||||
|
||||
var undetectableError = common.ParseError{
|
||||
Line: 0,
|
||||
|
@ -20,7 +20,7 @@ func TextDocumentCodeAction(context *glsp.Context, params *protocol.CodeActionPa
|
||||
undetectableError,
|
||||
)
|
||||
|
||||
return nil, nil
|
||||
return fetchAddLanguageActions(params.TextDocument.URI)
|
||||
}
|
||||
|
||||
switch *language {
|
||||
|
Loading…
x
Reference in New Issue
Block a user