-
Notifications
You must be signed in to change notification settings - Fork 771
/
Copy pathSecureParameterCodeFixProvider.cs
41 lines (35 loc) · 1.38 KB
/
SecureParameterCodeFixProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.Linq;
using Bicep.Core.CodeAction;
using Bicep.Core.Semantics;
using Bicep.Core.Syntax;
namespace Bicep.LanguageServer.CodeFixes
{
public class SecureParameterCodeFixProvider : ICodeFixProvider
{
public IEnumerable<CodeFix> GetFixes(SemanticModel semanticModel, IReadOnlyList<SyntaxBase> matchingNodes)
{
if (matchingNodes.OfType<ParameterDeclarationSyntax>().FirstOrDefault() is not {} parameterSyntax ||
semanticModel.GetSymbolInfo(parameterSyntax) is not ParameterSymbol parameterSymbol)
{
yield break;
}
var newLeadingNodes = parameterSyntax.LeadingNodes
.Add(SyntaxFactory.CreateDecorator("secure"))
.Add(SyntaxFactory.NewlineToken);
var newParameterSyntax = new ParameterDeclarationSyntax(
newLeadingNodes,
parameterSyntax.Keyword,
parameterSyntax.Name,
parameterSyntax.Type,
parameterSyntax.Modifier);
var codeReplacement = CodeReplacement.FromSyntax(parameterSyntax.Span, newParameterSyntax);
yield return new CodeFix(
"Add @secure",
false,
codeReplacement);
}
}
}