Skip to content

Commit 146bf26

Browse files
committed
fix: guard against lean language id
1 parent a884fa0 commit 146bf26

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

vscode-lean4/src/extension.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { ExtUri, extUriToCwdUri, FileUri, toExtUri } from './utils/exturi'
2222
import { FullInstaller } from './utils/fullInstaller'
2323
import { displayInternalErrorsIn } from './utils/internalErrors'
2424
import { registerLeanCommandRunner } from './utils/leanCmdRunner'
25-
import { lean, registerLeanEditorProviders, text } from './utils/leanEditorProvider'
25+
import { isLeanDocument, lean, registerLeanEditorProviders, text } from './utils/leanEditorProvider'
2626
import { LeanInstaller } from './utils/leanInstaller'
2727
import { ModuleTreeViewProvider } from './utils/moduleTreeViewProvider'
2828
import {
@@ -48,7 +48,7 @@ async function findInitialLeanProjectUri(editor: TextEditor): Promise<ExtUri | u
4848
if (info.kind === 'FileNotFound') {
4949
return undefined
5050
}
51-
if (editor.document.languageId !== 'lean4' && info.kind === 'Success' && info.toolchainUri === undefined) {
51+
if (!isLeanDocument(editor.document) && info.kind === 'Success' && info.toolchainUri === undefined) {
5252
return undefined
5353
}
5454
return info.projectRootUri
@@ -179,7 +179,7 @@ function activateAlwaysEnabledFeatures(context: ExtensionContext): AlwaysEnabled
179179

180180
const checkForExtensionConflict = (doc: TextDocument) => {
181181
const isLean3ExtensionInstalled = extensions.getExtension('jroesch.lean') !== undefined
182-
if (isLean3ExtensionInstalled && (doc.languageId === 'lean' || doc.languageId === 'lean4')) {
182+
if (isLean3ExtensionInstalled && isLeanDocument(doc)) {
183183
displayNotification(
184184
'Error',
185185
"The Lean 3 and the Lean 4 VS Code extension are enabled at the same time. Since both extensions act on .lean files, this can lead to issues with either extension. Please disable the extension for the Lean major version that you do not wish to use ('Extensions' in the left sidebar > Cog icon > 'Disable').",
@@ -316,14 +316,14 @@ async function tryActivatingLean4Features(
316316
)
317317
}
318318
// We try activating the Lean features in two cases:
319-
// 1. When revealing a new editor with the `lean4` language ID (e.g.: switching tabs, opening a new Lean document, changing the language ID to `lean4`)
320-
// 2. When revealing a new editor in a Lean project that doesn't have the `lean4` language ID (e.g.: switching tabs, opening a new document)
319+
// 1. When revealing a new editor with the `lean` or `lean4` language ID (e.g.: switching tabs, opening a new Lean document, changing the language ID to `lean` or `lean4`)
320+
// 2. When revealing a new editor in a Lean project that doesn't have the `lean` or `lean4` language ID (e.g.: switching tabs, opening a new document)
321321
// These two events are disjoint, so combining them won't cause duplicate triggers.
322322
const combinedEvent = combine(
323323
lean.onDidRevealLeanEditor,
324324
_ => true,
325325
text.onDidRevealLeanEditor,
326-
editor => editor.editor.document.languageId !== 'lean4',
326+
editor => !isLeanDocument(editor.editor.document),
327327
)
328328
context.subscriptions.push(combinedEvent.disposable)
329329
context.subscriptions.push(

vscode-lean4/src/utils/leanEditorProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import {
1414
import { ExtUri, isExtUri, toExtUriOrError } from './exturi'
1515
import { groupByKey, groupByUniqueKey } from './groupBy'
1616

17+
export function isLeanDocument(doc: TextDocument): boolean {
18+
return isExtUri(doc.uri) && (doc.languageId === 'lean4' || doc.languageId === 'lean')
19+
}
20+
1721
export class LeanDocument {
1822
constructor(
1923
readonly doc: TextDocument,
@@ -329,7 +333,7 @@ export class LeanEditorProvider implements Disposable {
329333
private isLeanDocument(doc: TextDocument): boolean {
330334
switch (this.mode) {
331335
case 'Lean':
332-
return isExtUri(doc.uri) && doc.languageId === 'lean4'
336+
return isLeanDocument(doc)
333337
case 'Text':
334338
return isExtUri(doc.uri)
335339
}

0 commit comments

Comments
 (0)