Skip to content

Commit

Permalink
Lightbulb/cmd to edit config
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Weatherford committed Mar 11, 2022
1 parent 1ac421f commit bb01cbb
Show file tree
Hide file tree
Showing 27 changed files with 1,650 additions and 904 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"BICEP_TRACING_ENABLED": "true",

// Defaulting to "verbose" when debugging so that new telemetry IDs during development aren't accidentally sent and created before they're finalized
"DEBUGTELEMETRY": "v", // "" or "0" or "false": send telemetry as normal; "1": debug mode (no telemetry sent); "verbose": telemetry in console, don't send (from vscode-azureextensionui)
"DEBUGTELEMETRY": "v", // "" or "0" or "false": send telemetry as normal; "1": debug mode (no telemetry sent); "verbose": telemetry in console, don't send (from microsoft/vscode-azext-utils)
},
"stopOnEntry": false,
"sourceMaps": true,
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ If you have an active branch pushed to your GitHub fork, you can use the "Update
* On the first run, you'll need to ensure you have installed all the npm packages required by the Bicep VSCode extension with the following:
* `cd src/vscode-bicep`
* `npm i`
* In the [VSCode Run View](https://code.visualstudio.com/Docs/editor/debugging), select the "Bicep VSCode Extension" task, and press the "Start" button. This will launch a new VSCode window with the Bicep extension and LanguageServer containing your changes. When running on WSL, create a symbolic link in `src/vscode-bicep` named `bicepLanguageServer` to `../Bicep.LangServer/bin/Debug/net6.0`.
* If you want the ability to put breakpoints and step through the C# code, you can also use the "Attach" run configuration once the extension host has launched, and select the Bicep LanguageServer process by searching for "bicep".
* In the [VSCode Run View](https://code.visualstudio.com/Docs/editor/debugging), select the "VSCode Extension" task, and press the "Start" button. This will launch a new VSCode window with the Bicep extension and LanguageServer containing your changes. When running on WSL, create a symbolic link in `src/vscode-bicep` named `bicepLanguageServer` to `../Bicep.LangServer/bin/Debug/net6.0`.
* If you want the ability to set breakpoints and step through the C# code, you can also use the "Attach" run configuration once the extension host has launched, and select the Bicep LanguageServer process by searching for "dotnet" processes with a command line containing "...\Bicep.LangServer.dll --pipe=..." (Windows) or "vscode-*.sock" (MacOs).

### Running the Bicep CLI

Expand Down
20 changes: 20 additions & 0 deletions src/Bicep.Core/Configuration/DefaultBicepConfigHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Bicep.Core.Configuration
{
public static class DefaultBicepConfigHelper
{
public static string GetDefaultBicepConfig()
{
return @"{
""analyzers"": {
""core"": {
""rules"": {
}
}
}
}";
}
}
}
3 changes: 2 additions & 1 deletion src/Bicep.Core/LanguageConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public static class LanguageConstants

public const string BicepConfigurationFileName = "bicepconfig.json";

public const string DisableLinterRuleCommandName = "bicep.DisableLinterRule";
// An internal-only command used in code actions to edit a particular rule in the bicepconfig.json file
public const string EditLinterRuleCommandName = "bicep.EditLinterRule";

public const string DisableNextLineDiagnosticsKeyword = "disable-next-line";

Expand Down
301 changes: 0 additions & 301 deletions src/Bicep.LangServer.IntegrationTests/CodeActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Bicep.Core;
using Bicep.Core.Analyzers;
using Bicep.Core.CodeAction;
using Bicep.Core.Diagnostics;
using Bicep.Core.Extensions;
using Bicep.Core.FileSystem;
using Bicep.Core.Navigation;
using Bicep.Core.Parsing;
using Bicep.Core.Registry;
using Bicep.Core.Samples;
using Bicep.Core.Semantics;
using Bicep.Core.Text;
Expand Down Expand Up @@ -108,304 +105,6 @@ public async Task RequestingCodeActionWithFixableDiagnosticsShouldProduceQuickFi
}
}

