Skip to content
Open
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
29 changes: 25 additions & 4 deletions packages/language-service/lib/plugins/vue-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
convertCompletionInfo,
} from 'volar-service-typescript/lib/utils/lspConverters.js';
import * as html from 'vscode-html-languageservice';
import { URI } from 'vscode-uri';
import { URI, Utils } from 'vscode-uri';
import type { ComponentMeta, PropertyMeta } from '../../../component-meta';
import { loadModelModifiersData, loadTemplateData } from '../data';
import { format } from '../htmlFormatter';
Expand Down Expand Up @@ -55,6 +55,7 @@ interface TagInfo {
meta: ComponentMeta | undefined | null;
}

let htmlCustomData: html.IHTMLDataProvider[] | undefined = undefined;
let builtInData: html.HTMLDataV1 | undefined;
let modelData: html.HTMLDataV1 | undefined;

Expand Down Expand Up @@ -115,7 +116,7 @@ export function create(
useDefaultDataProvider: false,
getDocumentContext,
getCustomData() {
return htmlData;
return htmlCustomData ? [...htmlCustomData, ...htmlData] : htmlData;
},
onDidChangeCustomData,
})
Expand All @@ -124,7 +125,7 @@ export function create(
useDefaultDataProvider: false,
getDocumentContext,
getCustomData() {
return htmlData;
return htmlCustomData ? [...htmlCustomData, ...htmlData] : htmlData;
},
onDidChangeCustomData,
});
Expand Down Expand Up @@ -210,7 +211,6 @@ export function create(

builtInData ??= loadTemplateData(context.env.locale ?? 'en');
modelData ??= loadModelModifiersData(context.env.locale ?? 'en');

// https://vuejs.org/api/built-in-directives.html#v-on
const vOnModifiers = extractDirectiveModifiers(builtInData.globalAttributes?.find(x => x.name === 'v-on'));
// https://vuejs.org/api/built-in-directives.html#v-bind
Expand Down Expand Up @@ -615,6 +615,26 @@ export function create(
return { result, ...lastSync };
}

async function loadHtmlCustomData(): Promise<html.IHTMLDataProvider[]> {
if (htmlCustomData) { return htmlCustomData }
const newData: html.IHTMLDataProvider[] = [];
const customData: string[] = await context.env.getConfiguration?.('html.customData') ?? []
const workspaceFolder = context.env.workspaceFolders?.[0] ?? undefined
for (const customDataPath of customData) {
try {
const uri = Utils.resolvePath(URI.parse(workspaceFolder?.toString() ?? "."), customDataPath);
const json = await context.env.fs?.readFile?.(uri, "utf-8");
if (json) {
const data = JSON.parse(json) as html.HTMLDataV1
newData.push(html.newHTMLDataProvider(customDataPath, data));
}
} catch(e) {
continue
}
}
return newData
}

async function provideHtmlData(
sourceDocumentUri: URI,
root: VueVirtualCode,
Expand All @@ -634,6 +654,7 @@ export function create(

const tasks: Promise<void>[] = [];
const tagDataMap = new Map<string, TagInfo>();
htmlCustomData = await loadHtmlCustomData()

updateExtraCustomData([
{
Expand Down
Loading