@@ -25,12 +25,14 @@ import {
25
25
import { closeAllEditors } from "../../utilities/commands" ;
26
26
import {
27
27
determineSchemaURL ,
28
+ handleConfigFileChange ,
28
29
handleSchemaUpdate ,
29
30
sourcekitConfigFilePath ,
30
31
sourcekitFolderPath ,
31
32
} from "../../../src/commands/generateSourcekitConfiguration" ;
32
33
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" ;
34
36
35
37
suite ( "Generate SourceKit-LSP configuration Command" , function ( ) {
36
38
let folderContext : FolderContext ;
@@ -112,6 +114,7 @@ suite("Generate SourceKit-LSP configuration Command", function () {
112
114
113
115
suite ( "handleSchemaUpdate" , async ( ) => {
114
116
const mockWindow = mockGlobalObject ( vscode , "window" ) ;
117
+ const mockRestartLSPServerModule = mockGlobalModule ( restartLSPServerModule ) ;
115
118
116
119
test ( "Updates to new schema version" , async ( ) => {
117
120
await vscode . workspace . fs . writeFile (
@@ -156,7 +159,12 @@ suite("Generate SourceKit-LSP configuration Command", function () {
156
159
157
160
await handleSchemaUpdate ( document , workspaceContext ) ;
158
161
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
+ ) ;
160
168
} ) ;
161
169
162
170
test ( "Don't update schema version" , async ( ) => {
@@ -180,5 +188,29 @@ suite("Generate SourceKit-LSP configuration Command", function () {
180
188
"https://raw.githubusercontent.com/swiftlang/sourcekit-lsp/refs/heads/main/config.schema.json"
181
189
) ;
182
190
} ) ;
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
+ } ) ;
183
215
} ) ;
184
216
} ) ;
0 commit comments