Skip to content

Commit

Permalink
Fix #1336
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Nov 26, 2020
1 parent 0993014 commit 87244e1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/src/embeddedSupport/vueDocumentRegionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -75,7 +77,9 @@ export function parseVueDocumentRegions(document: TextDocument) {
}
lastAttributeName = '';
break;
case TokenType.StartTagSelfClose:
case TokenType.EndTagClose:
stakes--;
lastAttributeName = '';
languageIdFromType = '';
break;
Expand Down
10 changes: 10 additions & 0 deletions test/lsp/features/diagnostics/issue-1336.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
14 changes: 14 additions & 0 deletions test/lsp/fixture/diagnostics/issue-1336.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<div>hello world</div>
</template>

<docs>
` ``vue
<foo>
<template>
<div>1</div>
<div>2</div>
</template>
</foo>
` ``
</docs>

0 comments on commit 87244e1

Please sign in to comment.