@@ -32,6 +32,7 @@ import { SwiftExecOperation, TaskOperation } from "./tasks/TaskQueue";
3232import { SwiftProjectTemplate } from "./toolchain/toolchain" ;
3333import { showToolchainSelectionQuickPick , showToolchainError } from "./ui/ToolchainSelection" ;
3434import { captureDiagnostics } from "./commands/captureDiagnostics" ;
35+ import { reindexProjectRequest } from "./sourcekit-lsp/lspExtensions" ;
3536
3637/**
3738 * References:
@@ -656,6 +657,25 @@ function restartLSPServer(workspaceContext: WorkspaceContext): Promise<void> {
656657 return workspaceContext . languageClientManager . restart ( ) ;
657658}
658659
660+ /** Request that the SourceKit-LSP server reindexes the workspace */
661+ function reindexProject ( workspaceContext : WorkspaceContext ) : Promise < unknown > {
662+ return workspaceContext . languageClientManager . useLanguageClient ( async ( client , token ) => {
663+ try {
664+ return await client . sendRequest ( reindexProjectRequest , { } , token ) ;
665+ } catch ( err ) {
666+ const error = err as { code : number ; message : string } ;
667+ // methodNotFound, version of sourcekit-lsp is likely too old.
668+ if ( error . code === - 32601 ) {
669+ vscode . window . showWarningMessage (
670+ "The installed version of SourceKit-LSP does not support background indexing."
671+ ) ;
672+ } else {
673+ vscode . window . showWarningMessage ( error . message ) ;
674+ }
675+ }
676+ } ) ;
677+ }
678+
659679/** Execute task and show UI while running */
660680async function executeTaskWithUI (
661681 task : vscode . Task ,
@@ -817,6 +837,7 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
817837 vscode . commands . registerCommand ( "swift.debugSnippet" , ( ) => debugSnippet ( ctx ) ) ,
818838 vscode . commands . registerCommand ( "swift.runPluginTask" , ( ) => runPluginTask ( ) ) ,
819839 vscode . commands . registerCommand ( "swift.restartLSPServer" , ( ) => restartLSPServer ( ctx ) ) ,
840+ vscode . commands . registerCommand ( "swift.reindexProject" , ( ) => reindexProject ( ctx ) ) ,
820841 vscode . commands . registerCommand ( "swift.insertFunctionComment" , ( ) =>
821842 insertFunctionComment ( ctx )
822843 ) ,
0 commit comments