Skip to content

Commit

Permalink
refactor: Apply fixes from code review to debug functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Nov 4, 2022
1 parent 03d085f commit f94baca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
26 changes: 15 additions & 11 deletions src/debugger/scalaDebugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,13 @@ export function initialize(outputChannel: vscode.OutputChannel): Disposable[] {
];
}

function isScalaRunMain(
lenses: DebugDiscoveryParams | ScalaCodeLensesParams
): lenses is ScalaRunMain {
return Object.prototype.hasOwnProperty.call(lenses, "data");
}

function isExtendedScalaRunMain(
runMain: DebugDiscoveryParams | ScalaCodeLensesParams
runMain: ScalaCodeLensesParams
): runMain is ExtendedScalaRunMain {
return isScalaRunMain(runMain) && runMain.data.shellCommand != undefined;
return (
runMain.dataKind === "scala-main-class" &&
runMain.data.shellCommand != undefined
);
}

async function runMain(main: ExtendedScalaRunMain): Promise<boolean> {
Expand All @@ -80,9 +77,16 @@ async function runMain(main: ExtendedScalaRunMain): Promise<boolean> {
return Promise.resolve(false);
}

export async function startDiscovery(
noDebug: boolean,
debugParams: DebugDiscoveryParams
): Promise<boolean> {
return debug(noDebug, debugParams);
}

export async function start(
noDebug: boolean,
debugParams: DebugDiscoveryParams | ScalaCodeLensesParams
debugParams: ScalaCodeLensesParams
): Promise<boolean> {
if (noDebug && isExtendedScalaRunMain(debugParams)) {
return runMain(debugParams);
Expand All @@ -91,7 +95,7 @@ export async function start(
}
}

export async function debug(
async function debug(
noDebug: boolean,
debugParams: DebugDiscoveryParams | ScalaCodeLensesParams
): Promise<boolean> {
Expand Down Expand Up @@ -131,7 +135,7 @@ class ScalaMainConfigProvider implements vscode.DebugConfigurationProvider {
path: editor.document.uri.toString(true),
runType: RunType.RunOrTestFile,
};
await start(debugConfiguration.noDebug, args);
await startDiscovery(debugConfiguration.noDebug, args);
return debugConfiguration;
} else {
return debugConfiguration;
Expand Down
18 changes: 16 additions & 2 deletions src/debugger/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BuildTargetIdentifier } from "../types";
import { BuildTargetIdentifier, FullyQualifiedClassName } from "../types";

export interface OldScalaMainData {
class: string;
Expand Down Expand Up @@ -48,4 +48,18 @@ export interface ScalaTestSuiteSelection {
tests: string[];
}

export type ScalaCodeLensesParams = ScalaRunMain | ScalaTestSuites;
interface ScalaRunTestSuites {
data: FullyQualifiedClassName[];
dataKind: "scala-test-suite";
targets: BuildTargetIdentifier[];
}

interface ScalaRunTestSuitesSelection {
data: ScalaTestSuites[];
dataKind: "scala-test-suites-selection";
targets: BuildTargetIdentifier[];
}

type ScalaRunTests = ScalaRunTestSuites | ScalaRunTestSuitesSelection;

export type ScalaCodeLensesParams = ScalaRunMain | ScalaRunTests;
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ function launchMetals(
path: editor.document.uri.toString(true),
runType: RunType.RunOrTestFile,
};
scalaDebugger.start(true, args).then((wasStarted) => {
scalaDebugger.startDiscovery(true, args).then((wasStarted) => {
if (!wasStarted) {
window.showErrorMessage("Debug session not started");
}
Expand All @@ -720,7 +720,7 @@ function launchMetals(
path: editor.document.uri.toString(true),
runType: RunType.TestTarget,
};
scalaDebugger.start(true, args).then((wasStarted) => {
scalaDebugger.startDiscovery(true, args).then((wasStarted) => {
if (!wasStarted) {
window.showErrorMessage("Debug session not started");
}
Expand Down

0 comments on commit f94baca

Please sign in to comment.