Skip to content

Commit

Permalink
feat(html): add useDefaultDataProvider option (#58)
Browse files Browse the repository at this point in the history
Co-authored-by: Johnson Chu <[email protected]>
  • Loading branch information
dongwa and johnsoncodehk authored Oct 6, 2023
1 parent d5bbfb1 commit a7ffc4f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const triggerCharacters = ['.', ':', '<', '"', '=', '/'];
export function create(options: {
validLang?: string;
disableCustomData?: boolean;
useDefaultDataProvider?: boolean;
} = {}): Service<Provide> {
return (context): ReturnType<Service<Provide>> => {

Expand All @@ -46,6 +47,7 @@ export function create(options: {
let shouldUpdateCustomData = true;
let customData: html.IHTMLDataProvider[] = [];
let extraData: html.IHTMLDataProvider[] = [];
const { useDefaultDataProvider = true } = options;

const fileSystemProvider: html.FileSystemProvider = {
stat: async uri => await context.env.fs?.stat(uri) ?? {
Expand Down Expand Up @@ -299,13 +301,13 @@ export function create(options: {
if (shouldUpdateCustomData && !options.disableCustomData) {
shouldUpdateCustomData = false;
customData = await getCustomData();
htmlLs.setDataProviders(true, [...customData, ...extraData]);
htmlLs.setDataProviders(useDefaultDataProvider, [...customData, ...extraData]);
}
}

function updateExtraCustomData(data: html.IHTMLDataProvider[]) {
extraData = data;
htmlLs.setDataProviders(true, [...customData, ...extraData]);
htmlLs.setDataProviders(useDefaultDataProvider, [...customData, ...extraData]);
}

async function getCustomData() {
Expand Down

0 comments on commit a7ffc4f

Please sign in to comment.