Skip to content

Commit

Permalink
fix(language-service): add null handling for script tag completion items
Browse files Browse the repository at this point in the history
close #4520
  • Loading branch information
johnsoncodehk committed Jul 4, 2024
1 parent 3194078 commit 614aed7
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions packages/language-service/lib/plugins/vue-sfc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,21 @@ export function create(): LanguageServicePlugin {
},

async provideCompletionItems(document, position, context, token) {
const result = await htmlPluginInstance.provideCompletionItems?.(document, position, context, token)
const result = await htmlPluginInstance.provideCompletionItems?.(document, position, context, token);
if (!result) {
return;
}
result.items = [
...result.items.filter(item => item.label !== '!DOCTYPE' && item.label !== 'Custom Blocks'),
createCompletionItemWithTs(result.items.find(item => item.label === 'script')!),
createCompletionItemWithTs(result.items.find(item => item.label === 'script setup')!),
]
result.items = result.items.filter(item => item.label !== '!DOCTYPE' && item.label !== 'Custom Blocks');
for (const scriptItem of result.items.filter(item => item.label === 'script' || item.label === 'script setup')) {
result.items.push({
...scriptItem,
label: scriptItem.label + ' lang="ts"',
textEdit: scriptItem.textEdit ? {
...scriptItem.textEdit,
newText: scriptItem.textEdit.newText + ' lang="ts"',
} : undefined,
});
}
return result;
},
};
Expand All @@ -198,14 +204,3 @@ export function create(): LanguageServicePlugin {
}
}
}

function createCompletionItemWithTs(base: vscode.CompletionItem): vscode.CompletionItem {
return {
...base,
label: base.label + ' lang="ts"',
textEdit: {
...base.textEdit!,
newText: base.textEdit!.newText + ' lang="ts"',
}
};
}

0 comments on commit 614aed7

Please sign in to comment.