Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/soundness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ EOF
\( \! -path './assets/*' -a \
\( \! -path './coverage/*' -a \
\( \! -path './.husky/*' -a \
\( \! -path './src/typings/*' -a \
\( "${matching_files[@]}" \) \
\) \) \) \) \) \) \)
\) \) \) \) \) \) \) \) \)
} | while read -r line; do
if [[ "$(replace_acceptable_years < "$line" | head -n "$expected_lines" | shasum)" != "$expected_sha" ]]; then
printf "\033[0;31mmissing headers in file '%s'!\033[0m\n" "$line"
Expand Down
6 changes: 5 additions & 1 deletion src/BackgroundCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class BackgroundCompilation implements vscode.Disposable {
private workspaceFileWatcher?: vscode.FileSystemWatcher;
private configurationEventDisposable?: vscode.Disposable;
private disposables: vscode.Disposable[] = [];
private _disposed = false;

constructor(private folderContext: FolderContext) {
// We only want to configure the file watcher if background compilation is enabled.
Expand Down Expand Up @@ -59,7 +60,9 @@ export class BackgroundCompilation implements vscode.Disposable {
this.workspaceFileWatcher.onDidChange(
debounce(
() => {
void this.runTask();
if (!this._disposed) {
void this.runTask();
}
},
100 /* 10 times per second */,
{ trailing: true }
Expand All @@ -73,6 +76,7 @@ export class BackgroundCompilation implements vscode.Disposable {
}

dispose() {
this._disposed = true;
this.configurationEventDisposable?.dispose();
this.disposables.forEach(disposable => disposable.dispose());
}
Expand Down
1 change: 1 addition & 0 deletions src/FolderContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class FolderContext implements vscode.Disposable {
this.packageWatcher.dispose();
this.testExplorer?.dispose();
this.backgroundCompilation.dispose();
this.taskQueue.dispose();
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/debugger/buildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ export class TestingConfigurationFactory {
if (xcTestPath === undefined) {
return null;
}
const toolchain = this.ctx.toolchain;
return {
...baseConfig,
program: path.join(xcTestPath, "xctest"),
Expand All @@ -450,6 +451,16 @@ export class TestingConfigurationFactory {
env: {
...this.testEnv,
...this.sanitizerRuntimeEnvironment,
...(toolchain.swiftVersion.isGreaterThanOrEqual(
new Version(6, 2, 0)
)
? {
// Starting in 6.2 we need to provide libTesting.dylib for xctests
DYLD_FRAMEWORK_PATH:
toolchain.swiftTestingFrameworkPath(),
DYLD_LIBRARY_PATH: toolchain.swiftTestingLibraryPath(),
}
: {}),
SWIFT_TESTING_ENABLED: "0",
},
};
Expand Down
13 changes: 6 additions & 7 deletions src/debugger/debugAdapterFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ export class LLDBDebugConfigurationProvider implements vscode.DebugConfiguration
return undefined;
}
}
if (!(await this.promptForCodeLldbSettings(toolchain))) {
return undefined;
}

await this.promptForCodeLldbSettingsIfRequired(toolchain);

// Rename lldb-dap's "terminateCommands" to "preTerminateCommands" for CodeLLDB
if ("terminateCommands" in launchConfig) {
launchConfig["preTerminateCommands"] = launchConfig["terminateCommands"];
Expand Down Expand Up @@ -203,23 +203,23 @@ export class LLDBDebugConfigurationProvider implements vscode.DebugConfiguration
}
}

async promptForCodeLldbSettings(toolchain: SwiftToolchain): Promise<boolean> {
async promptForCodeLldbSettingsIfRequired(toolchain: SwiftToolchain) {
const libLldbPathResult = await getLLDBLibPath(toolchain);
if (!libLldbPathResult.success) {
const errorMessage = `Error: ${getErrorDescription(libLldbPathResult.failure)}`;
void vscode.window.showWarningMessage(
`Failed to setup CodeLLDB for debugging of Swift code. Debugging may produce unexpected results. ${errorMessage}`
);
this.logger.error(`Failed to setup CodeLLDB: ${errorMessage}`);
return true;
return;
}
const libLldbPath = libLldbPathResult.success;
const lldbConfig = vscode.workspace.getConfiguration("lldb");
if (
lldbConfig.get<string>("library") === libLldbPath &&
lldbConfig.get<string>("launch.expressions") === "native"
) {
return true;
return;
}
let userSelection: "Global" | "Workspace" | "Run Anyway" | undefined = undefined;
switch (configuration.debugger.setupCodeLLDB) {
Expand Down Expand Up @@ -272,7 +272,6 @@ export class LLDBDebugConfigurationProvider implements vscode.DebugConfiguration
);
break;
}
return true;
}

private convertEnvironmentVariables(map: { [key: string]: string }): string[] {
Expand Down
7 changes: 6 additions & 1 deletion src/tasks/TaskQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class QueuedOperation {
*
* Queue swift task operations to be executed serially
*/
export class TaskQueue {
export class TaskQueue implements vscode.Disposable {
queue: QueuedOperation[];
activeOperation?: QueuedOperation;
workspaceContext: WorkspaceContext;
Expand All @@ -176,6 +176,11 @@ export class TaskQueue {
this.disabled = false;
}

dispose() {
this.queue = [];
this.activeOperation = undefined;
}

/**
* Add operation to queue
* @param operation Operation to queue
Expand Down
16 changes: 7 additions & 9 deletions src/ui/ProjectPanelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,13 @@ export class PackageNode {
}

async getChildren(): Promise<TreeNode[]> {
const [childDeps, files] = await Promise.all([
this.childDependencies(this.dependency),
getChildren(
this.dependency.path,
excludedFilesForProjectPanelExplorer(),
this.id,
this.fs
),
]);
const childDeps = this.childDependencies(this.dependency);
const files = await getChildren(
this.dependency.path,
excludedFilesForProjectPanelExplorer(),
this.id,
this.fs
);
const childNodes = childDeps.map(
dep => new PackageNode(dep, this.childDependencies, this.id)
);
Expand Down
20 changes: 5 additions & 15 deletions test/integration-tests/FolderContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { activateExtensionForSuite, getRootWorkspaceFolder } from "./utilities/t

suite("FolderContext Error Handling Test Suite", () => {
let workspaceContext: WorkspaceContext;
let folderContext: FolderContext | undefined;
let swiftToolchainCreateStub: MockedFunction<typeof SwiftToolchain.create>;
const showToolchainError = mockGlobalValue(toolchain, "showToolchainError");

Expand All @@ -38,6 +39,7 @@ suite("FolderContext Error Handling Test Suite", () => {
});

afterEach(() => {
folderContext?.dispose();
restore();
});

Expand All @@ -52,11 +54,7 @@ suite("FolderContext Error Handling Test Suite", () => {
const workspaceFolder = getRootWorkspaceFolder();
const testFolder = testAssetUri("package2");

const folderContext = await FolderContext.create(
testFolder,
workspaceFolder,
workspaceContext
);
folderContext = await FolderContext.create(testFolder, workspaceFolder, workspaceContext);

assert.ok(folderContext, "FolderContext should be created despite toolchain failure");
assert.strictEqual(
Expand Down Expand Up @@ -99,11 +97,7 @@ suite("FolderContext Error Handling Test Suite", () => {
const showToolchainErrorStub = stub().resolves(true);
showToolchainError.setValue(showToolchainErrorStub);

const folderContext = await FolderContext.create(
testFolder,
workspaceFolder,
workspaceContext
);
folderContext = await FolderContext.create(testFolder, workspaceFolder, workspaceContext);

// Assert: FolderContext should be created successfully
assert.ok(folderContext, "FolderContext should be created after retry");
Expand Down Expand Up @@ -146,11 +140,7 @@ suite("FolderContext Error Handling Test Suite", () => {
const showToolchainErrorStub = stub().resolves(true);
showToolchainError.setValue(showToolchainErrorStub);

const folderContext = await FolderContext.create(
testFolder,
workspaceFolder,
workspaceContext
);
folderContext = await FolderContext.create(testFolder, workspaceFolder, workspaceContext);

assert.ok(
folderContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async function buildProject(ctx: WorkspaceContext, name: string) {
await waitForNoRunningTasks();
const folderContext = await folderInRootWorkspace(name, ctx);
const task = await createBuildAllTask(folderContext);
task.definition.dontTriggerTestDiscovery = true;
const { exitCode, output } = await executeTaskAndWaitForResult(task);
expect(exitCode, `${output}`).to.equal(0);
return folderContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ tag("medium").suite("SwiftPluginTaskProvider Test Suite", function () {
activateExtensionForSuite({
async setup(ctx) {
workspaceContext = ctx;
ctx.logger.info("Locating command-plugin folder in root workspace");
folderContext = await folderInRootWorkspace("command-plugin", workspaceContext);
ctx.logger.info(
"Located command-plugin folder in root workspace at " + folderContext.folder.fsPath
);
const logger = await ctx.loggerFactory.temp("SwiftPluginTaskProvider.tests");
ctx.logger.info("Loading swift plugins");
await folderContext.loadSwiftPlugins(logger);
ctx.logger.info(
"Finished loading swift plugins, captured logs should be empty: " + logger.logs
);
if (logger.logs.length > 0) {
expect.fail(
`Expected no output channel logs: ${JSON.stringify(logger.logs, undefined, 2)}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
activateExtensionForSuite,
folderInRootWorkspace,
updateSettings,
withLogging,
} from "../utilities/testutilities";
import {
assertContains,
Expand All @@ -60,19 +61,29 @@ tag("large").suite("Test Explorer Suite", function () {
activateExtensionForSuite({
async setup(ctx) {
workspaceContext = ctx;
folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext);
const logger = withLogging(ctx.logger);
folderContext = await logger("Locating defaultPackage folder in root workspace", () =>
folderInRootWorkspace("defaultPackage", workspaceContext)
);

if (!folderContext) {
throw new Error("Unable to find test explorer");
}

testExplorer = await folderContext.resolvedTestExplorer;
testExplorer = await logger(
"Waiting for test explorer to resolve",
() => folderContext.resolvedTestExplorer
);

await executeTaskAndWaitForResult(await createBuildAllTask(folderContext));
await logger("Executing build all task", async () =>
executeTaskAndWaitForResult(await createBuildAllTask(folderContext))
);

// Set up the listener before bringing the text explorer in to focus,
// which starts searching the workspace for tests.
await waitForTestExplorerReady(testExplorer);
await logger("Waiting for test explorer to be ready", () =>
waitForTestExplorerReady(testExplorer)
);
},
requiresLSP: true,
requiresDebugger: true,
Expand Down
Loading
Loading