From 9b878583e9c1b30b7a86339d6eae599f0469adc1 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Tue, 19 Nov 2024 13:43:58 -0500 Subject: [PATCH] Show multi-root workspace warning as progress instead --- vscode/src/rubyLsp.ts | 68 ++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/vscode/src/rubyLsp.ts b/vscode/src/rubyLsp.ts index 4a055f743..83e5870ee 100644 --- a/vscode/src/rubyLsp.ts +++ b/vscode/src/rubyLsp.ts @@ -175,7 +175,6 @@ export class RubyLsp { workspaceFolder: vscode.WorkspaceFolder, eager: boolean, ) { - const workspaceDir = workspaceFolder.uri.fsPath; const customBundleGemfile: string = vscode.workspace .getConfiguration("rubyLsp") .get("bundleGemfile")!; @@ -191,31 +190,8 @@ export class RubyLsp { // If no lockfile exists and we're activating lazily (if the user opened a Ruby file inside a workspace we hadn't // activated before), then we start the language server, but we warn the user that they may be missing multi-root // workspace configuration - if ( - customBundleGemfile.length === 0 && - !lockfileExists && - !this.context.globalState.get("rubyLsp.disableMultirootLockfileWarning") - ) { - const answer = await vscode.window.showWarningMessage( - `Activating the Ruby LSP in ${workspaceDir}, but no lockfile was found. Are you using a monorepo setup?`, - "See the multi-root workspace docs", - "Don't show again", - ); - - if (answer === "See the multi-root workspace docs") { - await vscode.env.openExternal( - vscode.Uri.parse( - "https://github.com/Shopify/ruby-lsp/blob/main/vscode/README.md?tab=readme-ov-file#multi-root-workspaces", - ), - ); - } - - if (answer === "Don't show again") { - await this.context.globalState.update( - "rubyLsp.disableMultirootLockfileWarning", - true, - ); - } + if (customBundleGemfile.length === 0 && !lockfileExists) { + await this.showStandaloneWarning(workspaceFolder.uri.fsPath); } const workspace = new Workspace( @@ -797,4 +773,44 @@ export class RubyLsp { return false; } + + private async showStandaloneWarning(workspaceDir: string) { + await vscode.window.withProgress( + { + location: vscode.ProgressLocation.Notification, + title: "No bundle found. Launching in standalone mode in 5 seconds", + cancellable: true, + }, + async (progress, token) => { + progress.report({ + message: + "If working in a monorepo, cancel to see configuration instructions", + }); + + await new Promise((resolve) => { + token.onCancellationRequested(() => { + resolve(); + }); + + setTimeout(resolve, 5000); + }); + + if (token.isCancellationRequested) { + const answer = await vscode.window.showWarningMessage( + `Could not find a lockfile in ${workspaceDir}. Are you using a monorepo setup?`, + "See the multi-root workspace docs", + "Launch anyway", + ); + + if (answer === "See the multi-root workspace docs") { + const uri = vscode.Uri.parse( + "https://github.com/Shopify/ruby-lsp/blob/main/vscode/README.md?tab=readme-ov-file#multi-root-workspaces", + ); + + await vscode.env.openExternal(uri); + } + } + }, + ); + } }