Skip to content

Commit

Permalink
Revert "Provide adding decorators as quickfix. Fixes #1406 (#5544)"
Browse files Browse the repository at this point in the history
This reverts commit a61ba07.
  • Loading branch information
Stephen Weatherford committed Jan 28, 2022
1 parent a61ba07 commit 6e6d5ce
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 298 deletions.
9 changes: 2 additions & 7 deletions src/Bicep.Core/Semantics/SymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ public static SyntaxBase UnTryGetBodyPropertyValue(this ResourceSymbol resourceS
=> TryGetBodyProperty(moduleSymbol, propertyName)?.Value;

public static bool IsSecure(this ParameterSymbol parameterSymbol)
{
return HasDecorator(parameterSymbol, "secure");
}

public static bool HasDecorator(this ParameterSymbol parameterSymbol, string decoratorName)
{
// local function
bool hasDecorator(DecoratorSyntax? value, string decoratorName) => value?.Expression is FunctionCallSyntax functionCallSyntax && functionCallSyntax.NameEquals(decoratorName);
bool isSecure(DecoratorSyntax? value) => value?.Expression is FunctionCallSyntax functionCallSyntax && functionCallSyntax.NameEquals("secure");

if (parameterSymbol?.DeclaringSyntax is ParameterDeclarationSyntax paramDeclaration)
{
return paramDeclaration.Decorators.Any(d => hasDecorator(d, decoratorName));
return paramDeclaration.Decorators.Any(d => isSecure(d));
}
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Bicep.LangServer.IntegrationTests/CodeActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task RequestingCodeActionWithFixableDiagnosticsShouldProduceQuickFi
// Assert.
quickFixes.Should().NotBeNull();

var quickFixList = quickFixes.Where(x => x.CodeAction?.Kind == CodeActionKind.QuickFix && x.CodeAction?.IsPreferred == true).ToList();
var quickFixList = quickFixes.Where(x => x.CodeAction?.Kind == CodeActionKind.QuickFix).ToList();
var bicepFixList = fixable.Fixes.ToList();

quickFixList.Should().HaveSameCount(bicepFixList);
Expand Down Expand Up @@ -188,7 +188,8 @@ private async Task VerifyCodeActionIsAvailableToSuppressLinterDiagnostics(string
TextDocument = new TextDocumentIdentifier(documentUri),
Range = diagnostics.First().ToRange(lineStarts)
});
codeActions.Where(c => c.CodeAction?.Kind != CodeActionKind.QuickFix).Should().SatisfyRespectively(

codeActions.Should().SatisfyRespectively(
x =>
{
x.CodeAction!.Title.Should().Be("Disable no-unused-params for this line");
Expand Down
183 changes: 0 additions & 183 deletions src/Bicep.LangServer.IntegrationTests/CodeFixTests.cs

This file was deleted.

15 changes: 0 additions & 15 deletions src/Bicep.LangServer/CodeFixes/ICodeFixProvider.cs

This file was deleted.

54 changes: 0 additions & 54 deletions src/Bicep.LangServer/CodeFixes/ParameterCodeFixProvider.cs

This file was deleted.

14 changes: 0 additions & 14 deletions src/Bicep.LangServer/Completions/SyntaxMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Bicep.Core.Extensions;
using Bicep.Core.Navigation;
using Bicep.Core.Parsing;
using Bicep.Core.Syntax;
Expand Down Expand Up @@ -156,18 +154,6 @@ public static List<SyntaxBase> FindNodesMatchingOffset(ProgramSyntax syntax, int
return nodes;
}

public static ImmutableArray<SyntaxBase> FindNodesInRange(ProgramSyntax syntax, int startOffset, int endOffset)
{
var startNodes = FindNodesMatchingOffset(syntax, startOffset);
var endNodes = FindNodesMatchingOffset(syntax, endOffset);

return startNodes
.Zip(endNodes, (x, y) => object.ReferenceEquals(x, y) ? x : null)
.TakeWhile(x => x is not null)
.WhereNotNull()
.ToImmutableArray();
}

public static List<SyntaxBase> FindNodesMatchingOffsetExclusive(ProgramSyntax syntax, int offset)
{
var nodes = new List<SyntaxBase>();
Expand Down
23 changes: 0 additions & 23 deletions src/Bicep.LangServer/Handlers/BicepCodeActionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
Expand All @@ -12,38 +10,23 @@
using Bicep.Core.Diagnostics;
using Bicep.Core.Extensions;
using Bicep.Core.Parsing;
using Bicep.Core.Syntax;
using Bicep.Core.Text;
using Bicep.Core.Workspaces;
using Bicep.LanguageServer.CodeFixes;
using Bicep.LanguageServer.CompilationManager;
using Bicep.LanguageServer.Completions;
using Bicep.LanguageServer.Extensions;
using Bicep.LanguageServer.Telemetry;
using Bicep.LanguageServer.Utils;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using Range = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;

namespace Bicep.LanguageServer.Handlers
{
public class BicepCodeActionHandler : CodeActionHandlerBase
{
private readonly ICompilationManager compilationManager;

private static readonly ImmutableArray<ICodeFixProvider> codeFixProviders = new ICodeFixProvider[]
{
new ParameterCodeFixProvider("secure", new []{"string", "object"}, Array.Empty<SyntaxBase>()),
new ParameterCodeFixProvider("description", new []{"string", "object", "array", "bool", "int"}, new []{SyntaxFactory.CreateStringLiteral(String.Empty)}),
new ParameterCodeFixProvider("allowed", new []{"string", "object", "array", "bool", "int"}, new []{SyntaxFactory.CreateArray(Array.Empty<SyntaxBase>()) }),
new ParameterCodeFixProvider("minLength", new []{"string", "array"}, Array.Empty<SyntaxBase>()),
new ParameterCodeFixProvider("maxLength", new []{"string", "array"}, Array.Empty<SyntaxBase>()),
new ParameterCodeFixProvider("minValue", new []{"int"}, Array.Empty<SyntaxBase>()),
new ParameterCodeFixProvider("maxValue", new []{"int"}, Array.Empty<SyntaxBase>()),
}.ToImmutableArray<ICodeFixProvider>();

public BicepCodeActionHandler(ICompilationManager compilationManager)
{
this.compilationManager = compilationManager;
Expand Down Expand Up @@ -106,12 +89,6 @@ public override Task<CommandOrCodeActionContainer> Handle(CodeActionParams reque
}
}

var matchingNodes = SyntaxMatcher.FindNodesInRange(compilationContext.ProgramSyntax, requestStartOffset, requestEndOffset);
var codeFixes = codeFixProviders
.SelectMany(provider => provider.GetFixes(semanticModel, matchingNodes))
.Select(fix => CreateQuickFix(request.TextDocument.Uri, compilationContext, fix));
commandOrCodeActions.AddRange(codeFixes);

return Task.FromResult(new CommandOrCodeActionContainer(commandOrCodeActions));
}

Expand Down

0 comments on commit 6e6d5ce

Please sign in to comment.