Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ import moo from 'moo'
import Cache from 'tmp-cache'
import { getTextWithoutComments } from './doc'

export type LanguageBoundary = { type: 'html' | 'js' | 'css' | string; range: Range }
export type LanguageBoundary = { type: 'html' | 'js' | 'css' | (string & {}); range: Range }

let htmlScriptTypes = [
// https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html#option-1-use-script-tag
'text/html',
// https://vuejs.org/guide/essentials/component-basics.html#dom-template-parsing-caveats
'text/x-template',
// https://github.com/tailwindlabs/tailwindcss-intellisense/issues/722
'text/x-handlebars-template',
]

let text = { text: { match: /[^]/, lineBreaks: true } }

Expand All @@ -30,6 +39,8 @@ let states = {
jsBlockEnd: { match: '/>', pop: 1 },
langAttrStartDouble: { match: 'lang="', push: 'langAttrDouble' },
langAttrStartSingle: { match: "lang='", push: 'langAttrSingle' },
typeAttrStartDouble: { match: 'type="', push: 'typeAttrDouble' },
typeAttrStartSingle: { match: "type='", push: 'typeAttrSingle' },
attrStartDouble: { match: '"', push: 'attrDouble' },
attrStartSingle: { match: "'", push: 'attrSingle' },
interp: { match: '{', push: 'interp' },
Expand All @@ -48,6 +59,14 @@ let states = {
langAttrEnd: { match: "'", pop: 1 },
lang: { match: /[^']+/, lineBreaks: true },
},
typeAttrDouble: {
langAttrEnd: { match: '"', pop: 1 },
type: { match: /[^"]+/, lineBreaks: true },
},
typeAttrSingle: {
langAttrEnd: { match: "'", pop: 1 },
type: { match: /[^']+/, lineBreaks: true },
},
attrDouble: {
attrEnd: { match: '"', pop: 1 },
...text,
Expand Down Expand Up @@ -156,6 +175,8 @@ export function getLanguageBoundaries(
boundaries.push({ type: defaultType, range: { start: position, end: undefined } })
} else if (token.type === 'lang') {
boundaries[boundaries.length - 1].type = token.text
} else if (token.type === 'type' && htmlScriptTypes.includes(token.text)) {
boundaries[boundaries.length - 1].type = 'html'
}
}
offset += token.text.length
Expand Down