diff --git a/handlers/ssh_config/analyzer/values.go b/handlers/ssh_config/analyzer/values.go index 063b393..742a435 100644 --- a/handlers/ssh_config/analyzer/values.go +++ b/handlers/ssh_config/analyzer/values.go @@ -32,6 +32,7 @@ func analyzeValuesAreValid( Severity: &common.SeverityError, }, ) + ctx.document.Indexes.UnknownOptions = append(ctx.document.Indexes.UnknownOptions, info) continue } diff --git a/handlers/ssh_config/analyzer/values_test.go b/handlers/ssh_config/analyzer/values_test.go index 14d8a59..88bffcc 100644 --- a/handlers/ssh_config/analyzer/values_test.go +++ b/handlers/ssh_config/analyzer/values_test.go @@ -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) + } } diff --git a/handlers/ssh_config/indexes/indexes.go b/handlers/ssh_config/indexes/indexes.go index 015cd74..175a061 100644 --- a/handlers/ssh_config/indexes/indexes.go +++ b/handlers/ssh_config/indexes/indexes.go @@ -40,4 +40,9 @@ type SSHIndexes struct { // Map of 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 } diff --git a/handlers/ssh_config/indexes/indexes_handlers.go b/handlers/ssh_config/indexes/indexes_handlers.go index cab0d25..5c8093b 100644 --- a/handlers/ssh_config/indexes/indexes_handlers.go +++ b/handlers/ssh_config/indexes/indexes_handlers.go @@ -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), } }