Skip to content

Commit

Permalink
support fileDirname variable in roots configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Itay Shakury <[email protected]>
  • Loading branch information
itaysk authored and tsandall committed Jun 1, 2020
1 parent 68f3e03 commit b511634
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Search for "Open Policy Agent" in the Extensions (Shift ⌘ X) panel and then in
| --- | --- | --- |
| `opa.path` | `null` | Set path of OPA executable. |
| `opa.checkOnSave` | `false` | Enable automatic checking of .rego files on save. |
| `opa.roots` | `[${workspaceFolder}]` | List of paths to load as bundles for policy and data. Defaults to a single entry which is the current workspace root. The variable `${workspaceFolder}` will be resolved as the current workspace root. |
| `opa.roots` | `[${workspaceFolder}]` | List of paths to load as bundles for policy and data. Defaults to a single entry which is the current workspace root. The variable `${workspaceFolder}` will be resolved as the current workspace root. The variable `${fileDirname} will be resolved as the directory of the file currently opened in the active window. |
| `opa.bundleMode` | `true` | Enable treating the workspace as a bundle to avoid loading erroneous data JSON/YAML files. It is _NOT_ recommended to disable this. |

> For bundle documentation refer to [https://www.openpolicyagent.org/docs/latest/management/#bundle-file-format](https://www.openpolicyagent.org/docs/latest/management/#bundle-file-format).
Expand Down
2 changes: 2 additions & 0 deletions src/opa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as vscode from 'vscode';
import { promptForInstall } from './install-opa';
import { getImports, getPackage } from './util';
import { existsSync } from 'fs';
import { dirname } from 'path';

var regoVarPattern = new RegExp('^[a-zA-Z_][a-zA-Z0-9_]*$');

Expand Down Expand Up @@ -43,6 +44,7 @@ export function getRoots(): string[] {
let formattedRoots = new Array();
roots.forEach(root => {
root = root.replace('${workspaceFolder}', vscode.workspace.workspaceFolders![0].uri.toString());
root = root.replace('${fileDirname}', dirname(vscode.window.activeTextEditor!.document.fileName));
formattedRoots.push(getDataDir(vscode.Uri.parse(root)));
});

Expand Down

0 comments on commit b511634

Please sign in to comment.