From 250ec83a598f39a05deb5dd5a9ed99705cca571d Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 21 Sep 2024 18:41:20 +0200 Subject: [PATCH] refactor: Move match parser to common package --- .../parsers/openssh-match-parser}/Match.g4 | 0 .../openssh-match-parser}/error-listener.go | 0 .../openssh-match-parser}/full_test.go | 0 .../parsers/openssh-match-parser}/listener.go | 16 +++++----- .../openssh-match-parser}/match_ast.go | 0 .../openssh-match-parser}/match_fields.go | 0 .../parsers/openssh-match-parser}/parser.go | 6 ++-- .../openssh-match-parser}/parser/Match.interp | 0 .../openssh-match-parser}/parser/Match.tokens | 0 .../parser/MatchLexer.interp | 0 .../parser/MatchLexer.tokens | 0 .../parser/match_base_listener.go | 0 .../parser/match_lexer.go | 0 .../parser/match_listener.go | 0 .../parser/match_parser.go | 0 .../openssh-match-parser}/parser_test.go | 0 handlers/ssh_config/ast/ssh_config.go | 2 +- handlers/sshd_config/analyzer/match.go | 2 +- handlers/sshd_config/analyzer/options.go | 2 +- handlers/sshd_config/ast/listener.go | 8 ++--- handlers/sshd_config/ast/parser_test.go | 30 +++++++++---------- handlers/sshd_config/ast/sshd_config.go | 7 ++--- .../sshd_config/ast/sshd_config_fields.go | 10 +++---- .../sshd_config/handlers/completions_match.go | 3 +- .../sshd_config/handlers/formatting_nodes.go | 6 ++-- handlers/sshd_config/indexes/handlers.go | 2 +- 26 files changed, 46 insertions(+), 48 deletions(-) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/Match.g4 (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/error-listener.go (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/full_test.go (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/listener.go (86%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/match_ast.go (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/match_fields.go (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/parser.go (87%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/parser/Match.interp (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/parser/Match.tokens (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/parser/MatchLexer.interp (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/parser/MatchLexer.tokens (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/parser/match_base_listener.go (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/parser/match_lexer.go (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/parser/match_listener.go (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/parser/match_parser.go (100%) rename {handlers/sshd_config/fields/match-parser => common/parsers/openssh-match-parser}/parser_test.go (100%) diff --git a/handlers/sshd_config/fields/match-parser/Match.g4 b/common/parsers/openssh-match-parser/Match.g4 similarity index 100% rename from handlers/sshd_config/fields/match-parser/Match.g4 rename to common/parsers/openssh-match-parser/Match.g4 diff --git a/handlers/sshd_config/fields/match-parser/error-listener.go b/common/parsers/openssh-match-parser/error-listener.go similarity index 100% rename from handlers/sshd_config/fields/match-parser/error-listener.go rename to common/parsers/openssh-match-parser/error-listener.go diff --git a/handlers/sshd_config/fields/match-parser/full_test.go b/common/parsers/openssh-match-parser/full_test.go similarity index 100% rename from handlers/sshd_config/fields/match-parser/full_test.go rename to common/parsers/openssh-match-parser/full_test.go diff --git a/handlers/sshd_config/fields/match-parser/listener.go b/common/parsers/openssh-match-parser/listener.go similarity index 86% rename from handlers/sshd_config/fields/match-parser/listener.go rename to common/parsers/openssh-match-parser/listener.go index ce5e130..fc1f3b5 100644 --- a/handlers/sshd_config/fields/match-parser/listener.go +++ b/common/parsers/openssh-match-parser/listener.go @@ -3,7 +3,7 @@ package matchparser import ( "config-lsp/common" commonparser "config-lsp/common/parser" - "config-lsp/handlers/sshd_config/fields/match-parser/parser" + parser2 "config-lsp/common/parsers/openssh-match-parser/parser" "config-lsp/utils" "errors" "fmt" @@ -39,13 +39,13 @@ func createListener( } type matchParserListener struct { - *parser.BaseMatchListener + *parser2.BaseMatchListener match *Match Errors []common.LSPError matchContext *matchListenerContext } -func (s *matchParserListener) EnterMatchEntry(ctx *parser.MatchEntryContext) { +func (s *matchParserListener) EnterMatchEntry(ctx *parser2.MatchEntryContext) { location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext).ShiftHorizontal(s.matchContext.startCharacter) location.ChangeBothLines(s.matchContext.line) @@ -58,7 +58,7 @@ func (s *matchParserListener) EnterMatchEntry(ctx *parser.MatchEntryContext) { s.matchContext.currentEntry = entry } -func (s *matchParserListener) ExitMatchEntry(ctx *parser.MatchEntryContext) { +func (s *matchParserListener) ExitMatchEntry(ctx *parser2.MatchEntryContext) { s.matchContext.currentEntry = nil } @@ -72,7 +72,7 @@ var availableCriteria = map[string]MatchCriteriaType{ string(MatchCriteriaTypeAddress): MatchCriteriaTypeAddress, } -func (s *matchParserListener) EnterCriteria(ctx *parser.CriteriaContext) { +func (s *matchParserListener) EnterCriteria(ctx *parser2.CriteriaContext) { location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext).ShiftHorizontal(s.matchContext.startCharacter) location.ChangeBothLines(s.matchContext.line) @@ -95,7 +95,7 @@ func (s *matchParserListener) EnterCriteria(ctx *parser.CriteriaContext) { } } -func (s *matchParserListener) EnterSeparator(ctx *parser.SeparatorContext) { +func (s *matchParserListener) EnterSeparator(ctx *parser2.SeparatorContext) { location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext).ShiftHorizontal(s.matchContext.startCharacter) location.ChangeBothLines(s.matchContext.line) @@ -104,7 +104,7 @@ func (s *matchParserListener) EnterSeparator(ctx *parser.SeparatorContext) { } } -func (s *matchParserListener) EnterValues(ctx *parser.ValuesContext) { +func (s *matchParserListener) EnterValues(ctx *parser2.ValuesContext) { location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext).ShiftHorizontal(s.matchContext.startCharacter) location.ChangeBothLines(s.matchContext.line) @@ -114,7 +114,7 @@ func (s *matchParserListener) EnterValues(ctx *parser.ValuesContext) { } } -func (s *matchParserListener) EnterValue(ctx *parser.ValueContext) { +func (s *matchParserListener) EnterValue(ctx *parser2.ValueContext) { location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext).ShiftHorizontal(s.matchContext.startCharacter) location.ChangeBothLines(s.matchContext.line) diff --git a/handlers/sshd_config/fields/match-parser/match_ast.go b/common/parsers/openssh-match-parser/match_ast.go similarity index 100% rename from handlers/sshd_config/fields/match-parser/match_ast.go rename to common/parsers/openssh-match-parser/match_ast.go diff --git a/handlers/sshd_config/fields/match-parser/match_fields.go b/common/parsers/openssh-match-parser/match_fields.go similarity index 100% rename from handlers/sshd_config/fields/match-parser/match_fields.go rename to common/parsers/openssh-match-parser/match_fields.go diff --git a/handlers/sshd_config/fields/match-parser/parser.go b/common/parsers/openssh-match-parser/parser.go similarity index 87% rename from handlers/sshd_config/fields/match-parser/parser.go rename to common/parsers/openssh-match-parser/parser.go index d81f73c..b4abe9e 100644 --- a/handlers/sshd_config/fields/match-parser/parser.go +++ b/common/parsers/openssh-match-parser/parser.go @@ -2,7 +2,7 @@ package matchparser import ( "config-lsp/common" - "config-lsp/handlers/sshd_config/fields/match-parser/parser" + parser2 "config-lsp/common/parsers/openssh-match-parser/parser" "github.com/antlr4-go/antlr/v4" ) @@ -27,14 +27,14 @@ func (m *Match) Parse( stream := antlr.NewInputStream(input) lexerErrorListener := createErrorListener(context.line) - lexer := parser.NewMatchLexer(stream) + lexer := parser2.NewMatchLexer(stream) lexer.RemoveErrorListeners() lexer.AddErrorListener(&lexerErrorListener) tokenStream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel) parserErrorListener := createErrorListener(context.line) - antlrParser := parser.NewMatchParser(tokenStream) + antlrParser := parser2.NewMatchParser(tokenStream) antlrParser.RemoveErrorListeners() antlrParser.AddErrorListener(&parserErrorListener) diff --git a/handlers/sshd_config/fields/match-parser/parser/Match.interp b/common/parsers/openssh-match-parser/parser/Match.interp similarity index 100% rename from handlers/sshd_config/fields/match-parser/parser/Match.interp rename to common/parsers/openssh-match-parser/parser/Match.interp diff --git a/handlers/sshd_config/fields/match-parser/parser/Match.tokens b/common/parsers/openssh-match-parser/parser/Match.tokens similarity index 100% rename from handlers/sshd_config/fields/match-parser/parser/Match.tokens rename to common/parsers/openssh-match-parser/parser/Match.tokens diff --git a/handlers/sshd_config/fields/match-parser/parser/MatchLexer.interp b/common/parsers/openssh-match-parser/parser/MatchLexer.interp similarity index 100% rename from handlers/sshd_config/fields/match-parser/parser/MatchLexer.interp rename to common/parsers/openssh-match-parser/parser/MatchLexer.interp diff --git a/handlers/sshd_config/fields/match-parser/parser/MatchLexer.tokens b/common/parsers/openssh-match-parser/parser/MatchLexer.tokens similarity index 100% rename from handlers/sshd_config/fields/match-parser/parser/MatchLexer.tokens rename to common/parsers/openssh-match-parser/parser/MatchLexer.tokens diff --git a/handlers/sshd_config/fields/match-parser/parser/match_base_listener.go b/common/parsers/openssh-match-parser/parser/match_base_listener.go similarity index 100% rename from handlers/sshd_config/fields/match-parser/parser/match_base_listener.go rename to common/parsers/openssh-match-parser/parser/match_base_listener.go diff --git a/handlers/sshd_config/fields/match-parser/parser/match_lexer.go b/common/parsers/openssh-match-parser/parser/match_lexer.go similarity index 100% rename from handlers/sshd_config/fields/match-parser/parser/match_lexer.go rename to common/parsers/openssh-match-parser/parser/match_lexer.go diff --git a/handlers/sshd_config/fields/match-parser/parser/match_listener.go b/common/parsers/openssh-match-parser/parser/match_listener.go similarity index 100% rename from handlers/sshd_config/fields/match-parser/parser/match_listener.go rename to common/parsers/openssh-match-parser/parser/match_listener.go diff --git a/handlers/sshd_config/fields/match-parser/parser/match_parser.go b/common/parsers/openssh-match-parser/parser/match_parser.go similarity index 100% rename from handlers/sshd_config/fields/match-parser/parser/match_parser.go rename to common/parsers/openssh-match-parser/parser/match_parser.go diff --git a/handlers/sshd_config/fields/match-parser/parser_test.go b/common/parsers/openssh-match-parser/parser_test.go similarity index 100% rename from handlers/sshd_config/fields/match-parser/parser_test.go rename to common/parsers/openssh-match-parser/parser_test.go diff --git a/handlers/ssh_config/ast/ssh_config.go b/handlers/ssh_config/ast/ssh_config.go index fb15e51..b3b5b6a 100644 --- a/handlers/ssh_config/ast/ssh_config.go +++ b/handlers/ssh_config/ast/ssh_config.go @@ -3,7 +3,7 @@ package ast import ( "config-lsp/common" commonparser "config-lsp/common/parser" - matchparser "config-lsp/handlers/sshd_config/fields/match-parser" + "config-lsp/common/parsers/openssh-match-parser" "github.com/emirpasic/gods/maps/treemap" ) diff --git a/handlers/sshd_config/analyzer/match.go b/handlers/sshd_config/analyzer/match.go index 68d4769..a150fef 100644 --- a/handlers/sshd_config/analyzer/match.go +++ b/handlers/sshd_config/analyzer/match.go @@ -2,8 +2,8 @@ package analyzer import ( "config-lsp/common" + "config-lsp/common/parsers/openssh-match-parser" sshdconfig "config-lsp/handlers/sshd_config" - matchparser "config-lsp/handlers/sshd_config/fields/match-parser" "config-lsp/utils" "errors" "fmt" diff --git a/handlers/sshd_config/analyzer/options.go b/handlers/sshd_config/analyzer/options.go index 1b3eba7..3f19923 100644 --- a/handlers/sshd_config/analyzer/options.go +++ b/handlers/sshd_config/analyzer/options.go @@ -109,7 +109,7 @@ func checkMatchBlock( ) []common.LSPError { errs := make([]common.LSPError, 0) - matchOption := matchBlock.MatchEntry.OptionValue + matchOption := matchBlock.MatchOption.OptionValue if matchOption != nil { invalidValues := fields.Options["Match"].CheckIsValid(matchOption.Value.Value) diff --git a/handlers/sshd_config/ast/listener.go b/handlers/sshd_config/ast/listener.go index d41e6a6..72816dc 100644 --- a/handlers/sshd_config/ast/listener.go +++ b/handlers/sshd_config/ast/listener.go @@ -3,8 +3,8 @@ package ast import ( "config-lsp/common" commonparser "config-lsp/common/parser" + matchparser2 "config-lsp/common/parsers/openssh-match-parser" "config-lsp/handlers/sshd_config/ast/parser" - matchparser "config-lsp/handlers/sshd_config/fields/match-parser" "strings" "github.com/emirpasic/gods/maps/treemap" @@ -113,10 +113,10 @@ func (s *sshParserListener) ExitEntry(ctx *parser.EntryContext) { if s.sshContext.isKeyAMatchBlock { // Add new match block - var match *matchparser.Match + var match *matchparser2.Match if s.sshContext.currentOption.OptionValue != nil { - matchParser := matchparser.NewMatch() + matchParser := matchparser2.NewMatch() errors := matchParser.Parse( s.sshContext.currentOption.OptionValue.Value.Raw, location.Start.Line, @@ -137,7 +137,7 @@ func (s *sshParserListener) ExitEntry(ctx *parser.EntryContext) { matchBlock := &SSHDMatchBlock{ LocationRange: location, - MatchEntry: s.sshContext.currentOption, + MatchOption: s.sshContext.currentOption, MatchValue: match, Options: treemap.NewWith(gods.UInt32Comparator), } diff --git a/handlers/sshd_config/ast/parser_test.go b/handlers/sshd_config/ast/parser_test.go index 5aebf15..423c6b2 100644 --- a/handlers/sshd_config/ast/parser_test.go +++ b/handlers/sshd_config/ast/parser_test.go @@ -88,15 +88,15 @@ Match Address 192.168.0.1 rawSecondEntry, _ := p.Options.Get(uint32(2)) secondEntry := rawSecondEntry.(*SSHDMatchBlock) - if !(secondEntry.MatchEntry.Value.Value == "Match Address 192.168.0.1") { - t.Errorf("Expected second entry to be 'Match Address 192.168.0.1', but got: %v", secondEntry.MatchEntry.Value) + if !(secondEntry.MatchOption.Value.Value == "Match Address 192.168.0.1") { + t.Errorf("Expected second entry to be 'Match Address 192.168.0.1', but got: %v", secondEntry.MatchOption.Value) } if !(secondEntry.Start.Line == 2 && secondEntry.Start.Character == 0 && secondEntry.End.Line == 3 && secondEntry.End.Character == 27) { t.Errorf("Expected second entry's location to be 2:0-3:25, but got: %v", secondEntry.LocationRange) } - if !(secondEntry.MatchValue.Entries[0].Criteria.Type == "Address" && secondEntry.MatchValue.Entries[0].Values.Values[0].Value.Value == "192.168.0.1" && secondEntry.MatchEntry.OptionValue.Start.Character == 6) { + if !(secondEntry.MatchValue.Entries[0].Criteria.Type == "Address" && secondEntry.MatchValue.Entries[0].Values.Values[0].Value.Value == "192.168.0.1" && secondEntry.MatchOption.OptionValue.Start.Character == 6) { t.Errorf("Expected second entry to be 'Match Address 192.168.0.1', but got: %v", secondEntry.MatchValue) } @@ -126,8 +126,8 @@ Match User lena User root _, matchBlock := p.FindOption(uint32(0)) - if !(matchBlock.MatchEntry.Value.Value == "Match User lena User root") { - t.Errorf("Expected match block to be 'Match User lena User root', but got: %v", matchBlock.MatchEntry.Value) + if !(matchBlock.MatchOption.Value.Value == "Match User lena User root") { + t.Errorf("Expected match block to be 'Match User lena User root', but got: %v", matchBlock.MatchOption.Value) } if !(len(matchBlock.MatchValue.Entries) == 2) { @@ -157,8 +157,8 @@ func TestIncompleteMatchBlock( _, matchBlock := p.FindOption(uint32(0)) - if !(matchBlock.MatchEntry.Value.Value == "Match User lena User ") { - t.Errorf("Expected match block to be 'Match User lena User ', but got: %v", matchBlock.MatchEntry.Value) + if !(matchBlock.MatchOption.Value.Value == "Match User lena User ") { + t.Errorf("Expected match block to be 'Match User lena User ', but got: %v", matchBlock.MatchOption.Value) } if !(matchBlock.MatchValue.Entries[0].Criteria.Type == "User" && matchBlock.MatchValue.Entries[0].Values.Values[0].Value.Value == "lena") { @@ -231,12 +231,12 @@ Match Address 192.168.0.2 } emptyOption, matchBlock := p.FindOption(uint32(5)) - if !(emptyOption == nil && matchBlock.MatchEntry.Value.Value == "Match User lena" && matchBlock.MatchValue.Entries[0].Values.Values[0].Value.Value == "lena") { + if !(emptyOption == nil && matchBlock.MatchOption.Value.Value == "Match User lena" && matchBlock.MatchValue.Entries[0].Values.Values[0].Value.Value == "lena") { t.Errorf("Expected empty option and match block to be 'Match User lena', but got: %v, %v", emptyOption, matchBlock) } matchOption, matchBlock := p.FindOption(uint32(2)) - if !(matchOption.Value.Value == "Match User lena" && matchBlock.MatchEntry.Value.Value == "Match User lena" && matchBlock.MatchValue.Entries[0].Values.Values[0].Value.Value == "lena" && matchBlock.MatchEntry.OptionValue.Start.Character == 6) { + if !(matchOption.Value.Value == "Match User lena" && matchBlock.MatchOption.Value.Value == "Match User lena" && matchBlock.MatchValue.Entries[0].Values.Values[0].Value.Value == "lena" && matchBlock.MatchOption.OptionValue.Start.Character == 6) { t.Errorf("Expected match option to be 'Match User lena', but got: %v, %v", matchOption, matchBlock) } @@ -502,8 +502,8 @@ Match Address 172.22.100.0/24,172.22.5.0/24,127.0.0.1 rawFourthEntry, _ := p.Options.Get(uint32(135)) fourthEntry := rawFourthEntry.(*SSHDMatchBlock) - if !(fourthEntry.MatchEntry.Value.Value == "Match User anoncvs") { - t.Errorf("Expected fourth entry to be 'Match User anoncvs', but got: %v", fourthEntry.MatchEntry.Value) + if !(fourthEntry.MatchOption.Value.Value == "Match User anoncvs") { + t.Errorf("Expected fourth entry to be 'Match User anoncvs', but got: %v", fourthEntry.MatchOption.Value) } if !(fourthEntry.MatchValue.Entries[0].Criteria.Type == "User" && fourthEntry.MatchValue.Entries[0].Values.Values[0].Value.Value == "anoncvs") { @@ -522,12 +522,12 @@ Match Address 172.22.100.0/24,172.22.5.0/24,127.0.0.1 rawSixthEntry, _ := p.Options.Get(uint32(142)) sixthEntry := rawSixthEntry.(*SSHDMatchBlock) - if !(sixthEntry.MatchEntry.Value.Value == "Match Address 172.22.100.0/24,172.22.5.0/24,127.0.0.1") { - t.Errorf("Expected sixth entry to be 'Match Address 172.22.100.0/24,172.22.5.0/24,127.0.0.1', but got: %v", sixthEntry.MatchEntry.Value) + if !(sixthEntry.MatchOption.Value.Value == "Match Address 172.22.100.0/24,172.22.5.0/24,127.0.0.1") { + t.Errorf("Expected sixth entry to be 'Match Address 172.22.100.0/24,172.22.5.0/24,127.0.0.1', but got: %v", sixthEntry.MatchOption.Value) } - if !(sixthEntry.MatchEntry.Key.Value.Value == "Match" && sixthEntry.MatchEntry.OptionValue.Value.Value == "Address 172.22.100.0/24,172.22.5.0/24,127.0.0.1") { - t.Errorf("Expected sixth entry to be 'Match Address 172.22.100.0/24,172.22.5.0/24,127.0.0.1', but got: %v", sixthEntry.MatchEntry.Value) + if !(sixthEntry.MatchOption.Key.Value.Value == "Match" && sixthEntry.MatchOption.OptionValue.Value.Value == "Address 172.22.100.0/24,172.22.5.0/24,127.0.0.1") { + t.Errorf("Expected sixth entry to be 'Match Address 172.22.100.0/24,172.22.5.0/24,127.0.0.1', but got: %v", sixthEntry.MatchOption.Value) } if !(sixthEntry.MatchValue.Entries[0].Criteria.Type == "Address" && len(sixthEntry.MatchValue.Entries[0].Values.Values) == 3) { diff --git a/handlers/sshd_config/ast/sshd_config.go b/handlers/sshd_config/ast/sshd_config.go index 27b5aef..72933b0 100644 --- a/handlers/sshd_config/ast/sshd_config.go +++ b/handlers/sshd_config/ast/sshd_config.go @@ -3,8 +3,7 @@ package ast import ( "config-lsp/common" commonparser "config-lsp/common/parser" - matchparser "config-lsp/handlers/sshd_config/fields/match-parser" - + "config-lsp/common/parsers/openssh-match-parser" "github.com/emirpasic/gods/maps/treemap" ) @@ -47,8 +46,8 @@ type SSHDOption struct { type SSHDMatchBlock struct { common.LocationRange - MatchEntry *SSHDOption - MatchValue *matchparser.Match + MatchOption *SSHDOption + MatchValue *matchparser.Match // [uint32]*SSHDOption -> line number -> *SSHDOption Options *treemap.Map diff --git a/handlers/sshd_config/ast/sshd_config_fields.go b/handlers/sshd_config/ast/sshd_config_fields.go index 97cb4b7..8c226bd 100644 --- a/handlers/sshd_config/ast/sshd_config_fields.go +++ b/handlers/sshd_config/ast/sshd_config_fields.go @@ -13,7 +13,7 @@ func (m SSHDMatchBlock) GetType() SSHDEntryType { } func (m SSHDMatchBlock) GetOption() SSHDOption { - return *m.MatchEntry + return *m.MatchOption } func (c SSHDConfig) FindMatchBlock(line uint32) *SSHDMatchBlock { @@ -37,8 +37,8 @@ func (c SSHDConfig) FindOption(line uint32) (*SSHDOption, *SSHDMatchBlock) { matchBlock := c.FindMatchBlock(line) if matchBlock != nil { - if line == matchBlock.MatchEntry.Start.Line { - return matchBlock.MatchEntry, matchBlock + if line == matchBlock.MatchOption.Start.Line { + return matchBlock.MatchOption, matchBlock } rawEntry, found := matchBlock.Options.Get(line) @@ -55,7 +55,7 @@ func (c SSHDConfig) FindOption(line uint32) (*SSHDOption, *SSHDMatchBlock) { if found { switch rawEntry.(type) { case *SSHDMatchBlock: - return rawEntry.(*SSHDMatchBlock).MatchEntry, rawEntry.(*SSHDMatchBlock) + return rawEntry.(*SSHDMatchBlock).MatchOption, rawEntry.(*SSHDMatchBlock) case *SSHDOption: return rawEntry.(*SSHDOption), nil } @@ -78,7 +78,7 @@ func (c SSHDConfig) GetAllOptions() []*SSHDOption { case *SSHDOption: options = append(options, entry) case *SSHDMatchBlock: - options = append(options, entry.MatchEntry) + options = append(options, entry.MatchOption) for _, rawOption := range entry.Options.Values() { options = append(options, rawOption.(*SSHDOption)) diff --git a/handlers/sshd_config/handlers/completions_match.go b/handlers/sshd_config/handlers/completions_match.go index 4c4707b..0d13fd5 100644 --- a/handlers/sshd_config/handlers/completions_match.go +++ b/handlers/sshd_config/handlers/completions_match.go @@ -2,10 +2,9 @@ package handlers import ( "config-lsp/common" + "config-lsp/common/parsers/openssh-match-parser" sshdconfig "config-lsp/handlers/sshd_config" "config-lsp/handlers/sshd_config/fields" - matchparser "config-lsp/handlers/sshd_config/fields/match-parser" - protocol "github.com/tliron/glsp/protocol_3_16" ) diff --git a/handlers/sshd_config/handlers/formatting_nodes.go b/handlers/sshd_config/handlers/formatting_nodes.go index bb0b7cd..e0e9bf3 100644 --- a/handlers/sshd_config/handlers/formatting_nodes.go +++ b/handlers/sshd_config/handlers/formatting_nodes.go @@ -2,8 +2,8 @@ package handlers import ( "config-lsp/common/formatting" + "config-lsp/common/parsers/openssh-match-parser" "config-lsp/handlers/sshd_config/ast" - matchparser "config-lsp/handlers/sshd_config/fields/match-parser" "config-lsp/utils" "fmt" "strings" @@ -57,10 +57,10 @@ func formatSSHDMatchBlock( edits := make([]protocol.TextEdit, 0) edits = append(edits, protocol.TextEdit{ - Range: matchBlock.MatchEntry.ToLSPRange(), + Range: matchBlock.MatchOption.ToLSPRange(), NewText: matchTemplate.Format( options, - matchBlock.MatchEntry.Key.Key, + matchBlock.MatchOption.Key.Key, formatMatchToString(matchBlock.MatchValue), ), }) diff --git a/handlers/sshd_config/indexes/handlers.go b/handlers/sshd_config/indexes/handlers.go index 533825c..271887b 100644 --- a/handlers/sshd_config/indexes/handlers.go +++ b/handlers/sshd_config/indexes/handlers.go @@ -30,7 +30,7 @@ func CreateIndexes(config ast.SSHDConfig) (*SSHDIndexes, []common.LSPError) { case *ast.SSHDMatchBlock: matchBlock := entry.(*ast.SSHDMatchBlock) - errs = append(errs, addOption(indexes, matchBlock.MatchEntry, matchBlock)...) + errs = append(errs, addOption(indexes, matchBlock.MatchOption, matchBlock)...) it := matchBlock.Options.Iterator() for it.Next() {