Skip to content

Commit d310b9c

Browse files
authored
feat: improve activation error when forked extension is installed (#613)
Every so often, users decide that they want to get (what they believe to be) the "full" Lean experience in VS Code and install every single Lean-related extension from the VS Code marketplace. While well-intentioned, since the marketplace also contains forks of our extension, this then leads to an internal activation error when VS Code's `commands.registerCommand` API throws an exception for trying to register duplicate commands. This PR improves the error message that is displayed in this case to hint at the cause so that users are more likely to be able to fix it themselves without requiring assistance.
1 parent 0d094aa commit d310b9c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

vscode-lean4/src/utils/internalErrors.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { env } from 'vscode'
2-
import { displayNotificationWithInput } from './notifs'
2+
import { displayModalNotification, displayNotificationWithInput } from './notifs'
33

44
export async function displayInternalError(scope: string, e: any) {
55
let msg: string = `Internal error (while ${scope}): ${e}`
@@ -17,10 +17,21 @@ export async function displayInternalError(scope: string, e: any) {
1717
}
1818
}
1919

20+
const duplicateCommandError = (scope: string) =>
21+
`Error (while ${scope}): Two separate Lean 4 VS Code extensions that register the same VS Code functionality are installed.
22+
Please uninstall or disable one of them and restart VS Code.
23+
24+
The 'Lean 4' extension by the 'leanprover' organization is the only official Lean 4 VS Code extension.`
25+
2026
export async function displayInternalErrorsIn<T>(scope: string, f: () => Promise<T>): Promise<T> {
2127
try {
2228
return await f()
2329
} catch (e) {
30+
const msg = e.message
31+
if (msg !== undefined && typeof msg === 'string' && msg.match(/command '.*' already exists/)) {
32+
await displayModalNotification('Error', duplicateCommandError(scope))
33+
throw e
34+
}
2435
await displayInternalError(scope, e)
2536
throw e
2637
}

0 commit comments

Comments
 (0)