Skip to content

Commit e2ffe6d

Browse files
committed
Add binaryManager test + update vitest
1 parent 0e4a760 commit e2ffe6d

10 files changed

+1632
-799
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@
336336
"@types/ws": "^8.18.1",
337337
"@typescript-eslint/eslint-plugin": "^7.0.0",
338338
"@typescript-eslint/parser": "^6.21.0",
339+
"@vitest/coverage-v8": "^3.2.4",
339340
"@vscode/test-cli": "^0.0.10",
340341
"@vscode/test-electron": "^2.5.2",
341342
"@vscode/vsce": "^3.6.0",
@@ -355,7 +356,7 @@
355356
"ts-loader": "^9.5.1",
356357
"typescript": "^5.8.3",
357358
"utf-8-validate": "^6.0.5",
358-
"vitest": "^0.34.6",
359+
"vitest": "^3.2.4",
359360
"vscode-test": "^1.5.0",
360361
"webpack": "^5.99.6",
361362
"webpack-cli": "^5.1.4"

src/core/binaryManager.adapters.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import * as vscode from "vscode";
2+
import {
3+
ConfigurationProvider,
4+
ProgressReporter,
5+
UserInteraction,
6+
} from "./binaryManager.interfaces";
7+
8+
/**
9+
* VS Code implementation of ConfigurationProvider
10+
*/
11+
export class VSCodeConfigurationProvider implements ConfigurationProvider {
12+
get<T>(key: string): T | undefined;
13+
get<T>(key: string, defaultValue: T): T;
14+
get<T>(key: string, defaultValue?: T): T | undefined {
15+
const config = vscode.workspace.getConfiguration();
16+
return defaultValue !== undefined
17+
? config.get(key, defaultValue)
18+
: config.get(key);
19+
}
20+
}
21+
22+
/**
23+
* VS Code implementation of ProgressReporter
24+
*/
25+
export class VSCodeProgressReporter implements ProgressReporter {
26+
async withProgress<T>(
27+
title: string,
28+
operation: (
29+
progress: {
30+
report: (value: { message?: string; increment?: number }) => void;
31+
},
32+
cancellationToken: {
33+
onCancellationRequested: (listener: () => void) => void;
34+
},
35+
) => Promise<T>,
36+
): Promise<T> {
37+
return vscode.window.withProgress(
38+
{
39+
location: vscode.ProgressLocation.Notification,
40+
title,
41+
cancellable: true,
42+
},
43+
operation,
44+
);
45+
}
46+
}
47+
48+
/**
49+
* VS Code implementation of UserInteraction
50+
*/
51+
export class VSCodeUserInteraction implements UserInteraction {
52+
async showErrorMessage(
53+
message: string,
54+
options?: { detail?: string; modal?: boolean; useCustom?: boolean },
55+
...items: string[]
56+
): Promise<string | undefined> {
57+
return vscode.window.showErrorMessage(message, options || {}, ...items);
58+
}
59+
60+
async showWarningMessage(
61+
message: string,
62+
options?: { detail?: string; modal?: boolean; useCustom?: boolean },
63+
...items: string[]
64+
): Promise<string | undefined> {
65+
return vscode.window.showWarningMessage(message, options || {}, ...items);
66+
}
67+
68+
async openExternal(url: string): Promise<void> {
69+
await vscode.env.openExternal(vscode.Uri.parse(url));
70+
}
71+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Provides access to configuration settings
3+
*/
4+
export interface ConfigurationProvider {
5+
get<T>(key: string): T | undefined;
6+
get<T>(key: string, defaultValue: T): T;
7+
}
8+
9+
/**
10+
* Provides progress reporting capabilities for long-running operations
11+
*/
12+
export interface ProgressReporter {
13+
/**
14+
* Reports progress for a download operation with cancellation support
15+
* @param title The title to display for the progress
16+
* @param operation The operation to run with progress reporting
17+
* @returns Promise that resolves to true if completed, false if cancelled
18+
*/
19+
withProgress<T>(
20+
title: string,
21+
operation: (
22+
progress: {
23+
report: (value: { message?: string; increment?: number }) => void;
24+
},
25+
cancellationToken: {
26+
onCancellationRequested: (listener: () => void) => void;
27+
},
28+
) => Promise<T>,
29+
): Promise<T>;
30+
}
31+
32+
/**
33+
* User interaction capabilities for showing dialogs and opening external URLs
34+
*/
35+
export interface UserInteraction {
36+
/**
37+
* Shows an error message with optional action buttons
38+
* @param message The message to display
39+
* @param options Additional options for the dialog
40+
* @param items Action button labels
41+
* @returns Promise that resolves to the selected action or undefined
42+
*/
43+
showErrorMessage(
44+
message: string,
45+
options?: { detail?: string; modal?: boolean; useCustom?: boolean },
46+
...items: string[]
47+
): Promise<string | undefined>;
48+
49+
/**
50+
* Shows a warning message with optional action buttons
51+
* @param message The message to display
52+
* @param options Additional options for the dialog
53+
* @param items Action button labels
54+
* @returns Promise that resolves to the selected action or undefined
55+
*/
56+
showWarningMessage(
57+
message: string,
58+
options?: { detail?: string; modal?: boolean; useCustom?: boolean },
59+
...items: string[]
60+
): Promise<string | undefined>;
61+
62+
/**
63+
* Opens an external URL
64+
* @param url The URL to open
65+
* @returns Promise that resolves when the URL is opened
66+
*/
67+
openExternal(url: string): Promise<void>;
68+
}

0 commit comments

Comments
 (0)