Skip to content

Commit 09e8abc

Browse files
authored
Updates to VSCode extension (#2632)
1 parent aeea9b7 commit 09e8abc

12 files changed

+218
-3
lines changed

.vscode/settings.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
"url": "./schemas/PSRule-lock.schema.json"
4545
}
4646
],
47+
"[typescript]": {
48+
"editor.tabSize": 4
49+
},
4750
"[json]": {
4851
"editor.tabCompletion": "on",
4952
"editor.quickSuggestions": {
@@ -130,5 +133,6 @@
130133
"main",
131134
"release/*"
132135
],
133-
"dotnet.completion.showCompletionItemsFromUnimportedNamespaces": true
136+
"dotnet.completion.showCompletionItemsFromUnimportedNamespaces": true,
137+
"PSRule.options.path": "ps-rule-ci.yaml"
134138
}

.vscodeignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ bin/
1616
obj/
1717
out/
1818
!out/dist/
19+
!docs/CHANGELOG-v3.md
1920

2021
.eslintignore
2122
.gitignore
2223
.markdownlint.json
2324
.platyps.yml
2425
.vscode-test.mjs
2526
CHANGELOG.md
27+
README.md
2628
GitVersion.yml
2729
NuGet.config
2830
PSRule.sln
2931
SECURITY.md
30-
SUPPORT.md
3132
build.ps1
3233
esbuild.mjs
3334
global.json

docs/images/codelens-doc-link.png

56.1 KB
Loading

docs/images/options-schema-flyout.png

62.7 KB
Loading

docs/images/snippet-markdown.png

48.8 KB
Loading

docs/images/snippet-rule-type.png

15.4 KB
Loading

docs/images/tasks-provider.png

23.3 KB
Loading

docs/updates/v3_0.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
date: 2024-11-30
3+
version: 3.0
4+
---
5+
6+
## Visual Studio Code
7+
8+
### New home and identity
9+
10+
The Visual Studio Code (VSCode) extension for PSRule now lives side-by-side with the majority of the PSRule code base in `https://github.com/microsoft/PSRule`.
11+
12+
As part of this change we are now publishing the extension as a **verified** Microsoft extension with the ID `ps-rule.code`.
13+
14+
We hope this will not only help the community to log issues and get help on the correct repository,
15+
but also streamline how we deliver updates in the future.
16+
17+
Bringing together the code base is the first step in building an all improved rich experience in VSCode for PSRule.
18+
19+
### Runtime integration
20+
21+
Previously to use PSRule within VSCode,
22+
a prerequisite step was to install PowerShell on non-Windows OSs and then install PSRule through PowerShell.
23+
24+
We've done away with this approach entirely for the authoring experience in VSCode by providing native support in the extension.
25+
26+
### Other minor features and improvements
27+
28+
- You can now override the options file that VSCode uses when running PSRule.
29+
- Previously only `ps-rule.yaml` was used by VSCode although PSRule generally supported changing the options file.

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,13 @@
208208
"description": "Determines if a notification to install the PowerShell extension is shown on start up.",
209209
"scope": "application"
210210
},
211+
"PSRule.options.path": {
212+
"type": "string",
213+
"default": null,
214+
"description": "The path specifying a PSRule option file. When not set, the default ps-rule.yaml will be used from the current workspace.",
215+
"markdownDescription": "The path specifying a PSRule option file. When not set, the default `ps-rule.yaml` will be used from the current workspace.",
216+
"scope": "window"
217+
},
211218
"PSRule.output.as": {
212219
"type": "string",
213220
"default": "Summary",
@@ -493,7 +500,7 @@
493500
"build:esbuild": "node esbuild.mjs",
494501
"package": "npm run package:dotnet && npm run package:esbuild && npm run package:pack",
495502
"package:dotnet": "dotnet build ./src/PSRule.EditorServices/ --output server/",
496-
"package:pack": "vsce package --dependencies --pre-release --no-git-tag-version --no-update-package-json --githubBranch main --out out/package/",
503+
"package:pack": "vsce package --dependencies --pre-release --no-git-tag-version --no-update-package-json --githubBranch main --out out/package/ --readme-path src/code/README.md --changelog-path docs/CHANGELOG-v3.md --baseImagesUrl https://raw.githubusercontent.com/microsoft/PSRule/refs/heads/main/",
497504
"package:esbuild": "node esbuild.mjs",
498505
"test": "npm run build:dotnet && npm run build:esbuild && vscode-test"
499506
},

