Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit 965934f

Browse files
committed
Use public extension API to fetch the current client workspace
It seems that we do not share that on Windows the same way we do on the other platforms, so make sure to go through the 'blessed' way of fetching the public API that's returned by extension's `activate` function. This should fix tests on all platforms.
1 parent ad59173 commit 965934f

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

test/suite/extension.test.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,25 @@ import * as vscode from 'vscode';
55
import { Disposable, Uri } from 'vscode';
66

77
import * as extension from '../../src/extension';
8+
import { Observable } from '../../src/utils/observable';
89

910
const fixtureDir = path.resolve(
1011
path.join(__dirname, '..', '..', '..', 'fixtures'),
1112
);
1213

1314
suite('Extension Tests', () => {
1415
test('cargo tasks are auto-detected', async () => {
16+
// Activate manually to ease the access to internal, exported APIs without
17+
// having to open any file before
18+
const ext = vscode.extensions.getExtension<extension.Api>(
19+
'rust-lang.rust',
20+
)!;
21+
const { activeWorkspace } = await ext.activate();
22+
1523
const projects = [
1624
path.join(fixtureDir, 'bare-lib-project'),
1725
path.join(fixtureDir, 'another-lib-project'),
18-
];
26+
].map(path => Uri.file(path).fsPath);
1927

2028
const expected = [
2129
{ subcommand: 'build', group: vscode.TaskGroup.Build, cwd: projects[0] },
@@ -26,10 +34,9 @@ suite('Extension Tests', () => {
2634
{ subcommand: 'run', group: undefined },
2735
];
2836

29-
const whenWorkspacesActive = projects.map(path => {
30-
const fsPath = Uri.file(path).fsPath;
31-
return whenWorkspaceActive(fsPath);
32-
});
37+
const whenWorkspacesActive = projects.map(path =>
38+
whenWorkspaceActive(activeWorkspace, path),
39+
);
3340

3441
// This makes sure that we set the focus on the opened files (which is what
3542
// actually triggers the extension for the project)
@@ -89,11 +96,12 @@ async function currentTasksInclude(
8996
* @param fsPath normalized file system path of a URI
9097
*/
9198
function whenWorkspaceActive(
99+
observable: Observable<extension.ClientWorkspace | null>,
92100
fsPath: string,
93101
): Promise<extension.ClientWorkspace> {
94102
return new Promise(resolve => {
95103
let disposable: Disposable | undefined;
96-
disposable = extension.activeWorkspace.observe(value => {
104+
disposable = observable.observe(value => {
97105
if (value && value.folder.uri.fsPath === fsPath) {
98106
if (disposable) {
99107
disposable.dispose();

0 commit comments

Comments
 (0)