Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 24 additions & 0 deletions assets/test/Swift-Markdown/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// swift-tools-version:5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
// FIXME: Can be changed back to Swift-Markdown when
// https://github.com/swiftlang/swift-package-manager/issues/7931
// is released in the toolchain
// NB: The name here needs to match the name of the dependencies under assets/test/dependencies/Package.swift
name: "swift-markdown",
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "PackageLib",
targets: ["PackageLib"]),
],
targets: [
.target(
name: "PackageLib",
dependencies: []
),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public let a = "B"
2 changes: 1 addition & 1 deletion assets/test/dependencies/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
targets: [
.executableTarget(
name: "dependencies",
dependencies: [],
dependencies: [.product(name: "PackageLib", package: "Swift-Markdown")],
path: "Sources"),
]
)
4 changes: 3 additions & 1 deletion assets/test/dependencies/Sources/main.swift
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import PackageLib

print("dependencies")
print("Test Asset:(dependencies)")
print(a)
20 changes: 14 additions & 6 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export enum Commands {
RUN = "swift.run",
DEBUG = "swift.debug",
CLEAN_BUILD = "swift.cleanBuild",
RESOLVE_DEPENDENCIES = "swift.resolveDependencies",
UPDATE_DEPENDENCIES = "swift.updateDependencies",
RUN_TESTS_MULTIPLE_TIMES = "swift.runTestsMultipleTimes",
RESET_PACKAGE = "swift.resetPackage",
USE_LOCAL_DEPENDENCY = "swift.useLocalDependency",
UNEDIT_DEPENDENCY = "swift.uneditDependency",
}

