Skip to content

Commit 42ad255

Browse files
marufrasullyvoicis
andauthored
fix: empty xml file (#633)
* fix: empty xml file * fix: test and change set --------- Co-authored-by: Davis Voicescuks <davis.voicescuks@sap.com>
1 parent b7cf772 commit 42ad255

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

.changeset/blue-needles-peel.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@ui5-language-assistant/language-server": patch
3+
"vscode-ui5-language-assistant": patch
4+
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
5+
---
6+
7+
No completion items for empty file

packages/language-server/src/completion-items.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export function getCompletionItems(opts: {
4242
const documentText = opts.document.getText();
4343
const { cst, tokenVector } = parse(documentText);
4444
const ast = buildAst(cst as DocumentCstNode, tokenVector);
45+
if (!ast.rootElement) {
46+
return [];
47+
}
4548
const suggestions = getXMLViewCompletions({
4649
context: opts.context,
4750
offset: opts.document.offsetAt(opts.textDocumentPosition.position),

packages/language-server/test/unit/completion-items.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ describe("the UI5 language assistant Code Completion Services", () => {
3636
appContext = getDefaultContext(ui5SemanticModel);
3737
});
3838

39+
it("no completion items for empty file - no error", () => {
40+
const xmlSnippet = `⇶`;
41+
const suggestions = getSuggestions(xmlSnippet, appContext);
42+
expect(suggestions).toStrictEqual([]);
43+
});
44+
3945
it("will get completion values for UI5 property", () => {
4046
const xmlSnippet = `<mvc:View
4147
xmlns:mvc="sap.ui.core.mvc"

0 commit comments

Comments
 (0)