Skip to content

Commit 3de9e1b

Browse files
authored
Nightly failure fixes (#1586)
* Capture promise before running command It times out after long wait so thinking there may be a timing issue here * Try match expression in case it's a equality issue * Try to do a better job of capturing further data after exit Inspiration from microsoft/vscode@9464b54 * Debug logging * Also check no floating thenables * Make command callbacks async * Fix failing test * See if using correct WorkspaceContext instance * More debug logging * Try to return instead of resolve * Specify expected arguments * Allow passing count as command parameter * Fix failing test * Debug logging * Run function directly * Make these unit tests Don't require activated extension to test these * Remove debug logging * Make sure debugger extensions are activated Only activate first time since never will deactivate * Only need one folder for this test * Remove more debug logging * Move to unit level * Fix review comment
1 parent c3dd31c commit 3de9e1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+314
-201
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
// TODO "@typescript-eslint/semi" rule moved to https://eslint.style
1515
"semi": "error",
1616
"no-console": "warn",
17-
"@typescript-eslint/no-floating-promises": "warn",
17+
"@typescript-eslint/no-floating-promises": ["warn", { "checkThenables": true }],
18+
"@typescript-eslint/await-thenable": "warn",
1819
// Mostly fails tests, ex. expect(...).to.be.true returns a Chai.Assertion
1920
"@typescript-eslint/no-unused-expressions": "off",
2021
"@typescript-eslint/no-non-null-assertion": "off",

scripts/check_package_json.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import { getExtensionVersion, main } from "./lib/utilities";
1717

18+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
1819
main(async () => {
1920
const version = await getExtensionVersion();
2021
if (version.minor % 2 !== 0) {

scripts/compile_icons.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function minifyIcon(icon: string, color: string = "#424242"): string {
5151
}).data;
5252
}
5353

54+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
5455
main(async () => {
5556
const iconsSourceDirectory = path.join(__dirname, "../src/icons");
5657
const iconAssetsDirectory = path.join(__dirname, "../assets/icons");

scripts/dev_package.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import { exec, getExtensionVersion, getRootDirectory, main } from "./lib/utilities";
1717

18+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
1819
main(async () => {
1920
const rootDirectory = getRootDirectory();
2021
const version = await getExtensionVersion();

scripts/download_vsix.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const repository = process.env["GITHUB_REPOSITORY"] || "swiftlang/vscode-swift";
3333
const owner = repository.split("/")[0];
3434
const repo = repository.split("/")[1];
3535

36+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
3637
(async function () {
3738
const octokit = new Octokit({
3839
auth: token,

scripts/preview_package.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function formatDate(date: Date): string {
2828
return year + month + day;
2929
}
3030

31+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
3132
main(async () => {
3233
const rootDirectory = getRootDirectory();
3334
const version = await getExtensionVersion();

scripts/update_swift_docc_render.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ async function cloneSwiftDocCRender(buildDirectory: string): Promise<string> {
5656
return swiftDocCRenderDirectory;
5757
}
5858

59+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
5960
main(async () => {
6061
const outputDirectory = path.join(getRootDirectory(), "assets", "swift-docc-render");
6162
if (process.argv.includes("postinstall")) {

src/FolderContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class FolderContext implements vscode.Disposable {
9393

9494
const error = await swiftPackage.error;
9595
if (error) {
96-
vscode.window.showErrorMessage(
96+
void vscode.window.showErrorMessage(
9797
`Failed to load ${folderContext.name}/Package.swift: ${error.message}`
9898
);
9999
workspaceContext.outputChannel.log(
@@ -179,7 +179,7 @@ export class FolderContext implements vscode.Disposable {
179179
/** Refresh the tests in the test explorer for this folder */
180180
refreshTestExplorer() {
181181
if (this.testExplorer?.controller.resolveHandler) {
182-
this.testExplorer.controller.resolveHandler(undefined);
182+
void this.testExplorer.controller.resolveHandler(undefined);
183183
}
184184
}
185185

src/TestExplorer/TestExplorer.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ export class TestExplorer {
204204
*/
205205
private updateSwiftTestContext() {
206206
const items = flattenTestItemCollection(this.controller.items).map(({ id }) => id);
207-
vscode.commands.executeCommand("setContext", "swift.tests", items);
207+
void vscode.commands.executeCommand("setContext", "swift.tests", items).then(() => {
208+
/* Put in worker queue */
209+
});
208210
}
209211

210212
/**
@@ -285,7 +287,7 @@ export class TestExplorer {
285287
const ok = "OK";
286288
const enable = "Enable SourceKit-LSP";
287289
if (firstTry && configuration.lsp.disable === true) {
288-
vscode.window
290+
void vscode.window
289291
.showInformationMessage(
290292
`swift-testing tests will not be detected since SourceKit-LSP
291293
has been disabled for this workspace.`,
@@ -297,9 +299,12 @@ export class TestExplorer {
297299
explorer.folderContext.workspaceContext.outputChannel.log(
298300
`Enabling SourceKit-LSP after swift-testing message`
299301
);
300-
vscode.workspace
302+
void vscode.workspace
301303
.getConfiguration("swift")
302-
.update("sourcekit-lsp.disable", false);
304+
.update("sourcekit-lsp.disable", false)
305+
.then(() => {
306+
/* Put in worker queue */
307+
});
303308
} else if (selected === ok) {
304309
explorer.folderContext.workspaceContext.outputChannel.log(
305310
`User acknowledged that SourceKit-LSP is disabled`

src/TestExplorer/TestRunner.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,7 @@ export class TestRunner {
10211021
"Test Debugging Cancelled",
10221022
this.folderContext.name
10231023
);
1024-
vscode.debug.stopDebugging(session);
1025-
resolve();
1024+
void vscode.debug.stopDebugging(session).then(() => resolve());
10261025
});
10271026
subscriptions.push(cancellation);
10281027
});
@@ -1051,11 +1050,9 @@ export class TestRunner {
10511050
// dispose terminate debug handler
10521051
subscriptions.forEach(sub => sub.dispose());
10531052

1054-
vscode.commands.executeCommand(
1055-
"workbench.view.extension.test"
1056-
);
1057-
1058-
resolve();
1053+
void vscode.commands
1054+
.executeCommand("workbench.view.extension.test")
1055+
.then(() => resolve());
10591056
});
10601057
subscriptions.push(terminateSession);
10611058
} else {

src/WorkspaceContext.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class WorkspaceContext implements vscode.Disposable {
9292
if (!(await this.needToAutoGenerateLaunchConfig())) {
9393
return;
9494
}
95-
vscode.window
95+
void vscode.window
9696
.showInformationMessage(
9797
`Launch configurations need to be updated after changing the Swift runtime path. Custom versions of environment variable '${swiftLibraryPathKey()}' may be overridden. Do you want to update?`,
9898
"Update",
@@ -111,7 +111,7 @@ export class WorkspaceContext implements vscode.Disposable {
111111
if (!(await this.needToAutoGenerateLaunchConfig())) {
112112
return;
113113
}
114-
vscode.window
114+
void vscode.window
115115
.showInformationMessage(
116116
`Launch configurations need to be updated after changing the Swift build path. Do you want to update?`,
117117
"Update",
@@ -154,7 +154,11 @@ export class WorkspaceContext implements vscode.Disposable {
154154
event.exitCode !== undefined &&
155155
configuration.actionAfterBuildError === "Focus Problems"
156156
) {
157-
vscode.commands.executeCommand("workbench.panel.markers.view.focus");
157+
void vscode.commands
158+
.executeCommand("workbench.panel.markers.view.focus")
159+
.then(() => {
160+
/* Put in worker queue */
161+
});
158162
}
159163
});
160164
const swiftFileWatcher = vscode.workspace.createFileSystemWatcher("**/*.swift");

src/commands.ts

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -106,75 +106,98 @@ export enum Commands {
106106
*/
107107
export function register(ctx: WorkspaceContext): vscode.Disposable[] {
108108
return [
109-
vscode.commands.registerCommand("swift.generateLaunchConfigurations", () =>
110-
generateLaunchConfigurations(ctx)
109+
vscode.commands.registerCommand(
110+
"swift.generateLaunchConfigurations",
111+
async () => await generateLaunchConfigurations(ctx)
111112
),
112-
vscode.commands.registerCommand("swift.newFile", uri => newSwiftFile(uri)),
113-
vscode.commands.registerCommand(Commands.RESOLVE_DEPENDENCIES, () =>
114-
resolveDependencies(ctx)
113+
vscode.commands.registerCommand("swift.newFile", async uri => await newSwiftFile(uri)),
114+
vscode.commands.registerCommand(
115+
Commands.RESOLVE_DEPENDENCIES,
116+
async () => await resolveDependencies(ctx)
115117
),
116-
vscode.commands.registerCommand(Commands.UPDATE_DEPENDENCIES, () =>
117-
updateDependencies(ctx)
118+
vscode.commands.registerCommand(
119+
Commands.UPDATE_DEPENDENCIES,
120+
async () => await updateDependencies(ctx)
118121
),
119-
vscode.commands.registerCommand(Commands.RUN, target =>
120-
runBuild(ctx, ...unwrapTreeItem(target))
122+
vscode.commands.registerCommand(
123+
Commands.RUN,
124+
async target => await runBuild(ctx, ...unwrapTreeItem(target))
121125
),
122-
vscode.commands.registerCommand(Commands.DEBUG, target =>
123-
debugBuild(ctx, ...unwrapTreeItem(target))
126+
vscode.commands.registerCommand(
127+
Commands.DEBUG,
128+
async target => await debugBuild(ctx, ...unwrapTreeItem(target))
124129
),
125-
vscode.commands.registerCommand(Commands.CLEAN_BUILD, () => cleanBuild(ctx)),
126-
vscode.commands.registerCommand(Commands.RUN_TESTS_MULTIPLE_TIMES, item => {
130+
vscode.commands.registerCommand(Commands.CLEAN_BUILD, async () => await cleanBuild(ctx)),
131+
vscode.commands.registerCommand(Commands.RUN_TESTS_MULTIPLE_TIMES, async (item, count) => {
127132
if (ctx.currentFolder) {
128-
return runTestMultipleTimes(ctx.currentFolder, item, false);
133+
return await runTestMultipleTimes(ctx.currentFolder, item, false, count);
129134
}
130135
}),
131-
vscode.commands.registerCommand("swift.runTestsUntilFailure", item => {
136+
vscode.commands.registerCommand("swift.runTestsUntilFailure", async (item, count) => {
132137
if (ctx.currentFolder) {
133-
return runTestMultipleTimes(ctx.currentFolder, item, true);
138+
return await runTestMultipleTimes(ctx.currentFolder, item, true, count);
134139
}
135140
}),
136141
// Note: switchPlatform is only available on macOS and Swift 6.1 or later
137142
// (gated in `package.json`) because it's the only OS and toolchain combination that
138143
// has Darwin SDKs available and supports code editing with SourceKit-LSP
139-
vscode.commands.registerCommand("swift.switchPlatform", () => switchPlatform(ctx)),
140-
vscode.commands.registerCommand(Commands.RESET_PACKAGE, () => resetPackage(ctx)),
141-
vscode.commands.registerCommand("swift.runScript", () => runSwiftScript(ctx)),
142-
vscode.commands.registerCommand("swift.openPackage", () => {
144+
vscode.commands.registerCommand(
145+
"swift.switchPlatform",
146+
async () => await switchPlatform(ctx)
147+
),
148+
vscode.commands.registerCommand(
149+
Commands.RESET_PACKAGE,
150+
async () => await resetPackage(ctx)
151+
),
152+
vscode.commands.registerCommand("swift.runScript", async () => await runSwiftScript(ctx)),
153+
vscode.commands.registerCommand("swift.openPackage", async () => {
143154
if (ctx.currentFolder) {
144-
return openPackage(ctx.currentFolder.swiftVersion, ctx.currentFolder.folder);
155+
return await openPackage(ctx.currentFolder.swiftVersion, ctx.currentFolder.folder);
145156
}
146157
}),
147-
vscode.commands.registerCommand(Commands.RUN_SNIPPET, target =>
148-
runSnippet(ctx, ...unwrapTreeItem(target))
158+
vscode.commands.registerCommand(
159+
Commands.RUN_SNIPPET,
160+
async target => await runSnippet(ctx, ...unwrapTreeItem(target))
149161
),
150-
vscode.commands.registerCommand(Commands.DEBUG_SNIPPET, target =>
151-
debugSnippet(ctx, ...unwrapTreeItem(target))
162+
vscode.commands.registerCommand(
163+
Commands.DEBUG_SNIPPET,
164+
async target => await debugSnippet(ctx, ...unwrapTreeItem(target))
165+
),
166+
vscode.commands.registerCommand(
167+
Commands.RUN_PLUGIN_TASK,
168+
async () => await runPluginTask()
169+
),
170+
vscode.commands.registerCommand(Commands.RUN_TASK, async name => await runTask(ctx, name)),
171+
vscode.commands.registerCommand(
172+
Commands.RESTART_LSP,
173+
async () => await restartLSPServer(ctx)
152174
),
153-
vscode.commands.registerCommand(Commands.RUN_PLUGIN_TASK, () => runPluginTask()),
154-
vscode.commands.registerCommand(Commands.RUN_TASK, name => runTask(ctx, name)),
155-
vscode.commands.registerCommand(Commands.RESTART_LSP, () => restartLSPServer(ctx)),
156-
vscode.commands.registerCommand("swift.reindexProject", () => reindexProject(ctx)),
157-
vscode.commands.registerCommand("swift.insertFunctionComment", () =>
158-
insertFunctionComment(ctx)
175+
vscode.commands.registerCommand(
176+
"swift.reindexProject",
177+
async () => await reindexProject(ctx)
178+
),
179+
vscode.commands.registerCommand(
180+
"swift.insertFunctionComment",
181+
async () => await insertFunctionComment(ctx)
159182
),
160-
vscode.commands.registerCommand(Commands.USE_LOCAL_DEPENDENCY, (item, dep) => {
183+
vscode.commands.registerCommand(Commands.USE_LOCAL_DEPENDENCY, async (item, dep) => {
161184
if (item instanceof PackageNode) {
162-
return useLocalDependency(item.name, ctx, dep);
185+
return await useLocalDependency(item.name, ctx, dep);
163186
}
164187
}),
165-
vscode.commands.registerCommand("swift.editDependency", item => {
188+
vscode.commands.registerCommand("swift.editDependency", async item => {
166189
if (item instanceof PackageNode) {
167-
return editDependency(item.name, ctx);
190+
return await editDependency(item.name, ctx);
168191
}
169192
}),
170-
vscode.commands.registerCommand(Commands.UNEDIT_DEPENDENCY, item => {
193+
vscode.commands.registerCommand(Commands.UNEDIT_DEPENDENCY, async item => {
171194
if (item instanceof PackageNode) {
172-
return uneditDependency(item.name, ctx);
195+
return await uneditDependency(item.name, ctx);
173196
}
174197
}),
175-
vscode.commands.registerCommand("swift.openInWorkspace", item => {
198+
vscode.commands.registerCommand("swift.openInWorkspace", async item => {
176199
if (item instanceof PackageNode) {
177-
return openInWorkspace(item);
200+
return await openInWorkspace(item);
178201
}
179202
}),
180203
vscode.commands.registerCommand("swift.openExternal", item => {
@@ -186,7 +209,10 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
186209
vscode.commands.registerCommand("swift.clearDiagnosticsCollection", () =>
187210
ctx.diagnostics.clear()
188211
),
189-
vscode.commands.registerCommand("swift.captureDiagnostics", () => captureDiagnostics(ctx)),
212+
vscode.commands.registerCommand(
213+
"swift.captureDiagnostics",
214+
async () => await captureDiagnostics(ctx)
215+
),
190216
vscode.commands.registerCommand(
191217
Commands.RUN_ALL_TESTS_PARALLEL,
192218
async item => await runAllTests(ctx, TestKind.parallel, ...unwrapTreeItem(item))
@@ -216,9 +242,9 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
216242
vscode.commands.registerCommand("swift.openEducationalNote", uri =>
217243
openEducationalNote(uri)
218244
),
219-
vscode.commands.registerCommand(Commands.OPEN_MANIFEST, (uri: vscode.Uri) => {
245+
vscode.commands.registerCommand(Commands.OPEN_MANIFEST, async (uri: vscode.Uri) => {
220246
const packagePath = path.join(uri.fsPath, "Package.swift");
221-
vscode.commands.executeCommand("vscode.open", vscode.Uri.file(packagePath));
247+
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(packagePath));
222248
}),
223249
vscode.commands.registerCommand("swift.openDocumentation", () => openDocumentation()),
224250
];

src/commands/captureDiagnostics.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export async function captureDiagnostics(
7676
await showCapturedDiagnosticsResults(diagnosticsDir);
7777
}
7878
} catch (error) {
79-
vscode.window.showErrorMessage(`Unable to capture diagnostic logs: ${error}`);
79+
void vscode.window.showErrorMessage(`Unable to capture diagnostic logs: ${error}`);
8080
}
8181
}
8282

@@ -149,12 +149,12 @@ async function showCapturedDiagnosticsResults(diagnosticsDir: string) {
149149
copyPath
150150
);
151151
if (result === copyPath) {
152-
vscode.env.clipboard.writeText(diagnosticsDir);
152+
await vscode.env.clipboard.writeText(diagnosticsDir);
153153
} else if (result === showInFinderButton) {
154154
exec(showDirectoryCommand(diagnosticsDir), error => {
155155
// Opening the explorer on windows returns an exit code of 1 despite opening successfully.
156156
if (error && process.platform !== "win32") {
157-
vscode.window.showErrorMessage(
157+
void vscode.window.showErrorMessage(
158158
`Failed to open ${showCommandType()}: ${error.message}`
159159
);
160160
}

src/commands/createNewProject.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function createNewProject(toolchain: SwiftToolchain | undefined): P
3838
// activated. As such, we also have to allow this command to run when no workspace is
3939
// active. Show an error to the user if the command is unavailable.
4040
if (!toolchain.swiftVersion.isGreaterThanOrEqual(new Version(5, 8, 0))) {
41-
vscode.window.showErrorMessage(
41+
void vscode.window.showErrorMessage(
4242
"Creating a new swift project is only available starting in swift version 5.8.0."
4343
);
4444
return;
@@ -180,6 +180,6 @@ export async function createNewProject(toolchain: SwiftToolchain | undefined): P
180180
});
181181
} else if (action === "addToWorkspace") {
182182
const index = vscode.workspace.workspaceFolders?.length ?? 0;
183-
await vscode.workspace.updateWorkspaceFolders(index, 0, { uri: projectUri });
183+
vscode.workspace.updateWorkspaceFolders(index, 0, { uri: projectUri });
184184
}
185185
}

src/commands/dependencies/unedit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async function uneditFolderDependency(
9191
await uneditFolderDependency(folder, identifier, ctx, ["--force"]);
9292
} else {
9393
ctx.outputChannel.log(execError.stderr, folder.name);
94-
vscode.window.showErrorMessage(`${execError.stderr}`);
94+
void vscode.window.showErrorMessage(`${execError.stderr}`);
9595
}
9696
return false;
9797
}

src/commands/newFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function newSwiftFile(
4444
await vscode.languages.setTextDocumentLanguage(document, "swift");
4545
await vscode.window.showTextDocument(document);
4646
} catch (err) {
47-
vscode.window.showErrorMessage(`Failed to create ${targetUri.fsPath}`);
47+
void vscode.window.showErrorMessage(`Failed to create ${targetUri.fsPath}`);
4848
}
4949
} else {
5050
// If no path is supplied then open an untitled editor w/ Swift language type

src/commands/openInExternalEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { PackageNode } from "../ui/ProjectPanelProvider";
2222
export function openInExternalEditor(packageNode: PackageNode) {
2323
try {
2424
const uri = vscode.Uri.parse(packageNode.location, true);
25-
vscode.env.openExternal(uri);
25+
void vscode.env.openExternal(uri);
2626
} catch {
2727
// ignore error
2828
}

0 commit comments

Comments
 (0)