From 87244e18ebf2dd790eb2731e9a8361c1dbe42a5d Mon Sep 17 00:00:00 2001 From: yoyo930021 Date: Thu, 26 Nov 2020 15:29:22 +0800 Subject: [PATCH] Fix #1336 --- .../src/embeddedSupport/vueDocumentRegionParser.ts | 6 +++++- test/lsp/features/diagnostics/issue-1336.test.ts | 10 ++++++++++ test/lsp/fixture/diagnostics/issue-1336.vue | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/lsp/features/diagnostics/issue-1336.test.ts create mode 100644 test/lsp/fixture/diagnostics/issue-1336.vue diff --git a/server/src/embeddedSupport/vueDocumentRegionParser.ts b/server/src/embeddedSupport/vueDocumentRegionParser.ts index 00f4646b77..f472ee80bf 100644 --- a/server/src/embeddedSupport/vueDocumentRegionParser.ts +++ b/server/src/embeddedSupport/vueDocumentRegionParser.ts @@ -23,6 +23,7 @@ export function parseVueDocumentRegions(document: TextDocument) { let lastAttributeName = ''; let languageIdFromType: LanguageId | '' = ''; const importedScripts: string[] = []; + let stakes = 0; let token = scanner.scan(); while (token !== TokenType.EOS) { @@ -48,8 +49,9 @@ export function parseVueDocumentRegions(document: TextDocument) { languageIdFromType = ''; break; case TokenType.StartTag: + stakes++; const tagName = scanner.getTokenText(); - if (tagName === 'template') { + if (tagName === 'template' && stakes === 1) { const templateRegion = scanTemplateRegion(scanner, text); if (templateRegion) { regions.push(templateRegion); @@ -75,7 +77,9 @@ export function parseVueDocumentRegions(document: TextDocument) { } lastAttributeName = ''; break; + case TokenType.StartTagSelfClose: case TokenType.EndTagClose: + stakes--; lastAttributeName = ''; languageIdFromType = ''; break; diff --git a/test/lsp/features/diagnostics/issue-1336.test.ts b/test/lsp/features/diagnostics/issue-1336.test.ts new file mode 100644 index 0000000000..fe578f55a2 --- /dev/null +++ b/test/lsp/features/diagnostics/issue-1336.test.ts @@ -0,0 +1,10 @@ +import { testNoDiagnostics } from '../../../diagnosticHelper'; +import { getDocUri } from '../../path'; + +describe('Should find no error when no root template element', () => { + const docUri = getDocUri('diagnostics/issue-1336.vue'); + + it('shows no diagnostics error without root template element area', async () => { + await testNoDiagnostics(docUri); + }); +}); diff --git a/test/lsp/fixture/diagnostics/issue-1336.vue b/test/lsp/fixture/diagnostics/issue-1336.vue new file mode 100644 index 0000000000..aa0e964c7c --- /dev/null +++ b/test/lsp/fixture/diagnostics/issue-1336.vue @@ -0,0 +1,14 @@ + + + +` ``vue + + + +` `` +