Skip to content

Commit 74d2ab0

Browse files
authored
Show multi-root workspace warning as progress instead (#2879)
### Motivation We noticed that the warning for multi-root workspaces is sometimes ignored by users. The problem is that if you don't click anything, the LSP will never start because the promise is never resolved. Let's show the warning under a timer and auto-dismiss so that the behaviour is less confusing. ### Implementation I put the same warning inside a progress notification that auto-dismisses under 5 seconds.
1 parent 5f13ecd commit 74d2ab0

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

vscode/src/rubyLsp.ts

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ export class RubyLsp {
175175
workspaceFolder: vscode.WorkspaceFolder,
176176
eager: boolean,
177177
) {
178-
const workspaceDir = workspaceFolder.uri.fsPath;
179178
const customBundleGemfile: string = vscode.workspace
180179
.getConfiguration("rubyLsp")
181180
.get("bundleGemfile")!;
@@ -191,31 +190,8 @@ export class RubyLsp {
191190
// If no lockfile exists and we're activating lazily (if the user opened a Ruby file inside a workspace we hadn't
192191
// activated before), then we start the language server, but we warn the user that they may be missing multi-root
193192
// workspace configuration
194-
if (
195-
customBundleGemfile.length === 0 &&
196-
!lockfileExists &&
197-
!this.context.globalState.get("rubyLsp.disableMultirootLockfileWarning")
198-
) {
199-
const answer = await vscode.window.showWarningMessage(
200-
`Activating the Ruby LSP in ${workspaceDir}, but no lockfile was found. Are you using a monorepo setup?`,
201-
"See the multi-root workspace docs",
202-
"Don't show again",
203-
);
204-
205-
if (answer === "See the multi-root workspace docs") {
206-
await vscode.env.openExternal(
207-
vscode.Uri.parse(
208-
"https://github.com/Shopify/ruby-lsp/blob/main/vscode/README.md?tab=readme-ov-file#multi-root-workspaces",
209-
),
210-
);
211-
}
212-
213-
if (answer === "Don't show again") {
214-
await this.context.globalState.update(
215-
"rubyLsp.disableMultirootLockfileWarning",
216-
true,
217-
);
218-
}
193+
if (customBundleGemfile.length === 0 && !lockfileExists) {
194+
await this.showStandaloneWarning(workspaceFolder.uri.fsPath);
219195
}
220196

221197
const workspace = new Workspace(
@@ -797,4 +773,44 @@ export class RubyLsp {
797773

798774
return false;
799775
}
776+
777+
private async showStandaloneWarning(workspaceDir: string) {
778+
await vscode.window.withProgress(
779+
{
780+
location: vscode.ProgressLocation.Notification,
781+
title: "No bundle found. Launching in standalone mode in 5 seconds",
782+
cancellable: true,
783+
},
784+
async (progress, token) => {
785+
progress.report({
786+
message:
787+
"If working in a monorepo, cancel to see configuration instructions",
788+
});
789+
790+
await new Promise<void>((resolve) => {
791+
token.onCancellationRequested(() => {
792+
resolve();
793+
});
794+
795+
setTimeout(resolve, 5000);
796+
});
797+
798+
if (token.isCancellationRequested) {
799+
const answer = await vscode.window.showWarningMessage(
800+
`Could not find a lockfile in ${workspaceDir}. Are you using a monorepo setup?`,
801+
"See the multi-root workspace docs",
802+
"Launch anyway",
803+
);
804+
805+
if (answer === "See the multi-root workspace docs") {
806+
const uri = vscode.Uri.parse(
807+
"https://github.com/Shopify/ruby-lsp/blob/main/vscode/README.md?tab=readme-ov-file#multi-root-workspaces",
808+
);
809+
810+
await vscode.env.openExternal(uri);
811+
}
812+
}
813+
},
814+
);
815+
}
800816
}

0 commit comments

Comments
 (0)