Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ To run and debug your Aspire application, add an entry to the workspace `launch.
|---------|-------------|
| C# | project |
| Python | python |
| Java | java |

The debuggers property stores common debug configuration properties for different types of Aspire services.
C#-based services have common debugging properties under `project`. Python-based services have their common properties under `python`.
Expand All @@ -71,6 +72,12 @@ There is also a special entry for the apphost (`apphost`). For example:
}
```

Available configuration options for each debugger type can be found in the corresponding extension's documentation:

- [C# debugger options](https://code.visualstudio.com/docs/csharp/debugging#_configuration-options)
- [Python debugger options](https://code.visualstudio.com/docs/python/debugging#_set-configuration-options)
- [Java debugger options](https://code.visualstudio.com/docs/java/java-debugging#_configuration-options)

## Requirements

- The [Aspire CLI](https://learn.microsoft.com/en-us/dotnet/aspire/cli/install) must be installed and available on the path.
Expand Down
9 changes: 9 additions & 0 deletions extension/src/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export function isPythonInstalled() {
return isExtensionInstalled("ms-python.python");
}

export function isJavaInstalled() {
return isExtensionInstalled("vscjava.vscode-java-pack");
}

export function getSupportedCapabilities(): string[] {
const capabilities = ['prompting', 'baseline.v1', 'secret-prompts.v1'];

Expand All @@ -37,6 +41,11 @@ export function getSupportedCapabilities(): string[] {
capabilities.push("ms-python.python");
}

if (isJavaInstalled()) {
capabilities.push("java");
capabilities.push("vscjava.vscode-java-pack");
}

return capabilities;
}

Expand Down
10 changes: 10 additions & 0 deletions extension/src/dcp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ export function isPythonLaunchConfiguration(obj: any): obj is PythonLaunchConfig
return obj && obj.type === 'python';
}

export interface JavaLaunchConfiguration extends ExecutableLaunchConfiguration {
type: "java";
main_class_path?: string;
project_path?: string;
}

export function isJavaLaunchConfiguration(obj: any): obj is JavaLaunchConfiguration {
return obj && obj.type === 'java';
}

export interface EnvVar {
name: string;
value: string;
Expand Down
7 changes: 6 additions & 1 deletion extension/src/debugger/debuggerExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { debugProject, runProject } from "../loc/strings";
import { mergeEnvs } from "../utils/environment";
import { extensionLogOutputChannel } from "../utils/logging";
import { projectDebuggerExtension } from "./languages/dotnet";
import { isCsharpInstalled, isPythonInstalled } from "../capabilities";
import { isCsharpInstalled, isJavaInstalled, isPythonInstalled } from "../capabilities";
import { pythonDebuggerExtension } from "./languages/python";
import { javaDebuggerExtension } from "./languages/java";

// Represents a resource-specific debugger extension for when the default session configuration is not sufficient to launch the resource.
export interface ResourceDebuggerExtension {
Expand Down Expand Up @@ -72,6 +73,10 @@ export function getResourceDebuggerExtensions(): ResourceDebuggerExtension[] {
extensions.push(pythonDebuggerExtension);
}

if (isJavaInstalled()) {
extensions.push(javaDebuggerExtension);
}

return extensions;
}

20 changes: 20 additions & 0 deletions extension/src/debugger/languages/java.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { isJavaLaunchConfiguration } from "../../dcp/types";
import { invalidLaunchConfiguration } from "../../loc/strings";
import { ResourceDebuggerExtension } from "../debuggerExtensions";

export const javaDebuggerExtension: ResourceDebuggerExtension = {
resourceType: 'java',
debugAdapter: 'java',
extensionId: 'vscjava.vscode-java-pack',
displayName: 'Java',
getProjectFile: (launchConfig) => {
if (isJavaLaunchConfiguration(launchConfig)) {
const programPath = launchConfig.main_class_path || launchConfig.project_path;
if (programPath) {
return programPath;
}
}

throw new Error(invalidLaunchConfiguration(JSON.stringify(launchConfig)));
}
};
65 changes: 65 additions & 0 deletions extension/src/test/javaDebugger.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as assert from 'assert';
import { javaDebuggerExtension } from '../debugger/languages/java';
import { JavaLaunchConfiguration } from '../dcp/types';

suite('Java Debugger Extension Tests', () => {
test('getProjectFile returns main_class_path when provided', () => {
const mainClassPath = '/path/to/MainClass.java';
const launchConfig: JavaLaunchConfiguration = {
type: 'java',
main_class_path: mainClassPath,
project_path: '/path/to/project'
};

const result = javaDebuggerExtension.getProjectFile(launchConfig);

assert.strictEqual(result, mainClassPath);
});

test('getProjectFile returns project_path when main_class_path is not provided', () => {
const projectPath = '/path/to/project';
const launchConfig: JavaLaunchConfiguration = {
type: 'java',
project_path: projectPath
};

const result = javaDebuggerExtension.getProjectFile(launchConfig);

assert.strictEqual(result, projectPath);
});

test('getProjectFile throws error when neither main_class_path nor project_path is provided', () => {
const launchConfig: JavaLaunchConfiguration = {
type: 'java'
};

assert.throws(
() => javaDebuggerExtension.getProjectFile(launchConfig)
);
});

test('getProjectFile prefers main_class_path over project_path when both are provided', () => {
const mainClassPath = '/path/to/MainClass.java';
const projectPath = '/path/to/project';
const launchConfig: JavaLaunchConfiguration = {
type: 'java',
main_class_path: mainClassPath,
project_path: projectPath
};

const result = javaDebuggerExtension.getProjectFile(launchConfig);

assert.strictEqual(result, mainClassPath);
});

test('getProjectFile throws error when launch configuration is not Java type', () => {
const launchConfig = {
type: 'python',
program_path: '/path/to/program.py'
};

assert.throws(
() => javaDebuggerExtension.getProjectFile(launchConfig as any)
);
});
});
Loading