src/code/README.md

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# PSRule
2+
3+
Validate infrastructure as code (IaC) and DevOps repositories using the PSRule PowerShell module.
4+
PSRule is powerful, feature rich, and highly customizable to meet your needs.
5+
6+
![module-version-badge]
7+
8+
This extension is available in two release channels:
9+
10+
Channel | Description | Version/ downloads
11+
------- | ----------- | ---
12+
[Preview][ext-preview] | More frequent releases but more likely to contain bugs. | [![Preview][ext-preview-version-badge]][ext-preview] ![ext-preview-installs-badge]
13+
[Stable][ext-stable] | Less frequent releases, with more user testing, experimental features are disabled. | [![Stable][ext-stable-version-badge]][ext-stable] ![ext-stable-installs-badge]
14+
15+
## Features
16+
17+
### CodeLens
18+
19+
<p align="center">
20+
<img src="./docs/images/codelens-doc-link.png" alt="CodeLens showing link to create documentation" width="640px" />
21+
</p>
22+
23+
- CodeLens shows links to create or edit markdown documentation from rules in YAML, JSON, or PowerShell.
24+
- **Open documentation** &mdash; Opens rule markdown documentation in the editor.
25+
- The location for storing documentation is configurable in the extension settings.
26+
- By default, a locale specific folder is created in the same directory as the rule file.
27+
- **Create documentation** &mdash; Creates a new markdown file for the rule based on a snippet.
28+
- New markdown documentation is created with the built-in _Rule Doc_ snippet.
29+
- An alternative snippet can be specified by configuring extension settings.
30+
31+
### IntelliSense
32+
33+
<p align="center">
34+
<img src="./docs/images/options-schema-flyout.png" alt="Options suggestion context menu" width="640px" />
35+
</p>
36+
37+
- Adds IntelliSense and validation support for configuring options and resources.
38+
- **Workspace options** &mdash; use IntelliSense to configure options for the workspace.
39+
- Type or trigger IntelliSense with `Ctrl+Space` from `ps-rule.yaml`.
40+
- **Create resources** &mdash; define _baselines_ and _selectors_ by using pre-built snippets and IntelliSense.
41+
42+
<p align="center">
43+
<img src="./docs/images/snippet-rule-type.png" alt="Rule definition snippet" width="520px" />
44+
</p>
45+
46+
- Adds snippets for defining new rules.
47+
- **Define rules** with snippets and IntelliSense support.
48+
- Trigger IntelliSense by typing `rule` in a `.Rule.ps1`, `.Rule.yaml`, or `.Rule.jsonc` file.
49+
IntelliSense can also be triggered by using the shortcut `Ctrl+Space`.
50+
51+
<p align="center">
52+
<img src="./docs/images/snippet-markdown.png" alt="Rule markdown documentation snippet" width="640px" />
53+
</p>
54+
55+
- Adds snippets for creating markdown documentation.
56+
- **Quick documentation** &mdash; create rule documentation to provide rule recommendations and examples.
57+
- Trigger IntelliSense by typing `rule` in a `.md` file.
58+
IntelliSense can also be triggered by using the shortcut `Ctrl+Space`.
59+
60+
### Quick tasks
61+
62+
<p align="center">
63+
<img src="./docs/images/tasks-provider.png" alt="Built-in tasks shown in task list" width="640px" />
64+
</p>
65+
66+
- Adds quick tasks for analysis directly from Visual Studio Code.
67+
- **Run analysis** &mdash; runs rules against files in the current workspace.
68+
- _Input path_, _Baseline_, _Modules_, and _Outcome_ options can be configured per task.
69+
- _Output as_, and showing a _Not processed warning_ options can be configured by workspace or user.
70+
- Rule stored in `.ps-rule/` are automatically used by default.
71+
- Use the built-in analysis task by running or configuring the task from the _Terminal_ menu.
72+
73+
## Configuration
74+
75+
In addition to configuring the [ps-rule.yaml] options file, the following settings are available.
76+
77+
Name | Description
78+
---- | -----------
79+
`PSRule.codeLens.ruleDocumentationLinks` | Enables Code Lens that displays links to rule documentation. This is an experimental feature that requires experimental features to be enabled.
80+
`PSRule.documentation.path` | The path to look for rule documentation. When not set, the path containing rules will be used.
81+
`PSRule.documentation.localePath` | The locale path to use for locating rule documentation. The VS Code locale will be used by default.
82+
`PSRule.documentation.customSnippetPath` | The path to a file containing a rule documentation snippet. When not set, built-in PSRule snippets will be used.
83+
`PSRule.documentation.snippet` | The name of a snippet to use when creating new rule documentation. By default, the built-in `Rule Doc` snippet will be used.
84+
`PSRule.execution.notProcessedWarning` | Warn when objects are not processed by any rule. This option is deprecated and replaced by `PSRule.execution.unprocessedObject`.
85+
`PSRule.execution.ruleExcluded` | Determines how to handle excluded rules. When set to `None`, PSRule will use the default (`Ignore`), unless set by PSRule options.
86+
`PSRule.execution.ruleSuppressed` | Determines how to handle suppressed rules. When set to `None`, PSRule will use the default (`Warn`), unless set by PSRule options.
87+
`PSRule.execution.unprocessedObject` | Determines how to report objects that are not processed by any rule. When set to `None`, PSRule will use the default (`Warn`), unless set by PSRule options.
88+
`PSRule.experimental.enabled` | Enables experimental features in the PSRule extension.
89+
`PSRule.notifications.showChannelUpgrade` | Determines if a notification to switch to the stable channel is shown on start up.
90+
`PSRule.notifications.showPowerShellExtension` | Determines if a notification to install the PowerShell extension is shown on start up.
91+
`PSRule.options.path` | The path specifying a PSRule option file. When not set, the default `ps-rule.yaml` will be used from the current workspace.
92+
`PSRule.output.as` | Configures the output of analysis tasks, either summary or detailed.
93+
`PSRule.rule.baseline` | The name of the default baseline to use for executing rules. This setting can be overridden on individual PSRule tasks.
94+
95+
## Support
96+
97+
This project uses GitHub Issues to track bugs and feature requests.
98+
Please search the existing issues before filing new issues to avoid duplicates.
99+
100+
- For new issues, file your bug or feature request as a new [issue].
101+
- For help, discussion, and support questions about using this project, join or start a [discussion].
102+
103+
Support for this project/ product is limited to the resources listed above.
104+
105+
## Installing PSRule module
106+
107+
PSRule is available from the PowerShell Gallery and is required for this extension to work.
108+
109+
To install the module use the following command from a PowerShell prompt.
110+
111+
```powershell
112+
Install-Module -Name PSRule -Scope CurrentUser;
113+
```
114+
115+
## Installing the extension
116+
117+
You can install the latest release of the extension by following the steps in the [Visual Studio Code documentation][vscode-ext-gallery].
118+
In the Extensions pane, search for _PSRule_ extension and install it there.
119+
You will get notified automatically about any future extension updates.
120+
121+
```text
122+
code --install-extension bewhite.psrule-vscode-preview
123+
```
124+
125+
> NOTE: If you are using VS Code Insiders, the command will be `code-insiders`.
126+
127+
## Contributing
128+
129+
This project welcomes contributions and suggestions.
130+
If you are ready to contribute, please visit the [contribution guide].
131+
132+
## Code of Conduct
133+
134+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
135+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
136+
or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
137+
138+
## Maintainers
139+
140+
- [Bernie White](https://github.com/BernieWhite)
141+
142+
## License
143+
144+
This project is [licensed under the MIT License][license].
145+
146+
[issue]: https://github.com/Microsoft/PSRule/issues
147+
[discussion]: https://github.com/microsoft/PSRule/discussions
148+
[vscode-ext-gallery]: https://code.visualstudio.com/docs/editor/extension-gallery
149+
[ext-preview]: https://marketplace.visualstudio.com/items?itemName=bewhite.psrule-vscode-preview
150+
[ext-preview-version-badge]: https://img.shields.io/visual-studio-marketplace/v/bewhite.psrule-vscode-preview?label=Version
151+
[ext-preview-installs-badge]: https://img.shields.io/visual-studio-marketplace/i/bewhite.psrule-vscode-preview?label=Installs
152+
[ext-stable]: https://marketplace.visualstudio.com/items?itemName=bewhite.psrule-vscode
153+
[ext-stable-version-badge]: https://img.shields.io/visual-studio-marketplace/v/bewhite.psrule-vscode?label=Version
154+
[ext-stable-installs-badge]: https://img.shields.io/visual-studio-marketplace/i/bewhite.psrule-vscode?label=Installs
155+
[module-version-badge]: https://img.shields.io/powershellgallery/v/PSRule?label=PowerShell%20Gallery
156+
[contribution guide]: https://github.com/Microsoft/PSRule/blob/main/CONTRIBUTING.md
157+
[license]: https://github.com/Microsoft/PSRule/blob/main/LICENSE
158+
[ps-rule.yaml]: https://aka.ms/ps-rule/options

src/code/configuration.ts

+9
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ export interface ISetting {
8181
*/
8282
experimentalEnabled: boolean;
8383

84+
/**
85+
* The path specifying a PSRule option file.
86+
* When not set, the default ps-rule.yaml will be used from the current workspace.
87+
*/
88+
optionsPath: string | undefined;
89+
8490
outputAs: OutputAs;
8591
notificationsShowChannelUpgrade: boolean;
8692
notificationsShowPowerShellExtension: boolean;
@@ -114,6 +120,7 @@ const globalDefaults: ISetting = {
114120
executionRuleSuppressed: ExecutionActionPreference.None,
115121
executionUnprocessedObject: ExecutionActionPreference.None,
116122
experimentalEnabled: false,
123+
optionsPath: undefined,
117124
outputAs: OutputAs.Summary,
118125
notificationsShowChannelUpgrade: true,
119126
notificationsShowPowerShellExtension: true,
@@ -199,6 +206,8 @@ export class ConfigurationManager {
199206
this.current.executionRuleSuppressed = config.get<ExecutionActionPreference>('execution.ruleSuppressed', this.default.executionRuleSuppressed);
200207
this.current.executionUnprocessedObject = config.get<ExecutionActionPreference>('execution.unprocessedObject', this.default.executionUnprocessedObject);
201208

209+
this.current.optionsPath = config.get<string>('options.path') ?? this.default.optionsPath;
210+
202211
this.current.outputAs = config.get<OutputAs>('output.as', this.default.outputAs);
203212

204213
this.current.notificationsShowChannelUpgrade = config.get<boolean>(

src/code/tasks.ts

+7
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export class PSRuleTaskProvider implements vscode.TaskProvider {
222222
const executionRuleExcluded = configuration.get().executionRuleExcluded;
223223
const executionRuleSuppressed = configuration.get().executionRuleSuppressed;
224224
const executionUnprocessedObject = configuration.get().executionUnprocessedObject;
225+
const optionsPath = configuration.get().optionsPath;
225226
const outputAs = configuration.get().outputAs;
226227
const ruleBaseline = configuration.get().ruleBaseline;
227228
const traceTask = configuration.get().traceTask;
@@ -239,6 +240,12 @@ export class PSRuleTaskProvider implements vscode.TaskProvider {
239240
params.push(`'${path}'`);
240241
}
241242

243+
// Options Path
244+
if (optionsPath !== undefined && optionsPath !== '') {
245+
params.push('--option');
246+
params.push(`'${optionsPath}'`);
247+
}
248+
242249
// Input Path
243250
if (inputPath !== undefined && inputPath !== '') {
244251
params.push('--input-path');

0 commit comments

Comments
 (0)