You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Configurable Command Plugin Permissions
Packages can define their own plugins either directly or through their
dependencies. These plugins define commands, and the extension exposes a
list of these when you use `> Swift: Run Command Plugin`.
If a command requires special permissions to write to disk or use the
network the user is prompted in the integrated terminal to type "yes".
This can be bypassed by passing a permission flag to the command such as
`--allow-writing-to-package-directory`. The extension does supply
permission flags for a small list of well known package plugins, however
if the user creates their own or uses one not on this list they must
enter "yes" every time they run the command plugin.
This patch introduces a new setting that can be specified globally or on
a per workspace folder basis that allows users to configure which
permission flags should be used when running the command.
The setting is defined under `swift.pluginPermissions`, and is specified
as an object in the following form:
```json
{
"PluginName:intent-name": {
"allowWritingToPackageDirectory": true,
"allowWritingToDirectory: "/some/path",
"allowNetworkConnections: "all",
"disableSandbox": true,
}
}
```
- The top level string key is the command id in the form
`command_name:intent_name`. For instance, swift-format's
format-source-code command would be specified as
`swift-format:format-source-code`
- Each permission in the permissions lookup is optional.
- `allowWritingToDirectory` can also be specified as an array of paths.
- The valid values for `allowNetworkConnections` can be found here:
https://github.com/swiftlang/swift-package-manager/blob/0401a2ae55077cfd1f4c0acd43ae0a1a56ab21ef/Sources/Commands/PackageCommands/PluginCommand.swift#L62
Issue: #1277
Copy file name to clipboardExpand all lines: docs/settings.md
+39
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,45 @@ The Visual Studio Code Swift extension comes with a number of settings you can u
4
4
5
5
This document outlines useful configuration options not covered by the settings descriptions in the extension settings page.
6
6
7
+
## Command Plugins
8
+
9
+
Swift packages can define [command plugins](https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/Plugins.md) that can perform arbitrary tasks. For example, the [swift-format](https://github.com/swiftlang/swift-format) package exposes a `format-source-code` command which will use swift-format to format source code in a folder. These plugin commands can be invoked from VS Code using `> Swift: Run Command Plugin`.
10
+
11
+
A plugin may require permissions to perform tasks like writing to the file system or using the network. If a plugin command requires one of these permissions, you will be prompted in the integrated terminal to accept them. If you trust the command and wish to apply permissions on every command execution, you can configure a setting in your `settings.json`.
12
+
13
+
```json
14
+
{
15
+
"swift.pluginPermissions": {
16
+
"PluginName:command": {
17
+
"allowWritingToPackageDirectory": true,
18
+
"allowWritingToDirectory": "/some/path/",
19
+
"allowNetworkConnections": "all",
20
+
"disableSandbox": true
21
+
}
22
+
}
23
+
}
24
+
```
25
+
26
+
A key of `PluginName:command` will set permissions for a specific command. A key of `PluginName` will set permissions for all commands in the plugin.
27
+
28
+
Alternatively, you can define a task in your tasks.json and define permissions directly on the task. This will create a new entry in the list shown by `> Swift: Run Command Plugin`.
29
+
30
+
```json
31
+
{
32
+
"type": "swift-plugin",
33
+
"command": "command_plugin",
34
+
"args": ["--foo"],
35
+
"cwd": "command-plugin",
36
+
"problemMatcher": ["$swiftc"],
37
+
"label": "swift: command-plugin from tasks.json",
38
+
39
+
"allowWritingToPackageDirectory": true,
40
+
"allowWritingToDirectory": "/some/path/",
41
+
"allowNetworkConnections": "all",
42
+
"disableSandbox": true
43
+
}
44
+
```
45
+
7
46
## SourceKit-LSP
8
47
9
48
[SourceKit-LSP](https://github.com/apple/sourcekit-lsp) is the language server used by the the Swift extension to provide symbol completion, jump to definition etc. It is developed by Apple to provide Swift and C language support for any editor that supports the Language Server Protocol.
Copy file name to clipboardExpand all lines: package.json
+40
Original file line number
Diff line number
Diff line change
@@ -394,6 +394,46 @@
394
394
"type": "boolean",
395
395
"default": true,
396
396
"markdownDescription": "Controls whether or not the extension will contribute environment variables defined in `Swift: Environment Variables` to the integrated terminal. If this is set to `true` and a custom `Swift: Path` is also set then the swift path is appended to the terminal's `PATH`."
397
+
},
398
+
"swift.pluginPermissions": {
399
+
"type": "object",
400
+
"default": {},
401
+
"markdownDescription": "Configures a list of permissions to be used when running a command plugins.\n\nPermissions objects are defined in the form:\n\n`{ \"PluginName:command\": { \"allowWritingToPackageDirectory\": true } }`.\n\nA key of `PluginName:command` will set permissions for a specific command. A key of `PluginName` will set permissions for all commands in the plugin.",
402
+
"scope": "machine-overridable",
403
+
"patternProperties": {
404
+
"^([a-zA-Z0-9_-]+(:[a-zA-Z0-9_-]+)?)$": {
405
+
"type": "object",
406
+
"properties": {
407
+
"disableSandbox": {
408
+
"type": "boolean",
409
+
"description": "Disable using the sandbox when executing plugins"
410
+
},
411
+
"allowWritingToPackageDirectory": {
412
+
"type": "boolean",
413
+
"description": "Allow the plugin to write to the package directory"
414
+
},
415
+
"allowWritingToDirectory": {
416
+
"oneOf": [
417
+
{
418
+
"type": "string",
419
+
"description": "Allow the plugin to write to an additional directory"
420
+
},
421
+
{
422
+
"type": "array",
423
+
"items": {
424
+
"type": "string"
425
+
},
426
+
"description": "Allow the plugin to write to additional directories"
427
+
}
428
+
]
429
+
},
430
+
"allowNetworkConnections": {
431
+
"type": "string",
432
+
"description": "Allow the plugin to make network connections"
0 commit comments