Skip to content

Commit 7829093

Browse files
authored
Expand test logging during extension activation/deactivation (#1869)
* Expand test logging during extension activation/deactivation Provide more robust logs during extension activation/deactivation in order to help track down test timeouts. These logs are only printed if a test fails to avoid cluttering up the test report.
1 parent 1ba88bf commit 7829093

25 files changed

+498
-121
lines changed

.vscode-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const launchArgs = [
4444
"--disable-gpu",
4545
"--disable-gpu-sandbox",
4646
"--disable-chromium-sandbox",
47+
"--disable-extension=vscode.git",
4748
"--no-xshm",
4849
];
4950
if (dataDir) {

scripts/soundness.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ EOF
103103
\( \! -path './assets/*' -a \
104104
\( \! -path './coverage/*' -a \
105105
\( \! -path './.husky/*' -a \
106+
\( \! -path './src/typings/*' -a \
106107
\( "${matching_files[@]}" \) \
107-
\) \) \) \) \) \) \)
108+
\) \) \) \) \) \) \) \) \)
108109
} | while read -r line; do
109110
if [[ "$(replace_acceptable_years < "$line" | head -n "$expected_lines" | shasum)" != "$expected_sha" ]]; then
110111
printf "\033[0;31mmissing headers in file '%s'!\033[0m\n" "$line"

