Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
mapRangeToOriginal,
toRange
} from '../../../lib/documents';
import { AttributeContext, getAttributeContextAtPosition } from '../../../lib/documents/parseHtml';
import { LSConfigManager } from '../../../ls-config';
import { flatten, getRegExpMatches, isNotNullOrUndefined, pathToUrl } from '../../../utils';
import { AppCompletionItem, AppCompletionList, CompletionsProvider } from '../../interfaces';
Expand Down Expand Up @@ -164,9 +165,11 @@ export class CompletionsProviderImpl implements CompletionsProvider<CompletionEn
});

const componentInfo = getComponentAtPosition(lang, document, tsDoc, position);
const attributeContext = componentInfo && getAttributeContextAtPosition(document, position);
const eventAndSlotLetCompletions = this.getEventAndSlotLetCompletions(
componentInfo,
document,
attributeContext,
wordRange
);

Expand Down Expand Up @@ -216,17 +219,19 @@ export class CompletionsProviderImpl implements CompletionsProvider<CompletionEn
) {
// Very likely false global completions inside component start tag -> narrow
const props =
componentInfo
?.getProps()
.map((entry) =>
this.componentInfoToCompletionEntry(
entry,
'',
CompletionItemKind.Field,
document,
wordRange
)
) || [];
(!attributeContext?.inValue &&
componentInfo
?.getProps()
.map((entry) =>
this.componentInfoToCompletionEntry(
entry,
'',
CompletionItemKind.Field,
document,
wordRange
)
)) ||
[];
return CompletionList.create(
[...eventAndSlotLetCompletions, ...props],
!!tsDoc.parserError
Expand Down Expand Up @@ -292,12 +297,17 @@ export class CompletionsProviderImpl implements CompletionsProvider<CompletionEn
private getEventAndSlotLetCompletions(
componentInfo: ComponentInfoProvider | null,
document: Document,
attributeContext: AttributeContext | null,
wordRange: { start: number; end: number }
): Array<AppCompletionItem<CompletionEntryWithIdentifier>> {
if (componentInfo === null) {
return [];
}

if (attributeContext?.inValue) {
return [];
}

return [
...componentInfo
.getEvents()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,20 @@ function test(useNewTransformation: boolean) {
]);
});

it("doesn't provide event completions inside attribute value", async () => {
const { completionProvider, document } = setup('component-events-completion.svelte');

const completions = await completionProvider.getCompletions(
document,
Position.create(5, 17),
{
triggerKind: CompletionTriggerKind.Invoked
}
);

assert.deepStrictEqual(completions, null);
});

it('provides event completions with correct text replacement span', async () => {
const { completionProvider, document } = setup('component-events-completion.svelte');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import CED from './component-events-event-dispatcher.svelte';
</script>

<CEI on:a />
<CEI on:a foo="" />
<CED on />