From d3b655dc686ac8e69e82f31c132e467e6d424486 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 14 Sep 2024 21:08:46 +0200 Subject: [PATCH] fix: Bugfixes --- doc-values/value-array.go | 40 +++-- doc-values/value-key-enum-assignment.go | 2 +- doc-values/value-key-value-assignment.go | 2 +- doc-values/value-or.go | 2 +- handlers/sshd_config/Config.g4 | 4 +- handlers/sshd_config/ast/parser/Config.interp | 2 +- .../sshd_config/ast/parser/config_parser.go | 152 +++++++++--------- handlers/sshd_config/fields/fields.go | 4 +- handlers/sshd_config/handlers/completions.go | 3 +- 9 files changed, 116 insertions(+), 95 deletions(-) diff --git a/doc-values/value-array.go b/doc-values/value-array.go index 1fd7263..e69d98f 100644 --- a/doc-values/value-array.go +++ b/doc-values/value-array.go @@ -119,24 +119,34 @@ func (v ArrayValue) getCurrentValue(line string, cursor uint32) (string, uint32) return line, cursor } + MIN := uint32(0) + MAX := uint32(len(line) - 1) + var start uint32 var end uint32 + // hello,w[o]rld,and,more + // [h]ello,world + // hello,[w]orld + // hell[o],world + // hello,worl[d] + // hello,world[,] + // hello[,]world,how,are,you + relativePosition, found := utils.FindPreviousCharacter( line, v.Separator, - // defaults - min(len(line)-1, int(cursor)-1), + int(cursor), ) if found { - // +1 to skip the separator + // + 1 to skip the separator start = min( - min(uint32(len(line)), uint32(relativePosition+1)), - uint32(relativePosition+1), + MAX, + uint32(relativePosition)+1, ) } else { - start = 0 + start = MIN } relativePosition, found = utils.FindNextCharacter( @@ -146,21 +156,27 @@ func (v ArrayValue) getCurrentValue(line string, cursor uint32) (string, uint32) ) if found { - // -1 to skip the separator - end = min( - min(uint32(len(line)), uint32(relativePosition)), - cursor, + // - 1 to skip the separator + end = max( + MIN, + uint32(relativePosition)-1, ) } else { - end = uint32(len(line)) + end = MAX } - return line[start:end], cursor - start + if cursor > end { + // The user is typing a new (yet empty) value + return "", 0 + } + + return line[start : end+1], cursor - start } func (v ArrayValue) FetchCompletions(line string, cursor uint32) []protocol.CompletionItem { value, cursor := v.getCurrentValue(line, cursor) + println("after array", value, cursor) return v.SubValue.FetchCompletions(value, cursor) } diff --git a/doc-values/value-key-enum-assignment.go b/doc-values/value-key-enum-assignment.go index 2f27a60..4953caa 100644 --- a/doc-values/value-key-enum-assignment.go +++ b/doc-values/value-key-enum-assignment.go @@ -173,7 +173,7 @@ func (v KeyEnumAssignmentValue) FetchCompletions(line string, cursor uint32) []p relativePosition, found := utils.FindPreviousCharacter( line, v.Separator, - max(0, int(cursor-1)), + int(cursor), ) if found { diff --git a/doc-values/value-key-value-assignment.go b/doc-values/value-key-value-assignment.go index cda5c3c..77e60b7 100644 --- a/doc-values/value-key-value-assignment.go +++ b/doc-values/value-key-value-assignment.go @@ -111,7 +111,7 @@ func (v KeyValueAssignmentValue) FetchCompletions(line string, cursor uint32) [] relativePosition, found := utils.FindPreviousCharacter( line, v.Separator, - max(0, int(cursor-1)), + int(cursor), ) if found { diff --git a/doc-values/value-or.go b/doc-values/value-or.go index 3991a75..37bc8d3 100644 --- a/doc-values/value-or.go +++ b/doc-values/value-or.go @@ -63,7 +63,7 @@ func (v OrValue) FetchCompletions(line string, cursor uint32) []protocol.Complet _, found := utils.FindPreviousCharacter( line, keyEnumValue.Separator, - int(cursor-1), + int(cursor), ) if found { diff --git a/handlers/sshd_config/Config.g4 b/handlers/sshd_config/Config.g4 index 42346ad..376950e 100644 --- a/handlers/sshd_config/Config.g4 +++ b/handlers/sshd_config/Config.g4 @@ -5,7 +5,7 @@ lineStatement ; entry - : WHITESPACE? key? separator? value? WHITESPACE? leadingComment? + : WHITESPACE? key? separator? value? leadingComment? ; separator @@ -17,7 +17,7 @@ key ; value - : (STRING WHITESPACE)? STRING + : (STRING WHITESPACE)? STRING WHITESPACE? ; leadingComment diff --git a/handlers/sshd_config/ast/parser/Config.interp b/handlers/sshd_config/ast/parser/Config.interp index e860731..b286373 100644 --- a/handlers/sshd_config/ast/parser/Config.interp +++ b/handlers/sshd_config/ast/parser/Config.interp @@ -22,4 +22,4 @@ leadingComment atn: -[4, 1, 4, 65, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 1, 0, 3, 0, 15, 8, 0, 1, 0, 1, 0, 3, 0, 19, 8, 0, 3, 0, 21, 8, 0, 1, 0, 1, 0, 1, 1, 3, 1, 26, 8, 1, 1, 1, 3, 1, 29, 8, 1, 1, 1, 3, 1, 32, 8, 1, 1, 1, 3, 1, 35, 8, 1, 1, 1, 3, 1, 38, 8, 1, 1, 1, 3, 1, 41, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 3, 4, 49, 8, 4, 1, 4, 1, 4, 1, 5, 1, 5, 3, 5, 55, 8, 5, 1, 5, 1, 5, 3, 5, 59, 8, 5, 4, 5, 61, 8, 5, 11, 5, 12, 5, 62, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 0, 72, 0, 20, 1, 0, 0, 0, 2, 25, 1, 0, 0, 0, 4, 42, 1, 0, 0, 0, 6, 44, 1, 0, 0, 0, 8, 48, 1, 0, 0, 0, 10, 52, 1, 0, 0, 0, 12, 21, 3, 2, 1, 0, 13, 15, 5, 2, 0, 0, 14, 13, 1, 0, 0, 0, 14, 15, 1, 0, 0, 0, 15, 16, 1, 0, 0, 0, 16, 21, 3, 10, 5, 0, 17, 19, 5, 2, 0, 0, 18, 17, 1, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, 21, 1, 0, 0, 0, 20, 12, 1, 0, 0, 0, 20, 14, 1, 0, 0, 0, 20, 18, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 23, 5, 0, 0, 1, 23, 1, 1, 0, 0, 0, 24, 26, 5, 2, 0, 0, 25, 24, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 28, 1, 0, 0, 0, 27, 29, 3, 6, 3, 0, 28, 27, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, 31, 1, 0, 0, 0, 30, 32, 3, 4, 2, 0, 31, 30, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 34, 1, 0, 0, 0, 33, 35, 3, 8, 4, 0, 34, 33, 1, 0, 0, 0, 34, 35, 1, 0, 0, 0, 35, 37, 1, 0, 0, 0, 36, 38, 5, 2, 0, 0, 37, 36, 1, 0, 0, 0, 37, 38, 1, 0, 0, 0, 38, 40, 1, 0, 0, 0, 39, 41, 3, 10, 5, 0, 40, 39, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, 3, 1, 0, 0, 0, 42, 43, 5, 2, 0, 0, 43, 5, 1, 0, 0, 0, 44, 45, 5, 3, 0, 0, 45, 7, 1, 0, 0, 0, 46, 47, 5, 3, 0, 0, 47, 49, 5, 2, 0, 0, 48, 46, 1, 0, 0, 0, 48, 49, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 51, 5, 3, 0, 0, 51, 9, 1, 0, 0, 0, 52, 54, 5, 1, 0, 0, 53, 55, 5, 2, 0, 0, 54, 53, 1, 0, 0, 0, 54, 55, 1, 0, 0, 0, 55, 60, 1, 0, 0, 0, 56, 58, 5, 3, 0, 0, 57, 59, 5, 2, 0, 0, 58, 57, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 61, 1, 0, 0, 0, 60, 56, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, 62, 60, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 11, 1, 0, 0, 0, 13, 14, 18, 20, 25, 28, 31, 34, 37, 40, 48, 54, 58, 62] \ No newline at end of file +[4, 1, 4, 64, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 1, 0, 3, 0, 15, 8, 0, 1, 0, 1, 0, 3, 0, 19, 8, 0, 3, 0, 21, 8, 0, 1, 0, 1, 0, 1, 1, 3, 1,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1, 0, 0, 0, 38, 3, 1, 0, 0, 0, 39, 40, 5, 2, 0, 0, 40, 5, 1, 0, 0, 0, 41, 42, 5, 3, 0, 0, 42, 7, 1, 0, 0, 0, 43, 44, 5, 3, 0, 0, 44, 46, 5, 2, 0, 0, 45, 43, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, 49, 5, 3, 0, 0, 48, 50, 5, 2, 0, 0, 49, 48, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 9, 1, 0, 0, 0, 51, 53, 5, 1, 0, 0, 52, 54, 5, 2, 0, 0, 53, 52, 1, 0, 0, 0, 53, 54, 1, 0, 0, 0, 54, 59, 1, 0, 0, 0, 55, 57, 5, 3, 0, 0, 56, 58, 5, 2, 0, 0, 57, 56, 1, 0, 0, 0, 57, 58, 1, 0, 0, 0, 58, 60, 1, 0, 0, 0, 59, 55, 1, 0, 0, 0, 60, 61, 1, 0, 0, 0, 61, 59, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, 62, 11, 1, 0, 0, 0, 13, 14, 18, 20, 25, 28, 31, 34, 37, 45, 49, 53, 57, 61] \ No newline at end of file diff --git a/handlers/sshd_config/ast/parser/config_parser.go b/handlers/sshd_config/ast/parser/config_parser.go index 57ca885..79e7cfd 100644 --- a/handlers/sshd_config/ast/parser/config_parser.go +++ b/handlers/sshd_config/ast/parser/config_parser.go @@ -43,34 +43,34 @@ func configParserInit() { } staticData.PredictionContextCache = antlr.NewPredictionContextCache() staticData.serializedATN = []int32{ - 4, 1, 4, 65, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, + 4, 1, 4, 64, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 1, 0, 3, 0, 15, 8, 0, 1, 0, 1, 0, 3, 0, 19, 8, 0, 3, 0, 21, 8, 0, 1, 0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 38, 5, 2, 0, 0, 37, 36, 1, 0, 0, 0, 37, - 38, 1, 0, 0, 0, 38, 40, 1, 0, 0, 0, 39, 41, 3, 10, 5, 0, 40, 39, 1, 0, - 0, 0, 40, 41, 1, 0, 0, 0, 41, 3, 1, 0, 0, 0, 42, 43, 5, 2, 0, 0, 43, 5, - 1, 0, 0, 0, 44, 45, 5, 3, 0, 0, 45, 7, 1, 0, 0, 0, 46, 47, 5, 3, 0, 0, - 47, 49, 5, 2, 0, 0, 48, 46, 1, 0, 0, 0, 48, 49, 1, 0, 0, 0, 49, 50, 1, - 0, 0, 0, 50, 51, 5, 3, 0, 0, 51, 9, 1, 0, 0, 0, 52, 54, 5, 1, 0, 0, 53, - 55, 5, 2, 0, 0, 54, 53, 1, 0, 0, 0, 54, 55, 1, 0, 0, 0, 55, 60, 1, 0, 0, - 0, 56, 58, 5, 3, 0, 0, 57, 59, 5, 2, 0, 0, 58, 57, 1, 0, 0, 0, 58, 59, - 1, 0, 0, 0, 59, 61, 1, 0, 0, 0, 60, 56, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, - 62, 60, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 11, 1, 0, 0, 0, 13, 14, 18, - 20, 25, 28, 31, 34, 37, 40, 48, 54, 58, 62, + 1, 3, 1, 32, 8, 1, 1, 1, 3, 1, 35, 8, 1, 1, 1, 3, 1, 38, 8, 1, 1, 2, 1, + 2, 1, 3, 1, 3, 1, 4, 1, 4, 3, 4, 46, 8, 4, 1, 4, 1, 4, 3, 4, 50, 8, 4, + 1, 5, 1, 5, 3, 5, 54, 8, 5, 1, 5, 1, 5, 3, 5, 58, 8, 5, 4, 5, 60, 8, 5, + 11, 5, 12, 5, 61, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 0, 71, 0, 20, 1, + 0, 0, 0, 2, 25, 1, 0, 0, 0, 4, 39, 1, 0, 0, 0, 6, 41, 1, 0, 0, 0, 8, 45, + 1, 0, 0, 0, 10, 51, 1, 0, 0, 0, 12, 21, 3, 2, 1, 0, 13, 15, 5, 2, 0, 0, + 14, 13, 1, 0, 0, 0, 14, 15, 1, 0, 0, 0, 15, 16, 1, 0, 0, 0, 16, 21, 3, + 10, 5, 0, 17, 19, 5, 2, 0, 0, 18, 17, 1, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, + 21, 1, 0, 0, 0, 20, 12, 1, 0, 0, 0, 20, 14, 1, 0, 0, 0, 20, 18, 1, 0, 0, + 0, 21, 22, 1, 0, 0, 0, 22, 23, 5, 0, 0, 1, 23, 1, 1, 0, 0, 0, 24, 26, 5, + 2, 0, 0, 25, 24, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 28, 1, 0, 0, 0, 27, + 29, 3, 6, 3, 0, 28, 27, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, 31, 1, 0, 0, + 0, 30, 32, 3, 4, 2, 0, 31, 30, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 34, + 1, 0, 0, 0, 33, 35, 3, 8, 4, 0, 34, 33, 1, 0, 0, 0, 34, 35, 1, 0, 0, 0, + 35, 37, 1, 0, 0, 0, 36, 38, 3, 10, 5, 0, 37, 36, 1, 0, 0, 0, 37, 38, 1, + 0, 0, 0, 38, 3, 1, 0, 0, 0, 39, 40, 5, 2, 0, 0, 40, 5, 1, 0, 0, 0, 41, + 42, 5, 3, 0, 0, 42, 7, 1, 0, 0, 0, 43, 44, 5, 3, 0, 0, 44, 46, 5, 2, 0, + 0, 45, 43, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, 49, + 5, 3, 0, 0, 48, 50, 5, 2, 0, 0, 49, 48, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, + 50, 9, 1, 0, 0, 0, 51, 53, 5, 1, 0, 0, 52, 54, 5, 2, 0, 0, 53, 52, 1, 0, + 0, 0, 53, 54, 1, 0, 0, 0, 54, 59, 1, 0, 0, 0, 55, 57, 5, 3, 0, 0, 56, 58, + 5, 2, 0, 0, 57, 56, 1, 0, 0, 0, 57, 58, 1, 0, 0, 0, 58, 60, 1, 0, 0, 0, + 59, 55, 1, 0, 0, 0, 60, 61, 1, 0, 0, 0, 61, 59, 1, 0, 0, 0, 61, 62, 1, + 0, 0, 0, 62, 11, 1, 0, 0, 0, 13, 14, 18, 20, 25, 28, 31, 34, 37, 45, 49, + 53, 57, 61, } deserializer := antlr.NewATNDeserializer(nil) staticData.atn = deserializer.Deserialize(staticData.serializedATN) @@ -330,8 +330,7 @@ type IEntryContext interface { GetParser() antlr.Parser // Getter signatures - AllWHITESPACE() []antlr.TerminalNode - WHITESPACE(i int) antlr.TerminalNode + WHITESPACE() antlr.TerminalNode Key() IKeyContext Separator() ISeparatorContext Value() IValueContext @@ -373,12 +372,8 @@ func NewEntryContext(parser antlr.Parser, parent antlr.ParserRuleContext, invoki func (s *EntryContext) GetParser() antlr.Parser { return s.parser } -func (s *EntryContext) AllWHITESPACE() []antlr.TerminalNode { - return s.GetTokens(ConfigParserWHITESPACE) -} - -func (s *EntryContext) WHITESPACE(i int) antlr.TerminalNode { - return s.GetToken(ConfigParserWHITESPACE, i) +func (s *EntryContext) WHITESPACE() antlr.TerminalNode { + return s.GetToken(ConfigParserWHITESPACE, 0) } func (s *EntryContext) Key() IKeyContext { @@ -501,15 +496,17 @@ func (p *ConfigParser) Entry() (localctx IEntryContext) { } p.SetState(31) p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) - if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 5, p.GetParserRuleContext()) == 1 { + if _la == ConfigParserWHITESPACE { { p.SetState(30) p.Separator() } - } else if p.HasError() { // JIM - goto errorExit } p.SetState(34) p.GetErrorHandler().Sync(p) @@ -532,27 +529,9 @@ func (p *ConfigParser) Entry() (localctx IEntryContext) { } _la = p.GetTokenStream().LA(1) - if _la == ConfigParserWHITESPACE { - { - p.SetState(36) - p.Match(ConfigParserWHITESPACE) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - - } - p.SetState(40) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - if _la == ConfigParserHASH { { - p.SetState(39) + p.SetState(36) p.LeadingComment() } @@ -646,7 +625,7 @@ func (p *ConfigParser) Separator() (localctx ISeparatorContext) { p.EnterRule(localctx, 4, ConfigParserRULE_separator) p.EnterOuterAlt(localctx, 1) { - p.SetState(42) + p.SetState(39) p.Match(ConfigParserWHITESPACE) if p.HasError() { // Recognition error - abort rule @@ -742,7 +721,7 @@ func (p *ConfigParser) Key() (localctx IKeyContext) { p.EnterRule(localctx, 6, ConfigParserRULE_key) p.EnterOuterAlt(localctx, 1) { - p.SetState(44) + p.SetState(41) p.Match(ConfigParserSTRING) if p.HasError() { // Recognition error - abort rule @@ -773,7 +752,8 @@ type IValueContext interface { // Getter signatures AllSTRING() []antlr.TerminalNode STRING(i int) antlr.TerminalNode - WHITESPACE() antlr.TerminalNode + AllWHITESPACE() []antlr.TerminalNode + WHITESPACE(i int) antlr.TerminalNode // IsValueContext differentiates from other interfaces. IsValueContext() @@ -819,8 +799,12 @@ func (s *ValueContext) STRING(i int) antlr.TerminalNode { return s.GetToken(ConfigParserSTRING, i) } -func (s *ValueContext) WHITESPACE() antlr.TerminalNode { - return s.GetToken(ConfigParserWHITESPACE, 0) +func (s *ValueContext) AllWHITESPACE() []antlr.TerminalNode { + return s.GetTokens(ConfigParserWHITESPACE) +} + +func (s *ValueContext) WHITESPACE(i int) antlr.TerminalNode { + return s.GetToken(ConfigParserWHITESPACE, i) } func (s *ValueContext) GetRuleContext() antlr.RuleContext { @@ -846,13 +830,15 @@ func (s *ValueContext) ExitRule(listener antlr.ParseTreeListener) { func (p *ConfigParser) Value() (localctx IValueContext) { localctx = NewValueContext(p, p.GetParserRuleContext(), p.GetState()) p.EnterRule(localctx, 8, ConfigParserRULE_value) + var _la int + p.EnterOuterAlt(localctx, 1) - p.SetState(48) + p.SetState(45) p.GetErrorHandler().Sync(p) - if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 9, p.GetParserRuleContext()) == 1 { + if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 8, p.GetParserRuleContext()) == 1 { { - p.SetState(46) + p.SetState(43) p.Match(ConfigParserSTRING) if p.HasError() { // Recognition error - abort rule @@ -860,7 +846,7 @@ func (p *ConfigParser) Value() (localctx IValueContext) { } } { - p.SetState(47) + p.SetState(44) p.Match(ConfigParserWHITESPACE) if p.HasError() { // Recognition error - abort rule @@ -872,13 +858,31 @@ func (p *ConfigParser) Value() (localctx IValueContext) { goto errorExit } { - p.SetState(50) + p.SetState(47) p.Match(ConfigParserSTRING) if p.HasError() { // Recognition error - abort rule goto errorExit } } + p.SetState(49) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == ConfigParserWHITESPACE { + { + p.SetState(48) + p.Match(ConfigParserWHITESPACE) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + } errorExit: if p.HasError() { @@ -990,14 +994,14 @@ func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) { p.EnterOuterAlt(localctx, 1) { - p.SetState(52) + p.SetState(51) p.Match(ConfigParserHASH) if p.HasError() { // Recognition error - abort rule goto errorExit } } - p.SetState(54) + p.SetState(53) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -1006,7 +1010,7 @@ func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) { if _la == ConfigParserWHITESPACE { { - p.SetState(53) + p.SetState(52) p.Match(ConfigParserWHITESPACE) if p.HasError() { // Recognition error - abort rule @@ -1015,7 +1019,7 @@ func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) { } } - p.SetState(60) + p.SetState(59) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -1024,14 +1028,14 @@ func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) { for ok := true; ok; ok = _la == ConfigParserSTRING { { - p.SetState(56) + p.SetState(55) p.Match(ConfigParserSTRING) if p.HasError() { // Recognition error - abort rule goto errorExit } } - p.SetState(58) + p.SetState(57) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -1040,7 +1044,7 @@ func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) { if _la == ConfigParserWHITESPACE { { - p.SetState(57) + p.SetState(56) p.Match(ConfigParserWHITESPACE) if p.HasError() { // Recognition error - abort rule @@ -1050,7 +1054,7 @@ func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) { } - p.SetState(62) + p.SetState(61) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit diff --git a/handlers/sshd_config/fields/fields.go b/handlers/sshd_config/fields/fields.go index d7abb52..b58c6f3 100644 --- a/handlers/sshd_config/fields/fields.go +++ b/handlers/sshd_config/fields/fields.go @@ -572,8 +572,8 @@ Only a subset of keywords may be used on the lines following a Match keyword. Av SubValue: docvalues.KeyEnumAssignmentValue{ Separator: " ", Values: map[docvalues.EnumString]docvalues.Value{ - docvalues.CreateEnumString("User"): docvalues.StringValue{}, - docvalues.CreateEnumString("Group"): docvalues.StringValue{}, + docvalues.CreateEnumString("User"): docvalues.UserValue("", false), + docvalues.CreateEnumString("Group"): docvalues.GroupValue("", false), docvalues.CreateEnumString("Host"): docvalues.StringValue{}, docvalues.CreateEnumString("LocalAddress"): docvalues.StringValue{}, docvalues.CreateEnumString("LocalPort"): docvalues.NumberValue{Min: &ZERO, Max: &MAX_PORT}, diff --git a/handlers/sshd_config/handlers/completions.go b/handlers/sshd_config/handlers/completions.go index 0e4f48f..ceba5e7 100644 --- a/handlers/sshd_config/handlers/completions.go +++ b/handlers/sshd_config/handlers/completions.go @@ -1,6 +1,7 @@ package handlers import ( + "config-lsp/common" docvalues "config-lsp/doc-values" sshdconfig "config-lsp/handlers/sshd_config" "config-lsp/handlers/sshd_config/ast" @@ -66,7 +67,7 @@ func GetOptionCompletions( return option.FetchCompletions("", 0), nil } - relativeCursor := cursor - entry.OptionValue.Start.Character + relativeCursor := common.CursorToCharacterIndex(cursor - entry.OptionValue.Start.Character) line := entry.OptionValue.Value return option.FetchCompletions(line, relativeCursor), nil