Skip to content

Commit b640868

Browse files
authored
[perf]: early return in getCompletions if in style or script tag (#2899)
* early return in getCompletions if in style or script tag * Create big-cheetahs-admire.md * format
1 parent b6ebbd8 commit b640868

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

.changeset/big-cheetahs-admire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-language-server': patch
3+
---
4+
5+
[perf]: move return statement in `getCompletions` so it returns immediately if possible

packages/language-server/src/plugins/svelte/features/getCompletions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ export function getCompletions(
3434
svelteDoc: SvelteDocument,
3535
position: Position
3636
): CompletionList | null {
37-
const offset = svelteDoc.offsetAt(position);
37+
if (inStyleOrScript(svelteDoc, position)) {
38+
return null;
39+
}
3840

41+
const offset = svelteDoc.offsetAt(position);
3942
const lastCharactersBeforePosition = svelteDoc
4043
.getText()
4144
// use last 10 characters, should cover 99% of all cases
4245
.substr(Math.max(offset - 10, 0), Math.min(offset, 10));
4346
const precededByOpeningBracket = /[\s\S]*{\s*[#:/@]\w*$/.test(lastCharactersBeforePosition);
44-
if (inStyleOrScript(svelteDoc, position)) {
45-
return null;
46-
}
4747

4848
if (precededByOpeningBracket) {
4949
return getTagCompletionsWithinMoustache();

0 commit comments

Comments
 (0)