mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
fix(sshd_config): Improve analyzer for match blocks
This commit is contained in:
parent
f25c11b966
commit
0abcb043ad
@ -18,10 +18,26 @@ func analyzeOptionsAreValid(
|
||||
it := d.Config.Options.Iterator()
|
||||
|
||||
for it.Next() {
|
||||
line := it.Key().(uint32)
|
||||
entry := it.Value().(ast.SSHEntry)
|
||||
|
||||
option := entry.GetOption()
|
||||
switch entry.(type) {
|
||||
case *ast.SSHOption:
|
||||
errs = append(errs, checkOption(entry.(*ast.SSHOption), false)...)
|
||||
case *ast.SSHMatchBlock:
|
||||
matchBlock := entry.(*ast.SSHMatchBlock)
|
||||
errs = append(errs, checkMatchBlock(matchBlock)...)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
func checkOption(
|
||||
option *ast.SSHOption,
|
||||
isInMatchBlock bool,
|
||||
) []common.LSPError {
|
||||
errs := make([]common.LSPError, 0)
|
||||
|
||||
if option.Key != nil {
|
||||
docOption, found := fields.Options[option.Key.Value]
|
||||
@ -31,11 +47,21 @@ func analyzeOptionsAreValid(
|
||||
Range: option.Key.LocationRange,
|
||||
Err: errors.New(fmt.Sprintf("Unknown option: %s", option.Key.Value)),
|
||||
})
|
||||
continue
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
if _, found := fields.MatchAllowedOptions[option.Key.Value]; !found && isInMatchBlock {
|
||||
errs = append(errs, common.LSPError{
|
||||
Range: option.Key.LocationRange,
|
||||
Err: errors.New(fmt.Sprintf("Option '%s' is not allowed inside Match blocks", option.Key.Value)),
|
||||
})
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
if option.OptionValue == nil {
|
||||
continue
|
||||
return errs
|
||||
}
|
||||
|
||||
invalidValues := docOption.CheckIsValid(option.OptionValue.Value)
|
||||
@ -45,15 +71,47 @@ func analyzeOptionsAreValid(
|
||||
utils.Map(
|
||||
invalidValues,
|
||||
func(invalidValue *docvalues.InvalidValue) common.LSPError {
|
||||
err := docvalues.LSPErrorFromInvalidValue(line, *invalidValue)
|
||||
err := docvalues.LSPErrorFromInvalidValue(option.Start.Line, *invalidValue)
|
||||
err.ShiftCharacter(option.OptionValue.Start.Character)
|
||||
|
||||
return err
|
||||
},
|
||||
)...,
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
func checkMatchBlock(
|
||||
matchBlock *ast.SSHMatchBlock,
|
||||
) []common.LSPError {
|
||||
errs := make([]common.LSPError, 0)
|
||||
|
||||
matchOption := matchBlock.MatchEntry.OptionValue
|
||||
if matchOption != nil {
|
||||
invalidValues := fields.Options["Match"].CheckIsValid(matchOption.Value)
|
||||
|
||||
errs = append(
|
||||
errs,
|
||||
utils.Map(
|
||||
invalidValues,
|
||||
func(invalidValue *docvalues.InvalidValue) common.LSPError {
|
||||
err := docvalues.LSPErrorFromInvalidValue(matchBlock.Start.Line, *invalidValue)
|
||||
err.ShiftCharacter(matchOption.Start.Character)
|
||||
|
||||
return err
|
||||
},
|
||||
)...,
|
||||
)
|
||||
}
|
||||
|
||||
it := matchBlock.Options.Iterator()
|
||||
|
||||
for it.Next() {
|
||||
option := it.Value().(*ast.SSHOption)
|
||||
|
||||
errs = append(errs, checkOption(option, true)...)
|
||||
}
|
||||
|
||||
return errs
|
||||
|
@ -574,8 +574,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.UserValue("", true),
|
||||
docvalues.CreateEnumString("Group"): docvalues.GroupValue("", true),
|
||||
docvalues.CreateEnumString("User"): docvalues.StringValue{},
|
||||
docvalues.CreateEnumString("Group"): docvalues.StringValue{},
|
||||
docvalues.CreateEnumString("Host"): docvalues.StringValue{},
|
||||
docvalues.CreateEnumString("LocalAddress"): docvalues.StringValue{},
|
||||
docvalues.CreateEnumString("LocalPort"): docvalues.NumberValue{Min: &ZERO, Max: &MAX_PORT},
|
||||
|
@ -9,5 +9,12 @@ func TextDocumentHover(
|
||||
context *glsp.Context,
|
||||
params *protocol.HoverParams,
|
||||
) (*protocol.Hover, error) {
|
||||
// line := params.Position.Line
|
||||
// cursor := params.Position.Character
|
||||
//
|
||||
// d := sshdconfig.DocumentParserMap[params.TextDocument.URI]
|
||||
//
|
||||
// entry, matchBlock := d.Config.FindOption(line)
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user