Skip to content

Commit

Permalink
fix(vscode): unlock vscode extension (#2646)
Browse files Browse the repository at this point in the history
Fix (**partial**) #2580
  • Loading branch information
kpanot authored Jan 7, 2025
2 parents 1668f71 + 8643504 commit 1eaf786
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions apps/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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),
Expand Down
16 changes: 11 additions & 5 deletions apps/vscode-extension/src/intellisense/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CompletionItem, CompletionItemKind, CompletionItemProvider, SnippetString } from 'vscode';
import { ESLint } from 'eslint';
import { CompletionItem, CompletionItemKind, CompletionItemProvider, type OutputChannel, SnippetString } from 'vscode';

interface ConfigurationTags {
/** @see CompletionItem.documentation */
Expand Down Expand Up @@ -97,8 +96,15 @@ const getConfigurationTagsFromEslintConfig = (eslintConfig: any, comment: string
};
};

export const configurationCompletionItemProvider = () : CompletionItemProvider<CompletionItem> => {
const eslint = new ESLint();
export const configurationCompletionItemProvider = (options: { channel: OutputChannel }): CompletionItemProvider<CompletionItem> => {
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) => {
Expand Down Expand Up @@ -132,7 +138,7 @@ export const configurationCompletionItemProvider = () : CompletionItemProvider<C
return [];
}

const config = await eslint.calculateConfigForFile(doc.fileName);
const config = await (await eslint)?.calculateConfigForFile(doc.fileName) || {};
const configurationTags = getConfigurationTagsFromEslintConfig(config, match[0], fileText);

return getCompletionsItemsFromConfigurationTags(configurationTags);
Expand Down

0 comments on commit 1eaf786

Please sign in to comment.