feat(ssh_config): Add unknown option to indexes

This commit is contained in:
Myzel394 2024-10-02 08:14:15 +02:00
parent d9f7e3cbaf
commit bf54705e93
No known key found for this signature in database
GPG Key ID: ED20A1D1D423AF3F
4 changed files with 28 additions and 1 deletions

View File

@ -32,6 +32,7 @@ func analyzeValuesAreValid(
Severity: &common.SeverityError,
},
)
ctx.document.Indexes.UnknownOptions = append(ctx.document.Indexes.UnknownOptions, info)
continue
}

View File

@ -23,6 +23,14 @@ ThisOptionDoesNotExist okay
if !(len(ctx.diagnostics) == 1) {
t.Errorf("Expected 1 error, got %v", len(ctx.diagnostics))
}
if !(len(ctx.document.Indexes.UnknownOptions) == 1) {
t.Errorf("Expected 1 unknown option, got %v", len(ctx.document.Indexes.UnknownOptions))
}
if !(ctx.document.Indexes.UnknownOptions[0].Option.Key.Value.Value == "ThisOptionDoesNotExist") {
t.Errorf("Expected 'ThisOptionDoesNotExist', got %v", ctx.document.Indexes.UnknownOptions[0].Option.Key.Value.Value)
}
}
func TestUnknownOptionButIgnoredExample(
@ -40,7 +48,11 @@ ThisOptionDoesNotExist okay
analyzeValuesAreValid(ctx)
if len(ctx.diagnostics) > 0 {
t.Errorf("Expected no errors, but got %v", len(ctx.diagnostics))
t.Fatalf("Expected no errors, but got %v", len(ctx.diagnostics))
}
if !(len(ctx.document.Indexes.UnknownOptions) == 0) {
t.Errorf("Expected 0 unknown options, got %v", len(ctx.document.Indexes.UnknownOptions))
}
}
@ -61,4 +73,12 @@ IgnoreUnknown ThisOptionDoesNotExist
if !(len(ctx.diagnostics) == 1) {
t.Errorf("Expected 1 error, got %v", len(ctx.diagnostics))
}
if !(len(ctx.document.Indexes.UnknownOptions) == 1) {
t.Errorf("Expected 1 unknown option, got %v", len(ctx.document.Indexes.UnknownOptions))
}
if !(ctx.document.Indexes.UnknownOptions[0].Option.Key.Value.Value == "ThisOptionDoesNotExist") {
t.Errorf("Expected 'ThisOptionDoesNotExist', got %v", ctx.document.Indexes.UnknownOptions[0].Option.Key.Value.Value)
}
}

View File

@ -40,4 +40,9 @@ type SSHIndexes struct {
// Map of <block|nil (for global)> to a list of ignored options
IgnoredOptions map[ast.SSHBlock]SSHIndexIgnoredUnknowns
// This is used for code actions.
// This stores a list of unknown option, so that we can provide
// a code action to add them to a "IgnoreUnknown" option
UnknownOptions []ast.AllOptionInfo
}

View File

@ -16,6 +16,7 @@ func NewSSHIndexes() *SSHIndexes {
AllOptionsPerName: make(map[fields.NormalizedOptionName](map[ast.SSHBlock]([]*ast.SSHOption)), 0),
Includes: make([]*SSHIndexIncludeLine, 0),
IgnoredOptions: make(map[ast.SSHBlock]SSHIndexIgnoredUnknowns),
UnknownOptions: make([]ast.AllOptionInfo, 0),
}
}