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

Commit c6b3b72

Browse files
authored
Merge pull request #785 from rust-lang/fix-ci-tests
Fix the current test harness
2 parents 6314bff + 9e0854b commit c6b3b72

File tree

6 files changed

+219
-58
lines changed

6 files changed

+219
-58
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"runtimeExecutable": "${execPath}",
2525
"args": [
2626
"--extensionDevelopmentPath=${workspaceFolder}",
27-
"--extensionTestsPath=${workspaceFolder}/out/test"
27+
"--extensionTestsPath=${workspaceFolder}/out/test/suite",
28+
"${workspaceFolder}/fixtures"
2829
],
2930
"outFiles": [
3031
"${workspaceFolder}/out/test/**/*.js"

package-lock.json

Lines changed: 73 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,20 @@
5353
"vscode-languageclient": "^4.3.0"
5454
},
5555
"devDependencies": {
56+
"@types/chai": "^4.2.11",
5657
"@types/glob": "^7.1.1",
5758
"@types/mocha": "^5.2.6",
5859
"@types/node": "^10.10",
5960
"@types/vscode": "^1.31.0",
61+
"chai": "^4.2.0",
6062
"glob": "^7.1.4",
6163
"mocha": "^6.2.3",
6264
"prettier": "^1.16.4",
6365
"tslint": "^5.14.0",
6466
"tslint-config-prettier": "^1.18.0",
6567
"typescript": "^3.0.0",
6668
"vsce": "^1.63.0",
67-
"vscode-test": "^0.4.3"
69+
"vscode-test": "^1.3.0"
6870
},
6971
"contributes": {
7072
"languages": [

src/extension.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ interface ProgressParams {
4545
done?: boolean;
4646
}
4747

48-
export async function activate(context: ExtensionContext) {
48+
/**
49+
* External API as exposed by the extension. Can be queried by other extensions
50+
* or by the integration test runner for VSCode extensions.
51+
*/
52+
export interface Api {
53+
activeWorkspace: typeof activeWorkspace;
54+
}
55+
56+
export async function activate(context: ExtensionContext): Promise<Api> {
4957
context.subscriptions.push(
5058
...[
5159
configureLanguage(),
@@ -84,6 +92,8 @@ export async function activate(context: ExtensionContext) {
8492
return;
8593
});
8694
}
95+
96+
return { activeWorkspace };
8797
}
8898

8999
export async function deactivate() {
@@ -106,7 +116,7 @@ function onDidChangeActiveTextEditor(editor: TextEditor | undefined) {
106116
return;
107117
}
108118

109-
activeWorkspace = workspace;
119+
activeWorkspace.value = workspace;
110120

111121
const updateProgress = (progress: WorkspaceProgress) => {
112122
if (progress.state === 'progress') {
@@ -121,9 +131,9 @@ function onDidChangeActiveTextEditor(editor: TextEditor | undefined) {
121131
if (progressObserver) {
122132
progressObserver.dispose();
123133
}
124-
progressObserver = activeWorkspace.progress.observe(updateProgress);
134+
progressObserver = workspace.progress.observe(updateProgress);
125135
// Update UI ourselves immediately and don't wait for value update callbacks
126-
updateProgress(activeWorkspace.progress.value);
136+
updateProgress(workspace.progress.value);
127137
}
128138

129139
function whenChangingWorkspaceFolders(e: WorkspaceFoldersChangeEvent) {
@@ -176,7 +186,7 @@ type WorkspaceProgress =
176186
// We run one RLS and one corresponding language client per workspace folder
177187
// (VSCode workspace, not Cargo workspace). This class contains all the per-client
178188
// and per-workspace stuff.
179-
class ClientWorkspace {
189+
export class ClientWorkspace {
180190
public readonly folder: WorkspaceFolder;
181191
// FIXME(#233): Don't only rely on lazily initializing it once on startup,
182192
// handle possible `rust-client.*` value changes while extension is running
@@ -440,7 +450,7 @@ class ClientWorkspace {
440450
* Tracks the most current VSCode workspace as opened by the user. Used by the
441451
* commands to know in which workspace these should be executed.
442452
*/
443-
let activeWorkspace: ClientWorkspace | null;
453+
const activeWorkspace = new Observable<ClientWorkspace | null>(null);
444454

445455
/**
446456
* Registers the VSCode [commands] used by the extension.
@@ -451,23 +461,24 @@ function registerCommands(): Disposable[] {
451461
return [
452462
commands.registerCommand(
453463
'rls.update',
454-
() => activeWorkspace && activeWorkspace.rustupUpdate(),
464+
() => activeWorkspace.value && activeWorkspace.value.rustupUpdate(),
455465
),
456466
commands.registerCommand(
457467
'rls.restart',
458-
async () => activeWorkspace && activeWorkspace.restart(),
468+
async () => activeWorkspace.value && activeWorkspace.value.restart(),
459469
),
460470
commands.registerCommand(
461471
'rls.run',
462-
(cmd: Execution) => activeWorkspace && activeWorkspace.runRlsCommand(cmd),
472+
(cmd: Execution) =>
473+
activeWorkspace.value && activeWorkspace.value.runRlsCommand(cmd),
463474
),
464475
commands.registerCommand(
465476
'rls.start',
466-
() => activeWorkspace && activeWorkspace.start(),
477+
() => activeWorkspace.value && activeWorkspace.value.start(),
467478
),
468479
commands.registerCommand(
469480
'rls.stop',
470-
() => activeWorkspace && activeWorkspace.stop(),
481+
() => activeWorkspace.value && activeWorkspace.value.stop(),
471482
),
472483
];
473484
}

test/runTest.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ import * as path from 'path';
33
import { runTests } from 'vscode-test';
44

55
(async () => {
6-
const extensionPath = path.resolve(__dirname, '../../');
7-
const testRunnerPath = path.resolve(__dirname, './suite');
6+
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
7+
const extensionTestsPath = path.resolve(__dirname, './suite');
88

99
await runTests({
10-
extensionPath,
11-
testRunnerPath,
10+
extensionDevelopmentPath,
11+
extensionTestsPath,
12+
launchArgs: [
13+
'--disable-extensions',
14+
// Already start in the fixtures dir because we lose debugger connection
15+
// once we re-open a different folder due to window reloading
16+
path.join(extensionDevelopmentPath, 'fixtures'),
17+
],
18+
}).catch(() => {
19+
console.error(`Test run failed`);
20+
process.exit(1);
1221
});
1322
})();

0 commit comments

Comments
 (0)