From b4aaa2cc3a416edb9a95d1fab43a19c81bec0908 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:51:19 +0200 Subject: [PATCH] feat(ssh_config): Add completions support for tokens --- server/handlers/ssh_config/analyzer/tokens.go | 2 +- server/handlers/ssh_config/fields/tokens.go | 44 ++++++++++--------- .../ssh_config/handlers/completions.go | 44 ++++++++++++++++--- .../ssh_config/handlers/completions_match.go | 8 ++-- .../ssh_config/handlers/completions_tag.go | 4 +- .../lsp/text-document-completion.go | 4 +- 6 files changed, 69 insertions(+), 37 deletions(-) diff --git a/server/handlers/ssh_config/analyzer/tokens.go b/server/handlers/ssh_config/analyzer/tokens.go index 58341bd..6d35585 100644 --- a/server/handlers/ssh_config/analyzer/tokens.go +++ b/server/handlers/ssh_config/analyzer/tokens.go @@ -28,7 +28,7 @@ func analyzeTokens( tokens = []string{} } - disallowedTokens := utils.Without(fields.AvailableTokens, tokens) + disallowedTokens := utils.Without(utils.KeysOfMap(fields.AvailableTokens), tokens) for _, token := range disallowedTokens { if strings.Contains(text, token) { diff --git a/server/handlers/ssh_config/fields/tokens.go b/server/handlers/ssh_config/fields/tokens.go index 2fb69d1..42b0f54 100644 --- a/server/handlers/ssh_config/fields/tokens.go +++ b/server/handlers/ssh_config/fields/tokens.go @@ -1,25 +1,27 @@ package fields -var AvailableTokens = []string{ - "%%", - "%C", - "%d", - "%f", - "%H", - "%h", - "%l", - "%i", - "%j", - "%K", - "%k", - "%L", - "%l", - "%n", - "%p", - "%r", - "%T", - "%t", - "%u", +import "config-lsp/utils" + +var AvailableTokens = map[string]string{ + "%%": "A literal ‘%’.", + "%C": "Hash of %l%h%p%r%j.", + "%d": "Local user's home directory.", + "%f": "The fingerprint of the server's host key.", + "%H": "The known_hosts hostname or address that is being searched for.", + "%h": "The remote hostname.", + "%I": "A string describing the reason for a KnownHostsCommand execution: either ADDRESS when looking up a host by address (only when CheckHostIP is enabled), HOSTNAME when searching by hostname, or ORDER when preparing the host key algorithm preference list to use for the destination host.", + "%i": "The local user ID.", + "%j": "The contents of the ProxyJump option, or the empty string if this option is unset.", + "%K": "The base64 encoded host key.", + "%k": "The host key alias if specified, otherwise the original remote hostname given on the command line.", + "%L": "The local hostname.", + "%l": "The local hostname, including the domain name.", + "%n": "The original remote hostname, as given on the command line.", + "%p": "The remote port.", + "%r": "The remote username.", + "%T": "The local tun(4) or tap(4) network interface assigned if tunnel forwarding was requested, or \"NONE\" otherwise.", + "%t": "The type of the server host key, e.g. ssh-ed25519.", + "%u": "The local username.", } // A map of