#if false //asdfg
[TestMethod]
public async Task DisableLinterRuleCodeActionInvocation_WithoutBicepConfig_ShouldCreateConfigFileAndDisableRule()
{
var bicepFileContents = "param storageAccountName string = 'testAccount'";
var expectedBicepConfigContents = @"{
""cloud"": {
""currentProfile"": ""AzureCloud"",
""profiles"": {
""AzureCloud"": {
""resourceManagerEndpoint"": ""https://management.azure.com"",
""activeDirectoryAuthority"": ""https://login.microsoftonline.com""
},
""AzureChinaCloud"": {
""resourceManagerEndpoint"": ""https://management.chinacloudapi.cn"",
""activeDirectoryAuthority"": ""https://login.chinacloudapi.cn""
},
""AzureUSGovernment"": {
""resourceManagerEndpoint"": ""https://management.usgovcloudapi.net"",
""activeDirectoryAuthority"": ""https://login.microsoftonline.us""
}
},
""credentialPrecedence"": [
""AzureCLI"",
""AzurePowerShell""
]
},
""moduleAliases"": {
""ts"": {},
""br"": {}
},
""analyzers"": {
""core"": {
""verbose"": false,
""enabled"": true,
""rules"": {
""no-hardcoded-env-urls"": {
""level"": ""warning"",
""disallowedhosts"": [
""gallery.azure.com"",
""management.core.windows.net"",
""management.azure.com"",
""database.windows.net"",
""core.windows.net"",
""login.microsoftonline.com"",
""graph.windows.net"",
""trafficmanager.net"",
""datalake.azure.net"",
""azuredatalakestore.net"",
""azuredatalakeanalytics.net"",
""vault.azure.net"",
""api.loganalytics.io"",
""asazure.windows.net"",
""region.asazure.windows.net"",
""batch.core.windows.net""
],
""excludedhosts"": [
""schema.management.azure.com""
]
},
""no-unused-params"": {
""level"": ""off""
}
}
}
}
}";
await VerifyLinterRuleIsDisabledAsync(bicepFileContents: bicepFileContents,
bicepConfigFileContents: null,
diagnosticLevel: DiagnosticLevel.Warning,
diagnosticMessage: @"Parameter ""storageAccountName"" is declared but never used.",
expectedBicepConfigFileContents: expectedBicepConfigContents);
}

[TestMethod]
public async Task DisableLinterRuleCodeActionInvocation_WithBicepConfig_ShouldUpdateConfigFileAndDisableRule()
{
var bicepFileContents = "param storageAccountName string = 'testAccount'";
var bicepConfigContents = @"{
""analyzers"": {
""core"": {
""verbose"": false,
""enabled"": true,
""rules"": {
""no-unused-params"": {
""level"": ""info""
}
}
}
}
}";
var expectedBicepConfigContents = @"{
""analyzers"": {
""core"": {
""verbose"": false,
""enabled"": true,
""rules"": {
""no-unused-params"": {
""level"": ""off""
}
}
}
}
}";
await VerifyLinterRuleIsDisabledAsync(bicepFileContents: bicepFileContents,
bicepConfigFileContents: bicepConfigContents,
diagnosticLevel: DiagnosticLevel.Info,
diagnosticMessage: @"Parameter ""storageAccountName"" is declared but never used.",
expectedBicepConfigFileContents: expectedBicepConfigContents);

}

[TestMethod]
public async Task DisableLinterRuleCodeActionInvocation_WithoutRulesNodeInBicepConfig_ShouldUpdateConfigFileAndDisableRule()
{
var bicepFileContents = "param storageAccountName string = 'testAccount'";
var bicepConfigContents = @"{
""analyzers"": {
""core"": {
""verbose"": false,
""enabled"": true
}
}
}";
var expectedBicepConfigContents = @"{
""analyzers"": {
""core"": {
""verbose"": false,
""enabled"": true,
""rules"": {
""no-unused-params"": {
""level"": ""off""
}
}
}
}
}";
await VerifyLinterRuleIsDisabledAsync(bicepFileContents: bicepFileContents,
bicepConfigFileContents: bicepConfigContents,
diagnosticLevel: DiagnosticLevel.Warning,
diagnosticMessage: @"Parameter ""storageAccountName"" is declared but never used.",
expectedBicepConfigFileContents: expectedBicepConfigContents);

}

