Skip to content

Commit fe4df34

Browse files
committed
Add a test for new functionality
Check that a LSP restart prompt is shown when the config.json file is changed and update existing tests that modify the file to ignore the LSP restart prompts.
1 parent c6851c1 commit fe4df34

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/commands/generateSourcekitConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export function registerSourceKitSchemaWatcher(
247247
);
248248
}
249249

250-
async function handleConfigFileChange(
250+
export async function handleConfigFileChange(
251251
configUri: vscode.Uri,
252252
workspaceContext: WorkspaceContext
253253
): Promise<void> {

test/integration-tests/commands/generateSourcekitConfiguration.test.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ import {
2525
import { closeAllEditors } from "../../utilities/commands";
2626
import {
2727
determineSchemaURL,
28+
handleConfigFileChange,
2829
handleSchemaUpdate,
2930
sourcekitConfigFilePath,
3031
sourcekitFolderPath,
3132
} from "../../../src/commands/generateSourcekitConfiguration";
3233
import { Version } from "../../../src/utilities/version";
33-
import { mockGlobalObject } from "../../MockUtils";
34+
import { mockGlobalObject, mockGlobalModule } from "../../MockUtils";
35+
import * as restartLSPServerModule from "../../../src/commands/restartLSPServer";
3436

3537
suite("Generate SourceKit-LSP configuration Command", function () {
3638
let folderContext: FolderContext;
@@ -112,6 +114,7 @@ suite("Generate SourceKit-LSP configuration Command", function () {
112114

113115
suite("handleSchemaUpdate", async () => {
114116
const mockWindow = mockGlobalObject(vscode, "window");
117+
const mockRestartLSPServerModule = mockGlobalModule(restartLSPServerModule);
115118

116119
test("Updates to new schema version", async () => {
117120
await vscode.workspace.fs.writeFile(
@@ -156,7 +159,12 @@ suite("Generate SourceKit-LSP configuration Command", function () {
156159

157160
await handleSchemaUpdate(document, workspaceContext);
158161

159-
expect(mockWindow.showInformationMessage).to.have.not.been.called;
162+
expect(mockWindow.showInformationMessage).to.have.not.been.calledWith(
163+
`The $schema property for ${configFileUri.fsPath} is not set to the version of the Swift toolchain that you are using. Would you like to update the $schema property?`,
164+
"Yes",
165+
"No",
166+
"Don't Ask Again"
167+
);
160168
});
161169

162170
test("Don't update schema version", async () => {
@@ -180,5 +188,29 @@ suite("Generate SourceKit-LSP configuration Command", function () {
180188
"https://raw.githubusercontent.com/swiftlang/sourcekit-lsp/refs/heads/main/config.schema.json"
181189
);
182190
});
191+
192+
test("Check LSP restart prompt for config.json modifications", async () => {
193+
await vscode.workspace.fs.writeFile(
194+
configFileUri,
195+
Buffer.from(
196+
JSON.stringify({
197+
$schema: "invalid schema",
198+
})
199+
)
200+
);
201+
await handleConfigFileChange(configFileUri, workspaceContext);
202+
203+
expect(mockWindow.showInformationMessage).to.have.been.called;
204+
expect(mockWindow.showInformationMessage).to.have.been.calledWith(
205+
`The SourceKit-LSP configuration file has been modified. Would you like to restart the language server to apply the changes?`,
206+
"Restart LSP Server",
207+
"Not Now"
208+
);
209+
210+
mockWindow.showInformationMessage.resolves("Restart LSP Server" as any);
211+
212+
await handleConfigFileChange(configFileUri, workspaceContext);
213+
expect(mockRestartLSPServerModule.default).to.have.been.calledWith(workspaceContext);
214+
});
183215
});
184216
});

0 commit comments

Comments
 (0)