mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
feat(ssh_config): Add hover support
This commit is contained in:
parent
614463d429
commit
413d919719
59
handlers/ssh_config/handlers/hover.go
Normal file
59
handlers/ssh_config/handlers/hover.go
Normal file
@ -0,0 +1,59 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
"config-lsp/handlers/ssh_config/ast"
|
||||
"config-lsp/handlers/ssh_config/fields"
|
||||
"strings"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func GetHoverInfoForOption(
|
||||
option *ast.SSHOption,
|
||||
line uint32,
|
||||
index common.IndexPosition,
|
||||
) (*protocol.Hover, error) {
|
||||
docValue, found := fields.Options[option.Key.Key]
|
||||
|
||||
if !found {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if option.Key.ContainsPosition(index) {
|
||||
optionName := fields.FieldsNameFormattedMap[option.Key.Key]
|
||||
contents := []string{
|
||||
"## " + optionName,
|
||||
"",
|
||||
}
|
||||
contents = append(contents, docValue.Documentation)
|
||||
contents = append(contents, []string{
|
||||
"",
|
||||
"---",
|
||||
"",
|
||||
}...)
|
||||
contents = append(contents, []string{
|
||||
"### Type",
|
||||
"",
|
||||
}...)
|
||||
contents = append(contents, docValue.GetTypeDescription()...)
|
||||
|
||||
return &protocol.Hover{
|
||||
Contents: strings.Join(contents, "\n"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
if option.OptionValue != nil && option.OptionValue.ContainsPosition(index) {
|
||||
line := option.OptionValue.Value.Raw
|
||||
contents := docValue.DeprecatedFetchHoverInfo(
|
||||
line,
|
||||
uint32(option.OptionValue.Start.GetRelativeIndexPosition(index)),
|
||||
)
|
||||
|
||||
return &protocol.Hover{
|
||||
Contents: strings.Join(contents, "\n"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
package lsp
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
sshconfig "config-lsp/handlers/ssh_config"
|
||||
"config-lsp/handlers/ssh_config/handlers"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
@ -9,5 +13,21 @@ func TextDocumentHover(
|
||||
context *glsp.Context,
|
||||
params *protocol.HoverParams,
|
||||
) (*protocol.Hover, error) {
|
||||
line := params.Position.Line
|
||||
index := common.LSPCharacterAsIndexPosition(params.Position.Character)
|
||||
|
||||
d := sshconfig.DocumentParserMap[params.TextDocument.URI]
|
||||
|
||||
option, _ := d.Config.FindOption(line)
|
||||
|
||||
if option == nil || option.Key == nil {
|
||||
// Empty line
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return handlers.GetHoverInfoForOption(
|
||||
option,
|
||||
line,
|
||||
index,
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user