src/BackgroundCompilation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class BackgroundCompilation implements vscode.Disposable {
2626
private workspaceFileWatcher?: vscode.FileSystemWatcher;
2727
private configurationEventDisposable?: vscode.Disposable;
2828
private disposables: vscode.Disposable[] = [];
29+
private _disposed = false;
2930

3031
constructor(private folderContext: FolderContext) {
3132
// We only want to configure the file watcher if background compilation is enabled.
@@ -59,7 +60,9 @@ export class BackgroundCompilation implements vscode.Disposable {
5960
this.workspaceFileWatcher.onDidChange(
6061
debounce(
6162
() => {
62-
void this.runTask();
63+
if (!this._disposed) {
64+
void this.runTask();
65+
}
6366
},
6467
100 /* 10 times per second */,
6568
{ trailing: true }
@@ -73,6 +76,7 @@ export class BackgroundCompilation implements vscode.Disposable {
7376
}
7477

7578
dispose() {
79+
this._disposed = true;
7680
this.configurationEventDisposable?.dispose();
7781
this.disposables.forEach(disposable => disposable.dispose());
7882
}

src/FolderContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class FolderContext implements vscode.Disposable {
7070
this.packageWatcher.dispose();
7171
this.testExplorer?.dispose();
7272
this.backgroundCompilation.dispose();
73+
this.taskQueue.dispose();
7374
}
7475

7576
/**

src/PackageWatcher.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ export class PackageWatcher {
108108
watcher.onDidDelete(async () => await this.handleWorkspaceStateChange());
109109

110110
if (await fileExists(uri.fsPath)) {
111+
// TODO: Remove this
112+
this.logger.info("Loading initial workspace-state.json");
111113
await this.handleWorkspaceStateChange();
112114
}
113115

@@ -193,6 +195,10 @@ export class PackageWatcher {
193195
*/
194196
private async handleWorkspaceStateChange() {
195197
await this.folderContext.reloadWorkspaceState();
198+
// TODO: Remove this
199+
this.logger.info(
200+
`Package watcher state updated workspace-state.json: ${JSON.stringify(this.folderContext.swiftPackage.workspaceState, null, 2)}`
201+
);
196202
await this.folderContext.fireEvent(FolderOperation.workspaceStateUpdated);
197203
}
198204
}

src/SwiftPackage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ export class SwiftPackage {
204204
readonly folder: vscode.Uri,
205205
private contentsPromise: Promise<SwiftPackageState>,
206206
public resolved: PackageResolved | undefined,
207-
private workspaceState: WorkspaceState | undefined
207+
// TODO: Make private again
208+
public workspaceState: WorkspaceState | undefined
208209
) {}
209210

210211
/**

src/WorkspaceContext.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { SwiftTaskProvider } from "./tasks/SwiftTaskProvider";
3434
import { TaskManager } from "./tasks/TaskManager";
3535
import { BuildFlags } from "./toolchain/BuildFlags";
3636
import { SwiftToolchain } from "./toolchain/toolchain";
37+
import { ProjectPanelProvider } from "./ui/ProjectPanelProvider";
3738
import { StatusItem } from "./ui/StatusItem";
3839
import { SwiftBuildStatus } from "./ui/SwiftBuildStatus";
3940
import { isExcluded, isPathInsidePath } from "./utilities/filesystem";
@@ -60,6 +61,7 @@ export class WorkspaceContext implements vscode.Disposable {
6061
public commentCompletionProvider: CommentCompletionProviders;
6162
public documentation: DocumentationManager;
6263
public testRunManager: TestRunManager;
64+
public projectPanel: ProjectPanelProvider;
6365
private lastFocusUri: vscode.Uri | undefined;
6466
private initialisationFinished = false;
6567

@@ -102,6 +104,7 @@ export class WorkspaceContext implements vscode.Disposable {
102104
this.documentation = new DocumentationManager(extensionContext, this);
103105
this.currentDocument = null;
104106
this.commentCompletionProvider = new CommentCompletionProviders();
107+
this.projectPanel = new ProjectPanelProvider(this);
105108

106109
const onChangeConfig = vscode.workspace.onDidChangeConfiguration(async event => {
107110
// Clear build path cache when build-related configurations change
@@ -225,6 +228,7 @@ export class WorkspaceContext implements vscode.Disposable {
225228
this.logger,
226229
this.statusItem,
227230
this.buildStatus,
231+
this.projectPanel,
228232
];
229233
this.lastFocusUri = vscode.window.activeTextEditor?.document.uri;
230234

@@ -463,7 +467,7 @@ export class WorkspaceContext implements vscode.Disposable {
463467
// find context with root folder
464468
const index = this.folders.findIndex(context => context.folder.fsPath === folder.fsPath);
465469
if (index !== -1) {
466-
this.logger.warn(`Adding package folder ${folder} twice`);
470+
this.logger.warn(`Adding package folder ${folder} twice: ${Error().stack}`);
467471
return this.folders[index];
468472
}
469473
const folderContext = await FolderContext.create(folder, workspaceFolder, this);

src/commands/dependencies/useLocal.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,21 @@ export async function useLocalDependency(
6767
currentFolder.toolchain
6868
);
6969

70+
ctx.logger.debug(
71+
`Placing dependency "${identifier}" in "editing" state with task: ${task.definition}`
72+
);
73+
7074
const success = await executeTaskWithUI(
7175
task,
7276
`Use local version of ${identifier}`,
7377
currentFolder,
7478
true
7579
);
80+
81+
ctx.logger.debug(
82+
`Finished placing dependency "${identifier}" in "editing" state, success: ${success}`
83+
);
84+
7685
if (success) {
7786
await ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
7887
}

src/debugger/buildConfig.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ export class TestingConfigurationFactory {
441441
if (xcTestPath === undefined) {
442442
return null;
443443
}
444+
const toolchain = this.ctx.toolchain;
444445
return {
445446
...baseConfig,
446447
program: path.join(xcTestPath, "xctest"),
@@ -450,6 +451,16 @@ export class TestingConfigurationFactory {
450451
env: {
451452
...this.testEnv,
452453
...this.sanitizerRuntimeEnvironment,
454+
...(toolchain.swiftVersion.isGreaterThanOrEqual(
455+
new Version(6, 2, 0)
456+
)
457+
? {
458+
// Starting in 6.2 we need to provide libTesting.dylib for xctests
459+
DYLD_FRAMEWORK_PATH:
460+
toolchain.swiftTestingFrameworkPath(),
461+
DYLD_LIBRARY_PATH: toolchain.swiftTestingLibraryPath(),
462+
}
463+
: {}),
453464
SWIFT_TESTING_ENABLED: "0",
454465
},
455466
};

src/debugger/debugAdapterFactory.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ export class LLDBDebugConfigurationProvider implements vscode.DebugConfiguration
148148
return undefined;
149149
}
150150
}
151-
if (!(await this.promptForCodeLldbSettings(toolchain))) {
152-
return undefined;
153-
}
151+
152+
await this.promptForCodeLldbSettingsIfRequired(toolchain);
153+
154154
// Rename lldb-dap's "terminateCommands" to "preTerminateCommands" for CodeLLDB
155155
if ("terminateCommands" in launchConfig) {
156156
launchConfig["preTerminateCommands"] = launchConfig["terminateCommands"];
@@ -203,23 +203,23 @@ export class LLDBDebugConfigurationProvider implements vscode.DebugConfiguration
203203
}
204204
}
205205

206-
async promptForCodeLldbSettings(toolchain: SwiftToolchain): Promise<boolean> {
206+
async promptForCodeLldbSettingsIfRequired(toolchain: SwiftToolchain) {
207207
const libLldbPathResult = await getLLDBLibPath(toolchain);
208208
if (!libLldbPathResult.success) {
209209
const errorMessage = `Error: ${getErrorDescription(libLldbPathResult.failure)}`;
210210
void vscode.window.showWarningMessage(
211211
`Failed to setup CodeLLDB for debugging of Swift code. Debugging may produce unexpected results. ${errorMessage}`
212212
);
213213
this.logger.error(`Failed to setup CodeLLDB: ${errorMessage}`);
214-
return true;
214+
return;
215215
}
216216
const libLldbPath = libLldbPathResult.success;
217217
const lldbConfig = vscode.workspace.getConfiguration("lldb");
218218
if (
219219
lldbConfig.get<string>("library") === libLldbPath &&
220220
lldbConfig.get<string>("launch.expressions") === "native"
221221
) {
222-
return true;
222+
return;
223223
}
224224
let userSelection: "Global" | "Workspace" | "Run Anyway" | undefined = undefined;
225225
switch (configuration.debugger.setupCodeLLDB) {
@@ -272,7 +272,6 @@ export class LLDBDebugConfigurationProvider implements vscode.DebugConfiguration
272272
);
273273
break;
274274
}
275-
return true;
276275
}
277276

278277
private convertEnvironmentVariables(map: { [key: string]: string }): string[] {

0 commit comments

Comments
 (0)