/
vue-sfc-styles.ts
36 lines (30 loc) · 869 Bytes
/
vue-sfc-styles.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { FileCapabilities, FileRangeCapabilities } from '@volar/language-core';
import { VueLanguagePlugin } from '../types';
const plugin: VueLanguagePlugin = () => {
return {
version: 1,
getEmbeddedFileNames(fileName, sfc) {
const names: string[] = [];
for (let i = 0; i < sfc.styles.length; i++) {
const style = sfc.styles[i];
names.push(fileName + '.style_' + i + '.' + style.lang);
}
return names;
},
resolveEmbeddedFile(_fileName, sfc, embeddedFile) {
const match = embeddedFile.fileName.match(/^(.*)\.style_(\d+)\.([^.]+)$/);
if (match) {
const index = parseInt(match[2]);
const style = sfc.styles[index];
embeddedFile.capabilities = FileCapabilities.full;
embeddedFile.content.push([
style.content,
style.name,
0,
FileRangeCapabilities.full,
]);
}
},
};
};
export = plugin;