[TestMethod]
public async Task DisableLinterRuleCodeActionInvocation_WithoutRuleInBicepConfig_ShouldUpdateConfigFileAndDisableRule()
{
var bicepFileContents = "param storageAccountName string = 'testAccount'";
var bicepConfigContents = @"{
""analyzers"": {
""core"": {
""verbose"": false,
""enabled"": true,
""rules"": {
""no-unused-vars"": {
""level"": ""warning""
}
}
}
}
}";
var expectedBicepConfigContents = @"{
""analyzers"": {
""core"": {
""verbose"": false,
""enabled"": true,
""rules"": {
""no-unused-vars"": {
""level"": ""warning""
},
""no-unused-params"": {
""level"": ""off""
}
}
}
}
}";
await VerifyLinterRuleIsDisabledAsync(bicepFileContents: bicepFileContents,
bicepConfigFileContents: bicepConfigContents,
diagnosticLevel: DiagnosticLevel.Warning,
diagnosticMessage: @"Parameter ""storageAccountName"" is declared but never used.",
expectedBicepConfigFileContents: expectedBicepConfigContents);

}

[TestMethod]
public async Task DisableLinterRuleCodeActionInvocation_WithoutLevelPropertyInRule_ShouldUpdateConfigFileAndDisableRule()
{
var bicepFileContents = "param storageAccountName string = 'testAccount'";
var bicepConfigContents = @"{
""analyzers"": {
""core"": {
""verbose"": false,
""enabled"": true,
""rules"": {
""no-unused-params"": {
}
}
}
}
}";
var expectedBicepConfigContents = @"{
""analyzers"": {
""core"": {
""verbose"": false,
""enabled"": true,
""rules"": {
""no-unused-params"": {
""level"": ""off""
}
}
}
}
}";
await VerifyLinterRuleIsDisabledAsync(bicepFileContents: bicepFileContents,
bicepConfigFileContents: bicepConfigContents,
diagnosticLevel: DiagnosticLevel.Warning,
diagnosticMessage: @"Parameter ""storageAccountName"" is declared but never used.",
expectedBicepConfigFileContents: expectedBicepConfigContents);

}

[TestMethod]
public async Task DisableLinterRuleCodeActionInvocation_WithOnlyCurlyBracesInBicepConfig_ShouldUpdateConfigFileAndDisableRule()
{
var bicepFileContents = "param storageAccountName string = 'testAccount'";
var bicepConfigContents = @"{}";
var expectedBicepConfigContents = @"{
""cloud"": {
""currentProfile"": ""AzureCloud"",
""profiles"": {
""AzureCloud"": {
""resourceManagerEndpoint"": ""https://management.azure.com"",
""activeDirectoryAuthority"": ""https://login.microsoftonline.com""
},
""AzureChinaCloud"": {
""resourceManagerEndpoint"": ""https://management.chinacloudapi.cn"",
""activeDirectoryAuthority"": ""https://login.chinacloudapi.cn""
},
""AzureUSGovernment"": {
""resourceManagerEndpoint"": ""https://management.usgovcloudapi.net"",
""activeDirectoryAuthority"": ""https://login.microsoftonline.us""
}
},
""credentialPrecedence"": [
""AzureCLI"",
""AzurePowerShell""
]
},
""moduleAliases"": {
""ts"": {},
""br"": {}
},
""analyzers"": {
""core"": {
""verbose"": false,
""enabled"": true,
""rules"": {
""no-hardcoded-env-urls"": {
""level"": ""warning"",
""disallowedhosts"": [
""gallery.azure.com"",
""management.core.windows.net"",
""management.azure.com"",
""database.windows.net"",
""core.windows.net"",
""login.microsoftonline.com"",
""graph.windows.net"",
""trafficmanager.net"",
""datalake.azure.net"",
""azuredatalakestore.net"",
""azuredatalakeanalytics.net"",
""vault.azure.net"",
""api.loganalytics.io"",
""asazure.windows.net"",
""region.asazure.windows.net"",
""batch.core.windows.net""
],
""excludedhosts"": [
""schema.management.azure.com""
]
},
""no-unused-params"": {
""level"": ""off""
}
}
}
}
}";
await VerifyLinterRuleIsDisabledAsync(bicepFileContents: bicepFileContents,
bicepConfigFileContents: bicepConfigContents,
diagnosticLevel: DiagnosticLevel.Warning,
diagnosticMessage: @"Parameter ""storageAccountName"" is declared but never used.",
expectedBicepConfigFileContents: expectedBicepConfigContents);
}
#endif

[TestMethod]
public async Task VerifyCodeActionIsAvailableToSuppressLinterWarning()
{
Expand Down
Loading

0 comments on commit bb01cbb

Please sign in to comment.