Skip to content

Commit f485f66

Browse files
committed
Refactor Swiftly import and address comments
1 parent f321e9f commit f485f66

File tree

5 files changed

+310
-18
lines changed

5 files changed

+310
-18
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,10 +1128,10 @@
11281128
"order": 4,
11291129
"scope": "machine-overridable"
11301130
},
1131-
"swift.suppressSwiftlyInstallPrompt": {
1131+
"swift.disableSwiftlyInstallPrompt": {
11321132
"type": "boolean",
11331133
"default": false,
1134-
"markdownDescription": "Suppress the automatic Swiftly installation prompt when no Swift toolchain is found.",
1134+
"markdownDescription": "Disable the automatic Swiftly installation prompt when no Swift toolchain is found.",
11351135
"order": 98,
11361136
"scope": "application"
11371137
},

src/FolderContext.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import { TestExplorer } from "./TestExplorer/TestExplorer";
2222
import { TestRunManager } from "./TestExplorer/TestRunManager";
2323
import { TestRunProxy } from "./TestExplorer/TestRunner";
2424
import { FolderOperation, WorkspaceContext } from "./WorkspaceContext";
25+
import { handleMissingSwiftly } from "./commands/installSwiftly";
2526
import configuration from "./configuration";
2627
import { SwiftLogger } from "./logging/SwiftLogger";
2728
import { PlaygroundProvider } from "./playgrounds/PlaygroundProvider";
2829
import { TaskQueue } from "./tasks/TaskQueue";
30+
import { Swiftly } from "./toolchain/swiftly";
2931
import { SwiftToolchain } from "./toolchain/toolchain";
3032
import { showToolchainError } from "./ui/ToolchainSelection";
3133
import { isPathInsidePath } from "./utilities/filesystem";
@@ -95,6 +97,23 @@ export class FolderContext implements vscode.Disposable {
9597
const statusItemText = `Loading Package (${FolderContext.uriName(folder)})`;
9698
workspaceContext.statusItem.start(statusItemText);
9799

100+
// Check if this folder has a .swift-version file and Swiftly is not installed
101+
try {
102+
const swiftVersionPath = vscode.Uri.joinPath(folder, ".swift-version");
103+
await vscode.workspace.fs.stat(swiftVersionPath);
104+
105+
// File exists, check if Swiftly is installed
106+
const swiftlyInstalled = await Swiftly.isInstalled();
107+
if (!swiftlyInstalled) {
108+
workspaceContext.logger.info(
109+
`Detected .swift-version file in ${FolderContext.uriName(folder)} without Swiftly, prompting for installation`
110+
);
111+
await handleMissingSwiftly(workspaceContext.logger);
112+
}
113+
} catch {
114+
// .swift-version file doesn't exist, continue normally
115+
}
116+
98117
let toolchain: SwiftToolchain;
99118
try {
100119
toolchain = await SwiftToolchain.create(

src/commands/installSwiftly.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,41 @@ export async function promptForSwiftlyInstallation(
3333
): Promise<SwiftlyInstallOptions | null> {
3434
const installMessage = `A .swift-version file was detected. Install Swiftly to automatically manage Swift toolchain versions for this project.`;
3535

36-
const selection = await vscode.window.showInformationMessage(
36+
const selection = await vscode.window.showWarningMessage(
3737
installMessage,
3838
{ modal: false },
3939
"Install Swiftly",
40-
"Customize Directories",
41-
"Don't Show Again",
42-
"Cancel"
40+
"Don't Show Again"
4341
);
4442

4543
switch (selection) {
46-
case "Install Swiftly":
47-
return {}; // Use defaults
48-
49-
case "Customize Directories":
50-
return await promptForDirectoryCustomization(logger);
44+
case "Install Swiftly": {
45+
// Ask if user wants to customize directories
46+
const customizeSelection = await vscode.window.showInformationMessage(
47+
"Do you want to customize the installation directories?",
48+
{ modal: false },
49+
"Use Defaults",
50+
"Customize Directories"
51+
);
52+
53+
if (customizeSelection === "Customize Directories") {
54+
return await promptForDirectoryCustomization(logger);
55+
} else if (customizeSelection === "Use Defaults") {
56+
return {}; // Use defaults
57+
}
58+
return null; // User closed the prompt
59+
}
5160

5261
case "Don't Show Again":
5362
// Set a workspace setting to suppress this prompt
5463
await vscode.workspace
5564
.getConfiguration("swift")
56-
.update("suppressSwiftlyInstallPrompt", true, vscode.ConfigurationTarget.Global);
65+
.update("disableSwiftlyInstallPrompt", true, vscode.ConfigurationTarget.Global);
5766
logger?.info("Swiftly installation prompt suppressed by user");
5867
return null;
5968

60-
case "Cancel":
6169
default:
62-
return null;
70+
return null; // User closed the prompt
6371
}
6472
}
6573

@@ -163,7 +171,7 @@ export async function installSwiftlyWithProgress(
163171
* @returns true if suppressed, false otherwise
164172
*/
165173
export function isSwiftlyPromptSuppressed(): boolean {
166-
return vscode.workspace.getConfiguration("swift").get("suppressSwiftlyInstallPrompt", false);
174+
return vscode.workspace.getConfiguration("swift").get("disableSwiftlyInstallPrompt", false);
167175
}
168176

169177
/**

src/extension.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { SwiftLoggerFactory } from "./logging/SwiftLoggerFactory";
3636
import { PlaygroundProvider } from "./playgrounds/PlaygroundProvider";
3737
import { SwiftEnvironmentVariablesManager, SwiftTerminalProfileProvider } from "./terminal";
3838
import { SelectedXcodeWatcher } from "./toolchain/SelectedXcodeWatcher";
39-
import { checkForSwiftlyInstallation } from "./toolchain/swiftly";
39+
import { Swiftly, checkForSwiftlyInstallation } from "./toolchain/swiftly";
4040
import { SwiftToolchain } from "./toolchain/toolchain";
4141
import { LanguageStatusItems } from "./ui/LanguageStatusItems";
4242
import { getReadOnlyDocumentProvider } from "./ui/ReadOnlyDocumentProvider";
@@ -334,7 +334,6 @@ async function createActiveToolchain(
334334
): Promise<SwiftToolchain | undefined> {
335335
// Check if there's a .swift-version file in the workspace and Swiftly is not installed
336336
if (await hasSwiftVersionFile()) {
337-
const { Swiftly } = await import("./toolchain/swiftly");
338337
const swiftlyInstalled = await Swiftly.isInstalled();
339338

340339
if (!swiftlyInstalled) {

0 commit comments

Comments
 (0)