-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathextension.ts
750 lines (631 loc) · 23.1 KB
/
extension.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
"use strict";
import * as fs from "fs";
import * as path from "path";
import * as vscode from "vscode";
import { activateDebugger } from "./da/activate";
import { activateLanguageServers } from "./ls/activate";
import { advertiseLanguageServers } from "./ls/advertise";
import { configureLanguageServers } from "./ls/configure";
import * as opa from "./opa";
import { getPrettyTime } from "./util";
export const opaOutputChannel = vscode.window.createOutputChannel("OPA");
export class JSONProvider implements vscode.TextDocumentContentProvider {
private _onDidChange = new vscode.EventEmitter<vscode.Uri>();
private content = "";
public provideTextDocumentContent(_uri: vscode.Uri): string {
return this.content;
}
get onDidChange(): vscode.Event<vscode.Uri> {
return this._onDidChange.event;
}
public set(uri: vscode.Uri, note: string, output: any) {
this.content = note;
if (output !== undefined) {
this.content += "\n" + JSON.stringify(output, undefined, 2);
}
this._onDidChange.fire(uri);
}
}
export function activate(context: vscode.ExtensionContext) {
vscode.window.onDidChangeActiveTextEditor(showCoverageOnEditorChange, null, context.subscriptions);
vscode.workspace.onDidChangeTextDocument(removeDecorationsOnDocumentChange, null, context.subscriptions);
activateCheckFile(context);
activateCoverWorkspace(context);
activateEvalPackage(context);
activateEvalSelection(context);
activateEvalCoverage(context);
activateTestWorkspace(context);
activateTraceSelection(context);
activateProfileSelection(context);
activatePartialSelection(context);
activateClearPromptsCommand(context);
// promote available language servers to users with none installed
advertiseLanguageServers(context);
// prompt users with language servers installed to enable them
configureLanguageServers(context);
// start configured language servers
activateLanguageServers(context);
// activate the debugger
activateDebugger(context);
// this will trigger the prompt to install OPA if missing, rather than waiting til on save
// the manual running of a command
opa.runWithStatus(context, "opa", ["version"], "", (_code: number, _stderr: string, _stdout: string) => {});
vscode.workspace.onDidChangeConfiguration((_event) => {
// configureLanguageServers is run here to catch newly installed language servers,
// after their paths are updated.
configureLanguageServers(context);
activateLanguageServers(context);
activateDebugger(context);
});
}
// this is the decoration type for the eval result covering the whole line
export const evalResultDecorationType = vscode.window.createTextEditorDecorationType({
isWholeLine: true,
after: {
textDecoration: "none",
fontWeight: "normal",
fontStyle: "normal",
},
});
// decoration type for the eval result covering only the rule name when the result is defined
export const evalResultTargetSuccessDecorationType = vscode.window.createTextEditorDecorationType({
isWholeLine: false,
backgroundColor: new vscode.ThemeColor("diffEditor.insertedTextBackground"),
});
// decoration type for the eval result covering only the rule name when the result is undefined
export const evalResultTargetUndefinedDecorationType = vscode.window.createTextEditorDecorationType({
isWholeLine: false,
backgroundColor: new vscode.ThemeColor("inputValidation.warningBackground"),
});
// remove all decorations from the active editor using the known types of decorations
export function removeDecorations() {
Object.keys(fileCoverage).forEach((fileName) => {
vscode.window.visibleTextEditors.forEach((value) => {
if (value.document.fileName.endsWith(fileName)) {
value.setDecorations(coveredHighlight, []);
value.setDecorations(notCoveredHighlight, []);
}
});
});
fileCoverage = {};
vscode.window.visibleTextEditors.forEach((value) => {
value.setDecorations(evalResultDecorationType, []);
value.setDecorations(evalResultTargetSuccessDecorationType, []);
value.setDecorations(evalResultTargetUndefinedDecorationType, []);
});
}
const outputUri = vscode.Uri.parse(`json:output.jsonc`);
const coveredHighlight = vscode.window.createTextEditorDecorationType({
backgroundColor: "rgba(64,128,64,0.5)",
isWholeLine: true,
});
const notCoveredHighlight = vscode.window.createTextEditorDecorationType({
backgroundColor: "rgba(128,64,64,0.5)",
isWholeLine: true,
});
interface UntypedObject {
[key: string]: any;
}
let fileCoverage: UntypedObject = {};
function showCoverageOnEditorChange(editor: vscode.TextEditor | undefined) {
if (!editor) {
return;
}
showCoverageForEditor(editor);
}
function removeDecorationsOnDocumentChange(e: vscode.TextDocumentChangeEvent) {
// output:extension-output is the output channel for the extensions
// and should not be used for clearing decorations
if (e.document.uri.toString().startsWith("output:extension-output")) {
return;
}
// output URI is the URI of the JSON file used for the eval result output
if (`${e.document.uri}` === `${outputUri}`) {
return;
}
removeDecorations();
}
function showCoverageForEditor(_editor: vscode.TextEditor) {
Object.keys(fileCoverage).forEach((fileName) => {
vscode.window.visibleTextEditors.forEach((value) => {
if (value.document.fileName.endsWith(fileName)) {
value.setDecorations(coveredHighlight, fileCoverage[fileName].covered);
value.setDecorations(notCoveredHighlight, fileCoverage[fileName].notCovered);
}
});
});
}
function showCoverageForWindow() {
vscode.window.visibleTextEditors.forEach((value) => {
showCoverageForEditor(value);
});
}
function setFileCoverage(result: any) {
Object.keys(result.files).forEach((fileName) => {
const report = result.files[fileName];
if (!report) {
return;
}
let covered = [];
if (report.covered !== undefined) {
covered = report.covered.map((range: any) => {
return new vscode.Range(range.start.row - 1, 0, range.end.row - 1, 1000);
});
}
let notCovered = [];
if (report.not_covered !== undefined) {
notCovered = report.not_covered.map((range: any) => {
return new vscode.Range(range.start.row - 1, 0, range.end.row - 1, 1000);
});
}
fileCoverage[fileName] = {
covered: covered,
notCovered: notCovered,
};
});
}
function setEvalOutput(provider: JSONProvider, uri: vscode.Uri, stderr: string, result: any, inputPath: string) {
if (stderr !== "") {
opaOutputShow(stderr);
} else {
opaOutputHide();
}
let inputMessage: string;
if (inputPath === "") {
inputMessage = "no input file";
} else {
inputMessage = inputPath.replace("file://", "");
inputMessage = vscode.workspace.asRelativePath(inputMessage);
}
if (result.result === undefined) {
provider.set(
outputUri,
`// No results found. Took ${
getPrettyTime(result.metrics.timer_rego_query_eval_ns)
}. Used ${inputMessage} as input.`,
undefined,
);
} else {
let output: any;
if (result.result[0].bindings === undefined) {
output = result.result.map((x: any) => x.expressions.map((x: any) => x.value));
} else {
output = result.result.map((x: any) => x.bindings);
}
provider.set(
uri,
`// Found ${result.result.length} result${result.result.length === 1 ? "" : "s"} in ${
getPrettyTime(result.metrics.timer_rego_query_eval_ns)
} using ${inputMessage} as input.`,
output,
);
}
}
function activateCheckFile(context: vscode.ExtensionContext) {
const checkRegoFile = () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
const doc = editor.document;
// Only check rego files
if (doc.languageId === "rego") {
const args: string[] = ["check"];
ifInWorkspace(() => {
if (opa.canUseBundleFlags()) {
args.push("--bundle");
}
args.push(...opa.getRoots());
args.push(...opa.getSchemaParams());
}, () => {
args.push(doc.uri.fsPath);
});
if (opa.canUseStrictFlag()) {
args.push("--strict");
}
opa.runWithStatus(context, "opa", args, "", (_code: number, stderr: string, _stdout: string) => {
const output = stderr;
if (output.trim() !== "") {
opaOutputShowError(output);
} else {
opaOutputHide();
}
});
}
};
const checkRegoFileOnSave = () => {
if (checkOnSaveEnabled()) {
checkRegoFile();
}
};
const checkFileCommand = vscode.commands.registerCommand("opa.check.file", checkRegoFile);
// Need to use onWillSave instead of onDidSave because there's a weird race condition
// that causes the callback to get called twice when we prompt for installing OPA
vscode.workspace.onWillSaveTextDocument(checkRegoFileOnSave, null, context.subscriptions);
context.subscriptions.push(checkFileCommand);
}
function activateCoverWorkspace(context: vscode.ExtensionContext) {
const coverWorkspaceCommand = vscode.commands.registerCommand("opa.test.coverage.workspace", () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
for (const fileName in fileCoverage) {
if (editor.document.fileName.endsWith(fileName)) {
removeDecorations();
return;
}
}
fileCoverage = {};
const args: string[] = ["test", "--coverage", "--format", "json"];
ifInWorkspace(() => {
if (opa.canUseBundleFlags()) {
args.push("--bundle");
}
args.push(...opa.getRoots());
}, () => {
args.push(editor.document.uri.fsPath);
});
opa.run(context, "opa", args, "", (_, result) => {
opaOutputHide();
setFileCoverage(result);
showCoverageForWindow();
}, opaOutputShowError);
});
context.subscriptions.push(coverWorkspaceCommand);
}
function activateEvalPackage(context: vscode.ExtensionContext) {
const provider = new JSONProvider();
const registration = vscode.workspace.registerTextDocumentContentProvider(outputUri.scheme, provider);
const evalPackageCommand = vscode.commands.registerCommand(
"opa.eval.package",
onActiveWorkspaceEditor(outputUri, (editor: vscode.TextEditor, _inWorkspace: boolean) => {
opa.parse(context, "opa", opa.getDataDir(editor.document.uri), (pkg: string, _: string[]) => {
const { inputPath, args } = createOpaEvalArgs(editor, pkg);
args.push("--metrics");
opa.run(context, "opa", args, "data." + pkg, (stderr, result) => {
setEvalOutput(provider, outputUri, stderr, result, inputPath);
}, opaOutputShowError);
}, (error: string) => {
opaOutputShowError(error);
});
}),
);
context.subscriptions.push(evalPackageCommand, registration);
}
function activateEvalSelection(context: vscode.ExtensionContext) {
const provider = new JSONProvider();
const registration = vscode.workspace.registerTextDocumentContentProvider(outputUri.scheme, provider);
const evalSelectionCommand = vscode.commands.registerCommand(
"opa.eval.selection",
onActiveWorkspaceEditor(outputUri, (editor: vscode.TextEditor) => {
opa.parse(context, "opa", opa.getDataDir(editor.document.uri), (pkg: string, imports: string[]) => {
const { inputPath, args } = createOpaEvalArgs(editor, pkg, imports);
args.push("--metrics");
const text = editor.document.getText(editor.selection);
opa.run(context, "opa", args, text, (stderr, result) => {
setEvalOutput(provider, outputUri, stderr, result, inputPath);
}, opaOutputShowError);
}, (error: string) => {
opaOutputShowError(error);
});
}),
);
context.subscriptions.push(evalSelectionCommand, registration);
}
function activateEvalCoverage(context: vscode.ExtensionContext) {
const provider = new JSONProvider();
const registration = vscode.workspace.registerTextDocumentContentProvider(outputUri.scheme, provider);
const evalCoverageCommand = vscode.commands.registerCommand(
"opa.eval.coverage",
onActiveWorkspaceEditor(outputUri, (editor: vscode.TextEditor) => {
for (const fileName in fileCoverage) {
if (editor.document.fileName.endsWith(fileName)) {
removeDecorations();
return;
}
}
fileCoverage = {};
opa.parse(context, "opa", opa.getDataDir(editor.document.uri), (pkg: string, imports: string[]) => {
const { inputPath, args } = createOpaEvalArgs(editor, pkg, imports);
args.push("--metrics");
args.push("--coverage");
const text = editor.document.getText(editor.selection);
opa.run(context, "opa", args, text, (stderr, result) => {
setEvalOutput(provider, outputUri, stderr, result, inputPath);
setFileCoverage(result.coverage);
showCoverageForWindow();
}, opaOutputShowError);
}, (error: string) => {
opaOutputShowError(error);
});
}),
);
context.subscriptions.push(evalCoverageCommand, registration);
}
function activateTestWorkspace(context: vscode.ExtensionContext) {
const testWorkspaceCommand = vscode.commands.registerCommand("opa.test.workspace", () => {
opaOutputChannel.show(true);
opaOutputChannel.clear();
const args: string[] = ["test"];
args.push("--verbose");
ifInWorkspace(() => {
if (opa.canUseBundleFlags()) {
args.push("--bundle");
}
args.push(...opa.getRoots());
}, () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
args.push(editor.document.uri.fsPath);
});
opa.runWithStatus(context, "opa", args, "", (code: number, stderr: string, stdout: string) => {
if (code === 0 || code === 2) {
opaOutputChannel.append(stdout);
} else {
opaOutputShowError(stderr);
}
});
});
context.subscriptions.push(testWorkspaceCommand);
}
function activateTraceSelection(context: vscode.ExtensionContext) {
const traceSelectionCommand = vscode.commands.registerCommand("opa.trace.selection", () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
const text = editor.document.getText(editor.selection);
opa.parse(context, "opa", opa.getDataDir(editor.document.uri), (pkg: string, imports: string[]) => {
const { args } = createOpaEvalArgs(editor, pkg, imports);
args.push("--format", "pretty");
args.push("--explain", "full");
opa.runWithStatus(context, "opa", args, text, (code: number, stderr: string, stdout: string) => {
opaOutputChannel.show(true);
opaOutputChannel.clear();
if (code === 0 || code === 2) {
opaOutputChannel.append(stdout);
} else {
opaOutputShowError(stderr);
}
});
}, (error: string) => {
opaOutputShowError(error);
});
});
context.subscriptions.push(traceSelectionCommand);
}
function activateProfileSelection(context: vscode.ExtensionContext) {
const profileSelectionCommand = vscode.commands.registerCommand("opa.profile.selection", () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
const text = editor.document.getText(editor.selection);
opa.parse(context, "opa", opa.getDataDir(editor.document.uri), (pkg: string, imports: string[]) => {
opaOutputChannel.show(true);
opaOutputChannel.clear();
const { args } = createOpaEvalArgs(editor, pkg, imports);
args.push("--profile");
args.push("--format", "pretty");
opa.runWithStatus(context, "opa", args, text, (code: number, stderr: string, stdout: string) => {
if (code === 0 || code === 2) {
opaOutputChannel.append(stdout);
} else {
opaOutputShowError(stderr);
}
});
}, (error: string) => {
opaOutputShowError(error);
});
});
context.subscriptions.push(profileSelectionCommand);
}
function activatePartialSelection(context: vscode.ExtensionContext) {
const partialSelectionCommand = vscode.commands.registerCommand("opa.partial.selection", () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
const text = editor.document.getText(editor.selection);
opa.parse(context, "opa", opa.getDataDir(editor.document.uri), (pkg: string, imports: string[]) => {
const depsArgs = ["deps", "--format", "json"];
ifInWorkspace(() => {
depsArgs.push(...opa.getRootParams());
}, () => {
depsArgs.push("--data", editor.document.uri.fsPath);
});
depsArgs.push("data." + pkg);
opa.run(context, "opa", depsArgs, "", (_, result: any) => {
const refs = result.base.map((ref: any) => opa.refToString(ref));
refs.push("input");
vscode.window.showQuickPick(refs).then((selection: string | undefined) => {
if (selection !== undefined) {
opaOutputChannel.show(true);
opaOutputChannel.clear();
const { args } = createOpaEvalArgs(editor, pkg, imports);
args.push("--partial");
args.push("--format", "pretty");
args.push("--unknowns", selection);
opa.runWithStatus(context, "opa", args, text, (code: number, stderr: string, stdout: string) => {
if (code === 0 || code === 2) {
opaOutputChannel.append(stdout);
} else {
opaOutputShowError(stderr);
}
});
}
});
}, (msg) => {
opaOutputShowError(msg);
});
}, (error: string) => {
opaOutputShowError(error);
});
});
context.subscriptions.push(partialSelectionCommand);
}
function activateClearPromptsCommand(context: vscode.ExtensionContext) {
// this command is to allow users that have dismissed installation prompts from the plugin
// to re-enable them. While mostly intended for development, it could be useful for users
// who have dismissed a prompt and want to action it again. Clearing the global state is
// otherwise a more involved process.
const promptsClearCommand = vscode.commands.registerCommand("opa.prompts.clear", () => {
opaOutputChannel.appendLine("Clearing prompts");
context.globalState.keys().forEach((key) => {
if (key.startsWith("opa.prompts")) {
opaOutputChannel.appendLine(key);
context.globalState.update(key, undefined);
}
});
});
context.subscriptions.push(promptsClearCommand);
}
function onActiveWorkspaceEditor(
forURI: vscode.Uri,
cb: (editor: vscode.TextEditor, inWorkspace: boolean) => void,
): () => void {
return () => {
// Open the read-only document on the right most column. If no
// read-only document exists yet, create a new one. If one exists,
// re-use it.
vscode.workspace.openTextDocument(forURI)
.then(function(doc: any) {
const found = vscode.window.visibleTextEditors.find((ed: vscode.TextEditor) => {
return ed.document.uri === doc.uri;
});
if (found === undefined) {
return vscode.window.showTextDocument(doc, vscode.ViewColumn.Three, true);
}
return found;
});
// TODO(tsandall): test non-workspace mode. I don't know if this plugin
// will work if a single file is loaded. Certain features may not work
// but many can.
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showErrorMessage("No active editor");
return;
}
const inWorkspace = !!vscode.workspace.workspaceFolders;
cb(editor, !!inWorkspace);
};
}
let informAboutWorkspace = true;
const informAboutWorkspaceOption = "Don't show this tip again";
function ifInWorkspace(yes: () => void, no: () => void = () => {}) {
if (vscode.workspace.workspaceFolders) {
yes();
} else {
if (informAboutWorkspace) {
vscode.window.showInformationMessage(
"You're editing a single file. Open it inside a workspace to include "
+ "any relative modules and schemas in the OPA commands you run.",
informAboutWorkspaceOption,
).then((selection: string | undefined) => {
if (selection === informAboutWorkspaceOption) {
informAboutWorkspace = false;
}
});
}
no();
}
}
export function deactivate() {
}
function opaOutputShow(msg: string) {
opaOutputChannel.clear();
opaOutputChannel.append(msg);
opaOutputChannel.show(true);
}
function opaOutputShowError(error: string) {
opaOutputChannel.clear();
opaOutputChannel.append(formatErrors(error));
opaOutputChannel.show(true);
}
function opaOutputHide() {
opaOutputChannel.clear();
opaOutputChannel.hide();
}
function formatErrors(error: string): string {
try {
const output = JSON.parse(error);
let errors;
if (output.error !== undefined) {
if (!Array.isArray(output.error)) {
errors = [output.error];
} else {
errors = output.error;
}
} else if (output.errors !== undefined) {
errors = output.errors;
}
const msg = [];
for (let i = 0; i < errors.length; i++) {
let location_prefix;
if (errors[i].location.file !== "") {
location_prefix = `${errors[i].location.file}:${errors[i].location.row}`;
} else {
location_prefix = `<query>`;
}
msg.push(`${location_prefix}: ${errors[i].code}: ${errors[i].message}`);
}
return msg.join("\n");
} catch (_) {
return error;
}
}
function checkOnSaveEnabled() {
return vscode.workspace.getConfiguration("opa").get<boolean>("checkOnSave");
}
export function existsSync(path: string): boolean {
const parsed = vscode.Uri.parse(path);
if (parsed.scheme === "file") {
return fs.existsSync(parsed.fsPath);
}
return fs.existsSync(path);
}
export function getInputPath(): string {
// look for input.json at the active editor's directory, or the workspace directory
const activeDir = path.dirname(vscode.window.activeTextEditor!.document.uri.fsPath);
let parsed = vscode.Uri.file(activeDir);
// If we're in a workspace, and there is no sibling input.json to the actively edited file, look for the file in the workspace root
if (!!vscode.workspace.workspaceFolders && !fs.existsSync(path.join(activeDir, "input.json"))) {
parsed = vscode.workspace.workspaceFolders![0].uri;
}
// If the rootDir is a file:// URL then just append /input.json onto the
// end. Otherwise use the path.join function to get a platform-specific file
// path returned.
const rootDir = opa.getDataDir(parsed);
if (parsed.scheme === "file") {
return parsed.toString() + "/input.json";
}
return path.join(rootDir, "input.json");
}
function createOpaEvalArgs(
editor: vscode.TextEditor,
pkg: string,
imports: string[] = [],
): { inputPath: string; args: string[] } {
const args: string[] = ["eval"];
args.push("--stdin");
args.push("--package", pkg);
let inputPath = getInputPath();
if (existsSync(inputPath)) {
args.push("--input", inputPath);
} else {
inputPath = "";
}
imports.forEach((x: string) => {
args.push("--import", x);
});
ifInWorkspace(() => {
args.push(...opa.getRootParams());
args.push(...opa.getSchemaParams());
}, () => {
args.push("--data", editor.document.uri.fsPath);
});
return { inputPath, args };
}