From 34533ca9cc9292faa8115d856728f25d9deee4c8 Mon Sep 17 00:00:00 2001 From: Kilian Panot Date: Mon, 23 Dec 2024 12:21:05 +0900 Subject: [PATCH] fix(vscode): Allow VsCode extension without espree detection --- .yarnrc.yml | 2 +- apps/vscode-extension/package.json | 1 + apps/vscode-extension/src/extension.ts | 4 +- .../src/intellisense/configuration.ts | 17 +++-- packages/@ama-sdk/schematics/package.json | 2 +- packages/@o3r/core/package.json | 6 +- .../@o3r/eslint-config-otter/package.json | 6 +- yarn.lock | 65 +------------------ 8 files changed, 24 insertions(+), 79 deletions(-) diff --git a/.yarnrc.yml b/.yarnrc.yml index dc79fc379c..aa654b4428 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -20,7 +20,7 @@ packageExtensions: "@swc/types": "*" "@typescript-eslint/rule-tester@*": dependencies: - "@typescript-eslint/parser": ~8.17.0 + "@typescript-eslint/parser": ~8.18.0 "@angular-eslint/eslint-plugin-template@*": dependencies: "@typescript-eslint/types": "^8.0.0" diff --git a/apps/vscode-extension/package.json b/apps/vscode-extension/package.json index f690e78301..2d17ceeb01 100644 --- a/apps/vscode-extension/package.json +++ b/apps/vscode-extension/package.json @@ -372,6 +372,7 @@ "@types/node": "^20.0.0", "@types/vscode": "^1.67.0", "@typescript-eslint/parser": "~8.18.0", + "@typescript-eslint/utils": "~8.18.0", "@vscode/vsce": "^2.16.0", "angular-eslint": "~18.4.0", "cpy-cli": "^5.0.0", diff --git a/apps/vscode-extension/src/extension.ts b/apps/vscode-extension/src/extension.ts index ea363dee0e..85f643ca9d 100644 --- a/apps/vscode-extension/src/extension.ts +++ b/apps/vscode-extension/src/extension.ts @@ -2,6 +2,7 @@ import { commands, ExtensionContext, languages, + window, } from 'vscode'; import { extractAllToVariable, @@ -60,10 +61,11 @@ import { * @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 568206c2f8..1fa1d85e1f 100644 --- a/apps/vscode-extension/src/intellisense/configuration.ts +++ b/apps/vscode-extension/src/intellisense/configuration.ts @@ -2,6 +2,7 @@ import { CompletionItem, CompletionItemKind, CompletionItemProvider, + type OutputChannel, SnippetString, } from 'vscode'; import type { @@ -11,9 +12,6 @@ import type { import type { TSESLint, } from '@typescript-eslint/utils'; -import { - ESLint, -} from 'eslint'; interface ConfigurationTags { /** @see CompletionItem.documentation */ @@ -115,8 +113,15 @@ const getConfigurationTagsFromEslintConfig = (eslintConfig: TSESLint.FlatConfig. }; }; -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) => { @@ -150,7 +155,7 @@ export const configurationCompletionItemProvider = (): CompletionItemProvider