Skip to content
Draft
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
9 changes: 2 additions & 7 deletions src/TestExplorer/TestExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,8 @@ export class TestExplorer {
return;
}

// get list of tests from `swift test --list-tests`
let listTestArguments: string[];
if (toolchain.swiftVersion.isGreaterThanOrEqual(new Version(5, 8, 0))) {
listTestArguments = ["test", "list", "--skip-build"];
} else {
listTestArguments = ["test", "--list-tests", "--skip-build"];
}
// get list of tests from `swift test list --skip-build`
let listTestArguments: string[] = ["test", "list", "--skip-build"];
listTestArguments = [...listTestArguments, ...testBuildOptions];
const listTestsOperation = new SwiftExecOperation(
listTestArguments,
Expand Down
11 changes: 0 additions & 11 deletions src/commands/createNewProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { SwiftProjectTemplate, SwiftToolchain } from "../toolchain/toolchain";
import { showToolchainError } from "../ui/ToolchainSelection";
import { withDelayedProgress } from "../ui/withDelayedProgress";
import { execSwift } from "../utilities/utilities";
import { Version } from "../utilities/version";

/**
* Prompts the user to input project details and then executes `swift package init`
Expand All @@ -34,16 +33,6 @@ export async function createNewProject(toolchain: SwiftToolchain | undefined): P
return;
}

// The context key `swift.createNewProjectAvailable` only works if the extension has been
// activated. As such, we also have to allow this command to run when no workspace is
// active. Show an error to the user if the command is unavailable.
if (!toolchain.swiftVersion.isGreaterThanOrEqual(new Version(5, 8, 0))) {
void vscode.window.showErrorMessage(
"Creating a new swift project is only available starting in swift version 5.8.0."
);
return;
}

// Prompt the user for the type of project they would like to create
const availableProjectTemplates = await toolchain.getProjectTemplates();
const selectedProjectTemplate = await vscode.window.showQuickPick<
Expand Down
4 changes: 1 addition & 3 deletions src/contextKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ export function createContextKeys(): ContextKeys {

return {
updateKeysBasedOnActiveVersion(toolchainVersion: Version) {
this.createNewProjectAvailable = toolchainVersion.isGreaterThanOrEqual(
new Version(5, 8, 0)
);
this.createNewProjectAvailable = true;
this.switchPlatformAvailable =
process.platform === "darwin"
? toolchainVersion.isGreaterThanOrEqual(new Version(6, 1, 0))
Expand Down
70 changes: 0 additions & 70 deletions src/debugger/buildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
import * as fs from "fs/promises";
import * as os from "os";
import * as path from "path";
import * as vscode from "vscode";

Expand Down Expand Up @@ -79,10 +78,6 @@ export class BuildConfigurationFactory {

/** flag for enabling test discovery */
private testDiscoveryFlag(ctx: FolderContext): string[] {
// Test discovery is only available in SwiftPM 5.1 and later.
if (ctx.swiftVersion.isLessThan(new Version(5, 1, 0))) {
return [];
}
// Test discovery is always enabled on Darwin.
if (process.platform !== "darwin") {
const hasLinuxMain = ctx.linuxMain.exists;
Expand Down Expand Up @@ -427,17 +422,6 @@ export class TestingConfigurationFactory {
},
};
default:
const swiftVersion = this.ctx.toolchain.swiftVersion;
if (
swiftVersion.isLessThan(new Version(5, 7, 0)) &&
swiftVersion.isGreaterThanOrEqual(new Version(5, 6, 0)) &&
process.platform === "darwin"
) {
// if debugging on macOS with Swift 5.6 we need to create a custom launch
// configuration so we can set the system architecture
return await this.createDarwin56TestConfiguration();
}

let xcTestArgs = [
"test",
...(this.testKind === TestKind.coverage
Expand Down Expand Up @@ -477,60 +461,6 @@ export class TestingConfigurationFactory {
}
/* eslint-enable no-case-declarations */

/**
* Return custom Darwin test configuration that works with Swift 5.6
**/
private async createDarwin56TestConfiguration(): Promise<vscode.DebugConfiguration | null> {
if ((await this.ctx.swiftPackage.getTargets(TargetType.test)).length === 0) {
return null;
}

let testFilterArg: string;
const testList = this.testList.join(",");
if (testList.length > 0) {
testFilterArg = `-XCTest ${testList}`;
} else {
testFilterArg = "";
}

const { folder, nameSuffix } = getFolderAndNameSuffix(this.ctx, true);
// On macOS, find the path to xctest
// and point it at the .xctest bundle from the configured build directory.
const xctestPath = this.ctx.toolchain.xcTestPath;
if (xctestPath === undefined) {
return null;
}
let arch: string;
switch (os.arch()) {
case "x64":
arch = "x86_64";
break;
case "arm64":
arch = "arm64e";
break;
default:
return null;
}
const sanitizer = this.ctx.toolchain.sanitizer(configuration.sanitizer);
const envCommands = Object.entries({
...swiftRuntimeEnv(),
...configuration.folder(this.ctx.workspaceFolder).testEnvironmentVariables,
...sanitizer?.runtimeEnvironment,
}).map(([key, value]) => `settings set target.env-vars ${key}="${value}"`);

return {
type: SWIFT_LAUNCH_CONFIG_TYPE,
request: "custom",
name: `Test ${await this.ctx.swiftPackage.name}`,
targetCreateCommands: [`file -a ${arch} ${xctestPath}/xctest`],
processCreateCommands: [
...envCommands,
`process launch -w ${folder} -- ${testFilterArg} ${this.xcTestOutputPath()}`,
],
preLaunchTask: `swift: Build All${nameSuffix}`,
};
}

private addSwiftTestingFlagsArgs(args: string[]): string[] {
if (!this.swiftTestingArguments) {
throw new Error(
Expand Down
20 changes: 0 additions & 20 deletions src/sourcekit-lsp/LanguageClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { SourceKitLogMessageNotification, SourceKitLogMessageParams } from "./ex
import { DidChangeActiveDocumentNotification } from "./extensions/DidChangeActiveDocumentRequest";
import { PollIndexRequest, WorkspaceSynchronizeRequest } from "./extensions/PollIndexRequest";
import { activateGetReferenceDocument } from "./getReferenceDocument";
import { activateLegacyInlayHints } from "./inlayHints";
import { activatePeekDocuments } from "./peekDocuments";

interface LanguageClientManageOptions {
Expand Down Expand Up @@ -165,21 +164,6 @@ export class LanguageClientManager implements vscode.Disposable {

this.subscriptions.push(onChangeConfig);

// Swift versions prior to 5.6 don't support file changes, so need to restart
// lSP server when a file is either created or deleted
if (this.swiftVersion.isLessThan(new Version(5, 6, 0))) {
folderContext.workspaceContext.logger.debug("LSP: Adding new/delete file handlers");
// restart LSP server on creation of a new file
const onDidCreateFileDisposable = vscode.workspace.onDidCreateFiles(() => {
void this.restart();
});
// restart LSP server on deletion of a file
const onDidDeleteFileDisposable = vscode.workspace.onDidDeleteFiles(() => {
void this.restart();
});
this.subscriptions.push(onDidCreateFileDisposable, onDidDeleteFileDisposable);
}

this.waitingOnRestartCount = 0;
this.documentSymbolWatcher = undefined;
this.cancellationToken = new vscode.CancellationTokenSource();
Expand Down Expand Up @@ -526,10 +510,6 @@ export class LanguageClientManager implements vscode.Disposable {
// if sourcekit-lsp crashes during normal operation.
errorHandler.enable();

if (this.swiftVersion.isLessThan(new Version(5, 7, 0))) {
this.legacyInlayHints = activateLegacyInlayHints(client);
}

this.peekDocuments = activatePeekDocuments(client);
this.getReferenceDocument = activateGetReferenceDocument(client);
this.subscriptions.push(this.getReferenceDocument);
Expand Down
7 changes: 1 addition & 6 deletions src/toolchain/BuildFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import * as path from "path";
import configuration from "../configuration";
import { SwiftLogger } from "../logging/SwiftLogger";
import { execSwift } from "../utilities/utilities";
import { Version } from "../utilities/version";
import { DarwinCompatibleTarget, SwiftToolchain, getDarwinTargetTriple } from "./toolchain";

/** Target info */
Expand Down Expand Up @@ -111,11 +110,7 @@ export class BuildFlags {
*/
buildPathFlags(): string[] {
if (configuration.buildPath && configuration.buildPath.length > 0) {
if (this.toolchain.swiftVersion.isLessThan(new Version(5, 8, 0))) {
return ["--build-path", configuration.buildPath];
} else {
return ["--scratch-path", configuration.buildPath];
}
return ["--scratch-path", configuration.buildPath];
} else {
return [];
}
Expand Down
4 changes: 0 additions & 4 deletions src/toolchain/toolchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,6 @@ export class SwiftToolchain {
* @returns a {@link SwiftProjectTemplate} for each discovered project type
*/
public async getProjectTemplates(): Promise<SwiftProjectTemplate[]> {
// Only swift versions >=5.8.0 are supported
if (this.swiftVersion.isLessThan(new Version(5, 8, 0))) {
return [];
}
// Parse the output from `swift package init --help`
const { stdout } = await execSwift(["package", "init", "--help"], "default");
const lines = stdout.split(/\r?\n/g);
Expand Down
7 changes: 1 addition & 6 deletions test/integration-tests/WorkspaceContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,6 @@ tag("medium").suite("WorkspaceContext Test Suite", () => {
});

tag("small").test("get project templates", async () => {
// This is only supported in swift versions >=5.8.0
const swiftVersion = workspaceContext.globalToolchain.swiftVersion;
if (swiftVersion.isLessThan(new Version(5, 8, 0))) {
assert.deepEqual(await workspaceContext.globalToolchain.getProjectTemplates(), []);
return;
}
// The output of `swift package init --help` will probably change at some point.
// Just make sure that the most complex portions of the output are parsed correctly.
const projectTemplates = await workspaceContext.globalToolchain.getProjectTemplates();
Expand All @@ -218,6 +212,7 @@ tag("medium").suite("WorkspaceContext Test Suite", () => {
"A package with an executable that uses Swift Argument Parser. Use this template if you plan to have a rich set of command-line arguments.",
});
// build-tool-plugin is only available in swift versions >=5.9.0
const swiftVersion = workspaceContext.globalToolchain.swiftVersion;
if (swiftVersion.isLessThan(new Version(5, 9, 0))) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions test/unit-tests/toolchain/BuildFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ suite("BuildFlags Test Suite", () => {
]);
});

test("configuration provided, before swift 5.8", () => {
mockedToolchain.swiftVersion = new Version(5, 7, 0);
test("configuration provided", () => {
mockedToolchain.swiftVersion = new Version(5, 9, 0);
buildPathConfig.setValue("/some/other/full/test/path");
expect(buildFlags.buildPathFlags()).to.deep.equal([
"--build-path",
"--scratch-path",
"/some/other/full/test/path",
]);
});
Expand Down