From ef737e194afd0c03186e3eeae82bcecb7cb127c4 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:20:18 +0200 Subject: [PATCH] feat(sshd_config): Add support for token completions --- .../handlers/sshd_config/analyzer/options.go | 2 +- server/handlers/sshd_config/ast/listener.go | 3 +- .../handlers/sshd_config/ast/sshd_config.go | 4 +- server/handlers/sshd_config/fields/tokens.go | 71 +++++++++++++++++++ .../sshd_config/handlers/completions.go | 42 +++++++++-- .../sshd_config/handlers/completions_match.go | 8 +-- .../sshd_config/handlers/formatting_nodes.go | 7 +- server/handlers/sshd_config/handlers/hover.go | 2 +- .../sshd_config/indexes/indexes_handlers.go | 2 +- .../lsp/text-document-completion.go | 2 +- 10 files changed, 123 insertions(+), 20 deletions(-) create mode 100644 server/handlers/sshd_config/fields/tokens.go diff --git a/server/handlers/sshd_config/analyzer/options.go b/server/handlers/sshd_config/analyzer/options.go index 0c13f62..8337ade 100644 --- a/server/handlers/sshd_config/analyzer/options.go +++ b/server/handlers/sshd_config/analyzer/options.go @@ -40,7 +40,7 @@ func checkOption( checkIsUsingDoubleQuotes(ctx, option.Key.Value, option.Key.LocationRange) checkQuotesAreClosed(ctx, option.Key.Value, option.Key.LocationRange) - key := fields.CreateNormalizedName(option.Key.Key) + key := option.Key.Key docOption, found := fields.Options[key] if !found { diff --git a/server/handlers/sshd_config/ast/listener.go b/server/handlers/sshd_config/ast/listener.go index cc5a414..287c1fb 100644 --- a/server/handlers/sshd_config/ast/listener.go +++ b/server/handlers/sshd_config/ast/listener.go @@ -4,6 +4,7 @@ import ( "config-lsp/common" commonparser "config-lsp/common/parser" "config-lsp/handlers/sshd_config/ast/parser" + "config-lsp/handlers/sshd_config/fields" "config-lsp/handlers/sshd_config/match-parser" "strings" @@ -76,7 +77,7 @@ func (s *sshdParserListener) EnterKey(ctx *parser.KeyContext) { s.sshdContext.currentOption.Key = &SSHDKey{ LocationRange: location, Value: value, - Key: key, + Key: fields.CreateNormalizedName(key), } } diff --git a/server/handlers/sshd_config/ast/sshd_config.go b/server/handlers/sshd_config/ast/sshd_config.go index 73513e2..f29285c 100644 --- a/server/handlers/sshd_config/ast/sshd_config.go +++ b/server/handlers/sshd_config/ast/sshd_config.go @@ -3,14 +3,16 @@ package ast import ( "config-lsp/common" commonparser "config-lsp/common/parser" + "config-lsp/handlers/sshd_config/fields" "config-lsp/handlers/sshd_config/match-parser" + "github.com/emirpasic/gods/maps/treemap" ) type SSHDKey struct { common.LocationRange Value commonparser.ParsedString - Key string + Key fields.NormalizedOptionName } type SSHDValue struct { diff --git a/server/handlers/sshd_config/fields/tokens.go b/server/handlers/sshd_config/fields/tokens.go new file mode 100644 index 0000000..ee9d875 --- /dev/null +++ b/server/handlers/sshd_config/fields/tokens.go @@ -0,0 +1,71 @@ +package fields + +var AvailableTokens = map[string]string{ + "%%": "A literal ‘%’.", + "%C": "Identifies the connection endpoints, containing four space-separated values: client address, client port number, server address, and server port number.", + "%D": "The routing domain in which the incoming connection was received.", + "%F": "The fingerprint of the CA key.", + "%f": "The fingerprint of the key or certificate.", + "%h": "The home directory of the user.", + "%i": "The key ID in the certificate.", + "%K": "The base64-encoded CA key.", + "%k": "The base64-encoded key or certificate for authentication.", + "%s": "The serial number of the certificate.", + "%T": "The type of the CA key.", + "%t": "The key or certificate type.", + "%U": "The numeric user ID of the target user.", + "%u": "The username.", +} + +// A map of