Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
4 changes: 4 additions & 0 deletions src/WorkspaceContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { SwiftTaskProvider } from "./tasks/SwiftTaskProvider";
import { TaskManager } from "./tasks/TaskManager";
import { BuildFlags } from "./toolchain/BuildFlags";
import { SwiftToolchain } from "./toolchain/toolchain";
import { ProjectPanelProvider } from "./ui/ProjectPanelProvider";
import { StatusItem } from "./ui/StatusItem";
import { SwiftBuildStatus } from "./ui/SwiftBuildStatus";
import { isExcluded, isPathInsidePath } from "./utilities/filesystem";
Expand All @@ -60,6 +61,7 @@ export class WorkspaceContext implements vscode.Disposable {
public commentCompletionProvider: CommentCompletionProviders;
public documentation: DocumentationManager;
public testRunManager: TestRunManager;
public projectPanel: ProjectPanelProvider;
private lastFocusUri: vscode.Uri | undefined;
private initialisationFinished = false;

Expand Down Expand Up @@ -102,6 +104,7 @@ export class WorkspaceContext implements vscode.Disposable {
this.documentation = new DocumentationManager(extensionContext, this);
this.currentDocument = null;
this.commentCompletionProvider = new CommentCompletionProviders();
this.projectPanel = new ProjectPanelProvider(this);

const onChangeConfig = vscode.workspace.onDidChangeConfiguration(async event => {
// Clear build path cache when build-related configurations change
Expand Down Expand Up @@ -225,6 +228,7 @@ export class WorkspaceContext implements vscode.Disposable {
this.logger,
this.statusItem,
this.buildStatus,
this.projectPanel,
];
this.lastFocusUri = vscode.window.activeTextEditor?.document.uri;

Expand Down
9 changes: 9 additions & 0 deletions src/commands/dependencies/useLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,21 @@ export async function useLocalDependency(
currentFolder.toolchain
);

ctx.logger.debug(
`Placing dependency "${identifier}" in "editing" state with task: ${task.definition}`
);

const success = await executeTaskWithUI(
task,
`Use local version of ${identifier}`,
currentFolder,
true
);

ctx.logger.debug(
`Finished placing dependency "${identifier}" in "editing" state, success: ${success}`
);

if (success) {
await ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
}
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
8 changes: 3 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { SelectedXcodeWatcher } from "./toolchain/SelectedXcodeWatcher";
import { checkForSwiftlyInstallation } from "./toolchain/swiftly";
import { SwiftToolchain } from "./toolchain/toolchain";
import { LanguageStatusItems } from "./ui/LanguageStatusItems";
import { ProjectPanelProvider } from "./ui/ProjectPanelProvider";
import { getReadOnlyDocumentProvider } from "./ui/ReadOnlyDocumentProvider";
import { showToolchainError } from "./ui/ToolchainSelection";
import { checkAndWarnAboutWindowsSymlinks } from "./ui/win32";
Expand Down Expand Up @@ -144,14 +143,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<Api> {
);

// project panel provider
const projectPanelProvider = new ProjectPanelProvider(workspaceContext);
const dependenciesView = vscode.window.createTreeView("projectPanel", {
treeDataProvider: projectPanelProvider,
treeDataProvider: workspaceContext.projectPanel,
showCollapseAll: true,
});
projectPanelProvider.observeFolders(dependenciesView);
workspaceContext.projectPanel.observeFolders(dependenciesView);

context.subscriptions.push(dependenciesView, projectPanelProvider);
context.subscriptions.push(dependenciesView);

// observer that will resolve package and build launch configurations
context.subscriptions.push(workspaceContext.onDidChangeFolders(handleFolderEvent(logger)));
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
45 changes: 36 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 Expand Up @@ -493,6 +491,8 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {

dispose() {
this.workspaceObserver?.dispose();
this.disposables.forEach(d => d.dispose());
this.disposables.length = 0;
}

observeTasks(ctx: WorkspaceContext) {
Expand All @@ -502,11 +502,17 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {
vscode.tasks.onDidStartTask(e => {
const taskId = e.execution.task.detail ?? e.execution.task.name;
this.activeTasks.add(taskId);
this.workspaceContext.logger.info(
`Project panel updating after task ${taskId} has started`
);
this.didChangeTreeDataEmitter.fire();
}),
vscode.tasks.onDidEndTask(e => {
const taskId = e.execution.task.detail ?? e.execution.task.name;
this.activeTasks.delete(taskId);
this.workspaceContext.logger.info(
`Project panel updating after task ${taskId} has ended`
);
this.didChangeTreeDataEmitter.fire();
}),
ctx.onDidStartBuild(e => {
Expand All @@ -515,6 +521,7 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {
} else {
this.activeTasks.add(e.targetName);
}
this.workspaceContext.logger.info("Project panel updating after build has started");
this.didChangeTreeDataEmitter.fire();
}),
ctx.onDidFinishBuild(e => {
Expand All @@ -523,18 +530,25 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {
} else {
this.activeTasks.delete(e.targetName);
}
this.workspaceContext.logger.info(
"Project panel updating after build has finished"
);
this.didChangeTreeDataEmitter.fire();
}),
ctx.onDidStartTests(e => {
for (const target of e.targets) {
this.activeTasks.add(testTaskName(target));
}
this.workspaceContext.logger.info("Project panel updating on test run start");
this.didChangeTreeDataEmitter.fire();
}),
ctx.onDidFinishTests(e => {
for (const target of e.targets) {
this.activeTasks.delete(testTaskName(target));
}
this.workspaceContext.logger.info(
"Project panel updating after test run has finished"
);
this.didChangeTreeDataEmitter.fire();
})
);
Expand All @@ -545,6 +559,9 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {
e.affectsConfiguration("files.exclude") ||
e.affectsConfiguration("swift.excludePathsFromPackageDependencies")
) {
this.workspaceContext.logger.info(
"Project panel updating due to configuration changes"
);
this.didChangeTreeDataEmitter.fire();
}
})
Expand All @@ -561,10 +578,16 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {
}
this.watchBuildPluginOutputs(folder);
treeView.title = `Swift Project (${folder.name})`;
this.workspaceContext.logger.info(
`Project panel updating, focused folder ${folder.name}`
);
this.didChangeTreeDataEmitter.fire();
break;
case FolderOperation.unfocus:
treeView.title = `Swift Project`;
this.workspaceContext.logger.info(
`Project panel updating, unfocused folder`
);
this.didChangeTreeDataEmitter.fire();
break;
case FolderOperation.workspaceStateUpdated:
Expand All @@ -575,6 +598,9 @@ export class ProjectPanelProvider implements vscode.TreeDataProvider<TreeNode> {
return;
}
if (folder === this.workspaceContext.currentFolder) {
this.workspaceContext.logger.info(
`Project panel updating, "${operation}" for folder ${folder.name}`
);
this.didChangeTreeDataEmitter.fire();
}
}
Expand Down Expand Up @@ -825,6 +851,7 @@ class TaskPoller implements vscode.Disposable {
dispose() {
if (this.timeout) {
clearTimeout(this.timeout);
this.timeout = undefined;
}
}
}
Expand Down
Loading
Loading