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

do not suggest lang when editing attributes #469

Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions packages/language-server/src/plugins/html/HTMLPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Position,
SymbolInformation,
CompletionItem,
CompletionItemKind,
} from 'vscode-languageserver';
import {
DocumentManager,
Expand All @@ -21,6 +22,7 @@ export class HTMLPlugin implements HoverProvider, CompletionsProvider {
private configManager: LSConfigManager;
private lang = getLanguageService({ customDataProviders: [svelteHtmlDataProvider] });
private documents = new WeakMap<Document, HTMLDocument>();
private styleScriptTemplate = new Set(['template', 'style', 'script']);

constructor(docManager: DocumentManager, configManager: LSConfigManager) {
this.configManager = configManager;
Expand Down Expand Up @@ -84,8 +86,10 @@ export class HTMLPlugin implements HoverProvider, CompletionsProvider {
}

private getLangCompletions(completions: CompletionItem[]): CompletionItem[] {
const styleScriptTemplateCompletions = completions.filter((completion) =>
['template', 'style', 'script'].includes(completion.label),
const styleScriptTemplateCompletions = completions.filter(
(completion) =>
completion.kind === CompletionItemKind.Property &&
this.styleScriptTemplate.has(completion.label),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great optimization!

);
const langCompletions: CompletionItem[] = [];
addLangCompletion('script', ['ts']);
Expand Down
19 changes: 19 additions & 0 deletions packages/language-server/test/plugins/html/HTMLPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,23 @@ describe('HTML Plugin', () => {
const tagCompletion = plugin.doTagComplete(document, Position.create(0, 21));
assert.strictEqual(tagCompletion, '$0</div>');
});

it('does provide lang in completions', async () => {
const { plugin, document } = setup('<sty');

const completions = plugin.getCompletions(document, Position.create(0, 4));
assert.ok(Array.isArray(completions && completions.items));
assert.ok(completions!.items.find((item) => item.label === 'style (lang="less")'));
});

it('does not provide lang in completions for attributes', async () => {
const { plugin, document } = setup('<div sty');

const completions = plugin.getCompletions(document, Position.create(0, 8));
assert.ok(Array.isArray(completions && completions.items));
assert.strictEqual(
completions!.items.find((item) => item.label === 'style (lang="less")'),
undefined,
);
});
});