mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +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,
|
matchBlock.MatchValue,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if entry.Key.Key == tagOption {
|
||||||
|
return getTagCompletions(
|
||||||
|
d,
|
||||||
|
cursor,
|
||||||
|
entry,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if entry.OptionValue == nil {
|
if entry.OptionValue == nil {
|
||||||
return option.DeprecatedFetchCompletions("", 0), 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 hostOption = fields.CreateNormalizedName("Host")
|
||||||
var matchOption = fields.CreateNormalizedName("Match")
|
var matchOption = fields.CreateNormalizedName("Match")
|
||||||
|
var tagOption = fields.CreateNormalizedName("Tag")
|
||||||
|
|
||||||
func FormatDocument(
|
func FormatDocument(
|
||||||
d *sshconfig.SSHDocument,
|
d *sshconfig.SSHDocument,
|
||||||
|
@ -49,7 +49,10 @@ func formatOption(
|
|||||||
template = blockOptionTemplate
|
template = blockOptionTemplate
|
||||||
}
|
}
|
||||||
|
|
||||||
edits = append(edits, formatSSHOption(option, options, template)...)
|
edits = append(edits, protocol.TextEdit{
|
||||||
|
Range: option.ToLSPRange(),
|
||||||
|
NewText: formatOptionToString(option, options, template),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return edits
|
return edits
|
||||||
@ -101,11 +104,11 @@ func formatMatchBlock(
|
|||||||
return edits
|
return edits
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatSSHOption(
|
func formatOptionToString(
|
||||||
option *ast.SSHOption,
|
option *ast.SSHOption,
|
||||||
options protocol.FormattingOptions,
|
options protocol.FormattingOptions,
|
||||||
template formatting.FormatTemplate,
|
template formatting.FormatTemplate,
|
||||||
) []protocol.TextEdit {
|
) string {
|
||||||
var key string
|
var key string
|
||||||
|
|
||||||
if option.Key != nil {
|
if option.Key != nil {
|
||||||
@ -126,12 +129,7 @@ func formatSSHOption(
|
|||||||
value = ""
|
value = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return []protocol.TextEdit{
|
return template.Format(options, key, value)
|
||||||
{
|
|
||||||
Range: option.ToLSPRange(),
|
|
||||||
NewText: template.Format(options, key, value),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatMatchToString(
|
func formatMatchToString(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user