From 35902f669aef675125b1a1ff6eba7c57c9cc05f4 Mon Sep 17 00:00:00 2001 From: Kilian Panot Date: Mon, 23 Dec 2024 12:26:46 +0900 Subject: [PATCH] fix(vscode): unlock vscode extension --- apps/vscode-extension/src/extension.ts | 6 ++++-- .../src/intellisense/configuration.ts | 16 +++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/vscode-extension/src/extension.ts b/apps/vscode-extension/src/extension.ts index 9189dc475f..fb2b094440 100644 --- a/apps/vscode-extension/src/extension.ts +++ b/apps/vscode-extension/src/extension.ts @@ -1,6 +1,7 @@ import { commands, - ExtensionContext, languages } from 'vscode'; + ExtensionContext, languages, + window } from 'vscode'; import { extractAllToVariable } from './commands/extract/styling/extract-all-to-variable.command'; import { extractToVariable } from './commands/extract/styling/extract-to-variable.command'; import { generateComponentGenerateCommand } from './commands/generate/component.command'; @@ -33,10 +34,11 @@ import { designTokenCompletionItemAndHoverProviders } from './intellisense/desig * @param context */ export function activate(context: ExtensionContext) { + const channel = window.createOutputChannel('Otter'); const designTokenProviders = designTokenCompletionItemAndHoverProviders(); context.subscriptions.push( - languages.registerCompletionItemProvider(['javascript','typescript'], configurationCompletionItemProvider(), configurationCompletionTriggerChar), + languages.registerCompletionItemProvider(['javascript','typescript'], configurationCompletionItemProvider({ channel }), configurationCompletionTriggerChar), languages.registerCompletionItemProvider(['scss'], stylingCompletionItemProvider(), stylingCompletionTriggerChar), languages.registerCompletionItemProvider(['scss', 'css'], designTokenProviders), languages.registerHoverProvider(['scss', 'css'], designTokenProviders), diff --git a/apps/vscode-extension/src/intellisense/configuration.ts b/apps/vscode-extension/src/intellisense/configuration.ts index c1a8c85778..73099bd59a 100644 --- a/apps/vscode-extension/src/intellisense/configuration.ts +++ b/apps/vscode-extension/src/intellisense/configuration.ts @@ -1,5 +1,4 @@ -import { CompletionItem, CompletionItemKind, CompletionItemProvider, SnippetString } from 'vscode'; -import { ESLint } from 'eslint'; +import { CompletionItem, CompletionItemKind, CompletionItemProvider, SnippetString, type OutputChannel } from 'vscode'; interface ConfigurationTags { /** @see CompletionItem.documentation */ @@ -97,8 +96,15 @@ const getConfigurationTagsFromEslintConfig = (eslintConfig: any, comment: string }; }; -export const configurationCompletionItemProvider = () : CompletionItemProvider => { - const eslint = new ESLint(); +export const configurationCompletionItemProvider = (options: { channel: OutputChannel }): CompletionItemProvider => { + const eslint = import('eslint') + // eslint-disable-next-line @typescript-eslint/naming-convention -- External package defined name + .then(({ ESLint }) => new ESLint()) + .catch((err) => { + options.channel.appendLine('Error during ESLint loading:'); + options.channel.appendLine(JSON.stringify(err)); + return undefined; + }); return { provideCompletionItems: async (doc, pos) => { @@ -132,7 +138,7 @@ export const configurationCompletionItemProvider = () : CompletionItemProvider