Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cascading] from release/11.5 to release/11.6.0-rc #2669

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
commands,
ExtensionContext,
languages,
window,
} from 'vscode';
import {
extractAllToVariable,
Expand Down Expand Up @@ -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),
Expand Down
17 changes: 11 additions & 6 deletions apps/vscode-extension/src/intellisense/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
CompletionItem,
CompletionItemKind,
CompletionItemProvider,
type OutputChannel,
SnippetString,
} from 'vscode';
import type {
Expand All @@ -11,9 +12,6 @@ import type {
import type {
TSESLint,
} from '@typescript-eslint/utils';
import {
ESLint,
} from 'eslint';

interface ConfigurationTags {
/** @see CompletionItem.documentation */
Expand Down Expand Up @@ -115,8 +113,15 @@ const getConfigurationTagsFromEslintConfig = (eslintConfig: TSESLint.FlatConfig.
};
};

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 @@ -150,7 +155,7 @@ export const configurationCompletionItemProvider = (): CompletionItemProvider<Co
return [];
}

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

return getCompletionsItemsFromConfigurationTags(configurationTags);
Expand Down
Loading