From b1a5898f6c1a2ac537fab5c4f2b19f7777ea8608 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 28 Sep 2024 13:38:05 +0200 Subject: [PATCH] feat(ssh_config): Improve match file so that it works with single criterias --- handlers/ssh_config/analyzer/dependents.go | 1 - handlers/ssh_config/analyzer/options_test.go | 2 - handlers/ssh_config/analyzer/quotes.go | 2 +- handlers/ssh_config/ast/listener.go | 6 +- handlers/ssh_config/document_fields.go | 1 - handlers/ssh_config/fields/match.go | 2 - handlers/ssh_config/fields/options.go | 9 +- .../ssh_config/handlers/completions_match.go | 123 +++ handlers/ssh_config/host-parser/host_ast.go | 1 - handlers/ssh_config/host-parser/parser.go | 6 +- handlers/ssh_config/indexes/indexes.go | 8 +- .../ssh_config/indexes/indexes_handlers.go | 8 +- handlers/ssh_config/indexes/indexes_test.go | 2 +- .../ssh_config/lsp/text-document-did-open.go | 2 +- handlers/ssh_config/match-parser/Match.g4 | 68 +- handlers/ssh_config/match-parser/listener.go | 48 +- handlers/ssh_config/match-parser/match_ast.go | 1 + .../match-parser/parser/Match.interp | 29 +- .../match-parser/parser/Match.tokens | 18 +- .../match-parser/parser/MatchLexer.interp | 35 +- .../match-parser/parser/MatchLexer.tokens | 18 +- .../parser/match_base_listener.go | 30 +- .../match-parser/parser/match_lexer.go | 110 ++- .../match-parser/parser/match_listener.go | 30 +- .../match-parser/parser/match_parser.go | 831 ++++++++++++++---- .../ssh_config/match-parser/parser_test.go | 131 +++ handlers/ssh_config/shared.go | 3 +- 27 files changed, 1265 insertions(+), 260 deletions(-) create mode 100644 handlers/ssh_config/handlers/completions_match.go diff --git a/handlers/ssh_config/analyzer/dependents.go b/handlers/ssh_config/analyzer/dependents.go index f9e3e9a..bb8d9ea 100644 --- a/handlers/ssh_config/analyzer/dependents.go +++ b/handlers/ssh_config/analyzer/dependents.go @@ -52,4 +52,3 @@ func checkIsDependent( return errs } - diff --git a/handlers/ssh_config/analyzer/options_test.go b/handlers/ssh_config/analyzer/options_test.go index 63191bc..c74c15e 100644 --- a/handlers/ssh_config/analyzer/options_test.go +++ b/handlers/ssh_config/analyzer/options_test.go @@ -50,5 +50,3 @@ User root t.Fatalf("Expected 1 error, got %v", errors) } } - - diff --git a/handlers/ssh_config/analyzer/quotes.go b/handlers/ssh_config/analyzer/quotes.go index a07b3b3..68a5747 100644 --- a/handlers/ssh_config/analyzer/quotes.go +++ b/handlers/ssh_config/analyzer/quotes.go @@ -27,7 +27,7 @@ func analyzeQuotesAreValid( func checkIsUsingDoubleQuotes( value commonparser.ParsedString, valueRange common.LocationRange, - ) []common.LSPError { +) []common.LSPError { singleQuotePosition := strings.Index(value.Raw, "'") if singleQuotePosition != -1 { diff --git a/handlers/ssh_config/ast/listener.go b/handlers/ssh_config/ast/listener.go index 0043422..3d6719f 100644 --- a/handlers/ssh_config/ast/listener.go +++ b/handlers/ssh_config/ast/listener.go @@ -176,9 +176,9 @@ func (s *sshParserListener) ExitEntry(ctx *parser.EntryContext) { hostBlock := &SSHHostBlock{ LocationRange: location, - HostOption: s.sshContext.currentOption, - HostValue: host, - Options: treemap.NewWith(gods.UInt32Comparator), + HostOption: s.sshContext.currentOption, + HostValue: host, + Options: treemap.NewWith(gods.UInt32Comparator), } s.Config.Options.Put( diff --git a/handlers/ssh_config/document_fields.go b/handlers/ssh_config/document_fields.go index 8f28204..f273a6f 100644 --- a/handlers/ssh_config/document_fields.go +++ b/handlers/ssh_config/document_fields.go @@ -35,4 +35,3 @@ func (d SSHDocument) DoesOptionExist( ) bool { return d.FindOptionByNameAndBlock(name, block) != nil } - diff --git a/handlers/ssh_config/fields/match.go b/handlers/ssh_config/fields/match.go index 071562a..95f5f5f 100644 --- a/handlers/ssh_config/fields/match.go +++ b/handlers/ssh_config/fields/match.go @@ -1,3 +1 @@ package fields - - diff --git a/handlers/ssh_config/fields/options.go b/handlers/ssh_config/fields/options.go index b52e15c..48043cc 100644 --- a/handlers/ssh_config/fields/options.go +++ b/handlers/ssh_config/fields/options.go @@ -2,15 +2,15 @@ package fields var AllowedDuplicateOptions = map[string]struct{}{ "CertificateFile": {}, - "Match": {}, - "Host": {}, + "Match": {}, + "Host": {}, } -// A list of +// A list of //