/**
Expand All @@ -76,14 +82,16 @@ export enum Commands {
export function register(ctx: WorkspaceContext): vscode.Disposable[] {
return [
vscode.commands.registerCommand("swift.newFile", uri => newSwiftFile(uri)),
vscode.commands.registerCommand("swift.resolveDependencies", () =>
vscode.commands.registerCommand(Commands.RESOLVE_DEPENDENCIES, () =>
resolveDependencies(ctx)
),
vscode.commands.registerCommand("swift.updateDependencies", () => updateDependencies(ctx)),
vscode.commands.registerCommand(Commands.UPDATE_DEPENDENCIES, () =>
updateDependencies(ctx)
),
vscode.commands.registerCommand(Commands.RUN, () => runBuild(ctx)),
vscode.commands.registerCommand(Commands.DEBUG, () => debugBuild(ctx)),
vscode.commands.registerCommand(Commands.CLEAN_BUILD, () => cleanBuild(ctx)),
vscode.commands.registerCommand("swift.runTestsMultipleTimes", item => {
vscode.commands.registerCommand(Commands.RUN_TESTS_MULTIPLE_TIMES, item => {
if (ctx.currentFolder) {
return runTestMultipleTimes(ctx.currentFolder, item, false);
}
Expand All @@ -95,7 +103,7 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
}),
// Note: This is only available on macOS (gated in `package.json`) because its the only OS that has the iOS SDK available.
vscode.commands.registerCommand("swift.switchPlatform", () => switchPlatform()),
vscode.commands.registerCommand("swift.resetPackage", () => resetPackage(ctx)),
vscode.commands.registerCommand(Commands.RESET_PACKAGE, () => resetPackage(ctx)),
vscode.commands.registerCommand("swift.runScript", () => runSwiftScript(ctx)),
vscode.commands.registerCommand("swift.openPackage", () => {
if (ctx.currentFolder) {
Expand All @@ -112,7 +120,7 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
vscode.commands.registerCommand("swift.insertFunctionComment", () =>
insertFunctionComment(ctx)
),
vscode.commands.registerCommand("swift.useLocalDependency", item => {
vscode.commands.registerCommand(Commands.USE_LOCAL_DEPENDENCY, item => {
if (item instanceof PackageNode) {
return useLocalDependency(item.name, ctx);
}
Expand All @@ -122,7 +130,7 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
return editDependency(item.name, ctx);
}
}),
vscode.commands.registerCommand("swift.uneditDependency", item => {
vscode.commands.registerCommand(Commands.UNEDIT_DEPENDENCY, item => {
if (item instanceof PackageNode) {
return uneditDependency(item.name, ctx);
}
Expand Down
5 changes: 4 additions & 1 deletion src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export async function folderCleanBuild(folderContext: FolderContext) {
/**
* Executes a {@link vscode.Task task} to debug swift target.
*/
async function debugBuildWithOptions(ctx: WorkspaceContext, options: vscode.DebugSessionOptions) {
export async function debugBuildWithOptions(
ctx: WorkspaceContext,
options: vscode.DebugSessionOptions
) {
const current = ctx.currentFolder;
if (!current) {
return;
Expand Down
6 changes: 4 additions & 2 deletions src/commands/dependencies/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import { executeTaskWithUI, updateAfterError } from "../utilities";
export async function resolveDependencies(ctx: WorkspaceContext) {
const current = ctx.currentFolder;
if (!current) {
return;
ctx.outputChannel.log("currentFolder is not set.");
return false;
}
await resolveFolderDependencies(current);
return await resolveFolderDependencies(current);
}

/**
Expand Down Expand Up @@ -57,4 +58,5 @@ export async function resolveFolderDependencies(
checkAlreadyRunning
);
updateAfterError(success, folderContext);
return success;
}
11 changes: 7 additions & 4 deletions src/commands/dependencies/unedit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import { FolderContext } from "../../FolderContext";
export async function uneditDependency(identifier: string, ctx: WorkspaceContext) {
const currentFolder = ctx.currentFolder;
if (!currentFolder) {
return;
ctx.outputChannel.log("currentFolder is not set.");
return false;
}
ctx.outputChannel.log(`unedit dependency ${identifier}`, currentFolder.name);
const status = `Reverting edited dependency ${identifier} (${currentFolder.name})`;
ctx.statusItem.showStatusWhileRunning(status, async () => {
await uneditFolderDependency(currentFolder, identifier, ctx);
return await ctx.statusItem.showStatusWhileRunning(status, async () => {
return await uneditFolderDependency(currentFolder, identifier, ctx);
});
}

Expand Down Expand Up @@ -67,6 +68,7 @@ async function uneditFolderDependency(
vscode.workspace.updateWorkspaceFolders(folderIndex, 1);
}
}
return true;
} catch (error) {
const execError = error as { stderr: string };
// if error contains "has uncommited changes" then ask if user wants to force the unedit
Expand All @@ -79,12 +81,13 @@ async function uneditFolderDependency(

if (result === "No") {
ctx.outputChannel.log(execError.stderr, folder.name);
return;
return false;
}
await uneditFolderDependency(folder, identifier, ctx, ["--force"]);
} else {
ctx.outputChannel.log(execError.stderr, folder.name);
vscode.window.showErrorMessage(`${execError.stderr}`);
}
return false;
}
}
11 changes: 6 additions & 5 deletions src/commands/dependencies/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import { executeTaskWithUI, updateAfterError } from "./../utilities";
export async function updateDependencies(ctx: WorkspaceContext) {
const current = ctx.currentFolder;
if (!current) {
return;
ctx.outputChannel.log("currentFolder is not set.");
return false;
}
await updateFolderDependencies(current);
return await updateFolderDependencies(current);
}

/**
Expand All @@ -46,7 +47,7 @@ export async function updateFolderDependencies(folderContext: FolderContext) {
folderContext.workspaceContext.toolchain
);

await executeTaskWithUI(task, "Updating Dependencies", folderContext).then(result => {
updateAfterError(result, folderContext);
});
const result = await executeTaskWithUI(task, "Updating Dependencies", folderContext);
updateAfterError(result, folderContext);
return result;
}
11 changes: 8 additions & 3 deletions src/commands/dependencies/useLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ import { executeTaskWithUI } from "../utilities";
* @param identifier Identifier for dependency
* @param ctx workspace context
*/
export async function useLocalDependency(identifier: string, ctx: WorkspaceContext) {
export async function useLocalDependency(
identifier: string,
ctx: WorkspaceContext
): Promise<boolean> {
const currentFolder = ctx.currentFolder;
if (!currentFolder) {
return;
ctx.outputChannel.log("currentFolder is not set.");
return false;
}
const folders = await vscode.window.showOpenDialog({
canSelectFiles: false,
Expand All @@ -39,7 +43,7 @@ export async function useLocalDependency(identifier: string, ctx: WorkspaceConte
});

if (!folders) {
return;
return false;
}
const folder = folders[0];
const task = createSwiftTask(
Expand All @@ -62,4 +66,5 @@ export async function useLocalDependency(identifier: string, ctx: WorkspaceConte
if (success) {
ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
}
return success;
}
46 changes: 28 additions & 18 deletions src/commands/resetPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function resetPackage(ctx: WorkspaceContext) {
if (!current) {
return;
}
await folderResetPackage(current);
return await folderResetPackage(current);
}

/**
Expand All @@ -47,22 +47,32 @@ export async function folderResetPackage(folderContext: FolderContext) {
folderContext.workspaceContext.toolchain
);

await executeTaskWithUI(task, "Reset Package", folderContext).then(async success => {
if (!success) {
return;
}
const resolveTask = createSwiftTask(
["package", "resolve"],
SwiftTaskProvider.resolvePackageName,
{
cwd: folderContext.folder,
scope: folderContext.workspaceFolder,
prefix: folderContext.name,
presentationOptions: { reveal: vscode.TaskRevealKind.Silent },
},
folderContext.workspaceContext.toolchain
);
return await executeTaskWithUI(task, "Reset Package", folderContext).then(
async success => {
if (!success) {
return false;
}
const resolveTask = createSwiftTask(
["package", "resolve"],
SwiftTaskProvider.resolvePackageName,
{
cwd: folderContext.folder,
scope: folderContext.workspaceFolder,
prefix: folderContext.name,
presentationOptions: { reveal: vscode.TaskRevealKind.Silent },
},
folderContext.workspaceContext.toolchain
);

await executeTaskWithUI(resolveTask, "Resolving Dependencies", folderContext);
});
const result = await executeTaskWithUI(
resolveTask,
"Resolving Dependencies",
folderContext
);
return result;
},
reason => {
return reason;
}
);
}
Loading