Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting formatter via configuration #226

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Additionally, users may choose to install [Regal](https://docs.styra.com/regal),
* Folding ranges (expand/collapse blocks, imports, comments)
* Document and workspace symbols (navigate to rules, functions, packages)
* Inlay hints (show names of built-in function arguments next to their values)
* Formatting
* Formatting (`opa fmt`, `opa fmt --rego-v1` or `regal fix`, see [Configuration](#configuration) below)
* Code actions (quick fixes for linting issues)
* Code completions

Expand Down Expand Up @@ -56,6 +56,7 @@ or search for "Open Policy Agent" in the 'Extensions' panel.
| `opa.schema` | `null` | Path to the [schema](https://www.openpolicyagent.org/docs/latest/policy-language/#using-schemas-to-enhance-the-rego-type-checker) file or directory. If set to `null`, schema evaluation is disabled. As for `opa.roots`, `${workspaceFolder}` and `${fileDirname}` variables can be used in the path. |
| `opa.languageServers` | `null` | An array of enabled language servers (currently `["regal"]` is supported) |
| `opa.env` | `{}` | Object of environment variables passed to the process running OPA (e.g. `{"key": "value"}`) |
| `opa.formatter` | `opa-fmt` | Name of the OPA formatter to use. Requires Regal. One of `opa-fmt`, `opa-fmt-rego-v1` and `regal-fix`. This value is sent as an initialization option to the language server, so the change won't take effect before the project (or VS Code) is reloaded. See the documentation for the [regal fix](https://docs.styra.com/regal/fixing) command for more information |

Note that the `${workspaceFolder}` variable will expand to a full URI of the workspace, as expected by most VS Code commands. The `${workspacePath}` variable may additionally be used where only the path component (i.e. without the `file://` schema component) of the workspace URI is required.

Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@
},
"default": {},
"description": "Environment variables passed to the process running OPA."
},
"opa.formatter": {
"type": [
"string"
],
"default": "opa-fmt",
"description": "The formatter to use for Rego. Supports: ['opa-fmt', 'opa-fmt-rego-v1', 'regal-fix']."
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions src/ls/clients/regal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ export function activateRegal(_context: ExtensionContext) {
onChange: true,
onSave: true,
},
initializationOptions: {
formatter: vscode.workspace.getConfiguration('opa').get<string>('formatter', 'opa-fmt'),
}
};

client = new LanguageClient(
Expand Down
Loading