mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
feat(ssh_config): Add completions for tag
This commit is contained in:
parent
7359fac2e0
commit
eda3a0e771
@ -81,6 +81,13 @@ func GetOptionCompletions(
|
||||
matchBlock.MatchValue,
|
||||
)
|
||||
}
|
||||
if entry.Key.Key == tagOption {
|
||||
return getTagCompletions(
|
||||
d,
|
||||
cursor,
|
||||
entry,
|
||||
)
|
||||
}
|
||||
|
||||
if entry.OptionValue == nil {
|
||||
return option.DeprecatedFetchCompletions("", 0), nil
|
||||
|
50
handlers/ssh_config/handlers/completions_tag.go
Normal file
50
handlers/ssh_config/handlers/completions_tag.go
Normal file
@ -0,0 +1,50 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
"config-lsp/common/formatting"
|
||||
sshconfig "config-lsp/handlers/ssh_config"
|
||||
"config-lsp/handlers/ssh_config/ast"
|
||||
"config-lsp/utils"
|
||||
"fmt"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func getTagCompletions(
|
||||
d *sshconfig.SSHDocument,
|
||||
cursor common.CursorPosition,
|
||||
entry *ast.SSHOption,
|
||||
) ([]protocol.CompletionItem, error) {
|
||||
return utils.MapMapToSlice(
|
||||
d.Indexes.Tags,
|
||||
func(name string, block *ast.SSHMatchBlock) protocol.CompletionItem {
|
||||
kind := protocol.CompletionItemKindModule
|
||||
text := renderMatchBlock(block)
|
||||
return protocol.CompletionItem{
|
||||
Label: name,
|
||||
Kind: &kind,
|
||||
Documentation: protocol.MarkupContent{
|
||||
Kind: protocol.MarkupKindMarkdown,
|
||||
Value: fmt.Sprintf("```sshconfig\n%s\n```", text),
|
||||
},
|
||||
}
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
func renderMatchBlock(
|
||||
block *ast.SSHMatchBlock,
|
||||
) string {
|
||||
text := ""
|
||||
|
||||
text += "Match " + formatMatchToString(block.MatchValue) + "\n"
|
||||
|
||||
it := block.Options.Iterator()
|
||||
for it.Next() {
|
||||
option := it.Value().(*ast.SSHOption)
|
||||
text += formatOptionToString(option, formatting.DefaultFormattingOptions, blockOptionTemplate) + "\n"
|
||||
}
|
||||
|
||||
return text
|
||||
}
|
@ -9,6 +9,7 @@ import (
|
||||
|
||||
var hostOption = fields.CreateNormalizedName("Host")
|
||||
var matchOption = fields.CreateNormalizedName("Match")
|
||||
var tagOption = fields.CreateNormalizedName("Tag")
|
||||
|
||||
func FormatDocument(
|
||||
d *sshconfig.SSHDocument,
|
||||
|
@ -49,7 +49,10 @@ func formatOption(
|
||||
template = blockOptionTemplate
|
||||
}
|
||||
|
||||
edits = append(edits, formatSSHOption(option, options, template)...)
|
||||
edits = append(edits, protocol.TextEdit{
|
||||
Range: option.ToLSPRange(),
|
||||
NewText: formatOptionToString(option, options, template),
|
||||
})
|
||||
}
|
||||
|
||||
return edits
|
||||
@ -101,11 +104,11 @@ func formatMatchBlock(
|
||||
return edits
|
||||
}
|
||||
|
||||
func formatSSHOption(
|
||||
func formatOptionToString(
|
||||
option *ast.SSHOption,
|
||||
options protocol.FormattingOptions,
|
||||
template formatting.FormatTemplate,
|
||||
) []protocol.TextEdit {
|
||||
) string {
|
||||
var key string
|
||||
|
||||
if option.Key != nil {
|
||||
@ -126,12 +129,7 @@ func formatSSHOption(
|
||||
value = ""
|
||||
}
|
||||
|
||||
return []protocol.TextEdit{
|
||||
{
|
||||
Range: option.ToLSPRange(),
|
||||
NewText: template.Format(options, key, value),
|
||||
},
|
||||
}
|
||||
return template.Format(options, key, value)
|
||||
}
|
||||
|
||||
func formatMatchToString(
|
||||
|
Loading…
x
Reference in New Issue
Block a user