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

Inferring input.json location for debug workspace launcher #262

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
10 changes: 10 additions & 0 deletions src/da/activate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from "vscode";

import { existsSync, getInputPath } from "../extension";
import { regalPath } from "./../ls/clients/regal";
import { promptForUpdateRegal } from "./../ls/clients/regal";
import * as opa from "./../opa";
Expand All @@ -13,13 +14,22 @@ export function activateDebugger(context: vscode.ExtensionContext) {
if (!targetResource && vscode.window.activeTextEditor) {
targetResource = vscode.window.activeTextEditor.document.uri;
}

// Only add the inputPath if the file exists
let inputPath: string | undefined = getInputPath();
if (!existsSync(inputPath)) {
inputPath = undefined;
}

if (targetResource) {
vscode.debug.startDebugging(undefined, {
type: "opa-debug",
name: "Debug Workspace",
request: "launch",
command: "eval",
query: "data",
inputPath: inputPath,
stopOnEntry: true,
enablePrint: true,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ function checkOnSaveEnabled() {
return vscode.workspace.getConfiguration("opa").get<boolean>("checkOnSave");
}

function existsSync(path: string): boolean {
export function existsSync(path: string): boolean {
const parsed = vscode.Uri.parse(path);

if (parsed.scheme === "file") {
Expand All @@ -695,7 +695,7 @@ function existsSync(path: string): boolean {
return fs.existsSync(path);
}

function getInputPath(): string {
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);
Expand Down