Skip to content

Commit 88753d0

Browse files
authored
fix: guard against lean language id (#738)
1 parent 9e9ab08 commit 88753d0

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

vscode-lean4/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"lean4.input.languages": {
4848
"type": "array",
4949
"default": [
50-
"lean4"
50+
"lean4",
51+
"lean"
5152
],
5253
"markdownDescription": "Enable Lean Unicode input in other file types.",
5354
"items": {

vscode-lean4/src/abbreviation/VSCodeAbbreviationConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class VSCodeAbbreviationConfig implements AbbreviationConfig, Disposable
2424
private reloadConfig() {
2525
this.inputModeEnabled = workspace.getConfiguration('lean4.input').get('enabled', true)
2626
this.abbreviationCharacter = workspace.getConfiguration('lean4.input').get('leader', '\\')
27-
this.languages = workspace.getConfiguration('lean4.input').get('languages', ['lean4'])
27+
this.languages = workspace.getConfiguration('lean4.input').get('languages', ['lean4', 'lean'])
2828
this.customTranslations = workspace.getConfiguration('lean4.input').get('customTranslations', {})
2929
this.eagerReplacementEnabled = workspace.getConfiguration('lean4.input').get('eagerReplacementEnabled', true)
3030
}

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/leanclient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ export class LeanClient implements Disposable {
841841
return {
842842
outputChannel: this.outputChannel,
843843
revealOutputChannelOn: RevealOutputChannelOn.Never, // contrary to the name, this disables the message boxes
844-
documentSelector: [documentSelector],
844+
documentSelector: [documentSelector, { ...documentSelector, language: 'lean' }],
845845
workspaceFolder,
846846
initializationOptions: {
847847
hasWidgets: true,

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)