diff --git a/extensions/html-language-features/client/src/customData.ts b/extensions/html-language-features/client/src/customData.ts index cc78f809548..248ad18672c 100644 --- a/extensions/html-language-features/client/src/customData.ts +++ b/extensions/html-language-features/client/src/customData.ts @@ -14,7 +14,7 @@ export function getCustomDataSource(toDispose: Disposable[]) { toDispose.push(extensions.onDidChange(_ => { const newPathsInExtensions = getCustomDataPathsFromAllExtensions(); - if (newPathsInExtensions.length !== pathsInExtensions.length || !newPathsInExtensions.every((val, idx) => val === pathsInExtensions[idx])) { + if (pathsInExtensions.size !== newPathsInExtensions.size || ![...pathsInExtensions].every(path => newPathsInExtensions.has(path))) { pathsInExtensions = newPathsInExtensions; onChange.fire(); } @@ -28,14 +28,14 @@ export function getCustomDataSource(toDispose: Disposable[]) { toDispose.push(workspace.onDidChangeTextDocument(e => { const path = e.document.uri.toString(); - if (pathsInExtensions.indexOf(path) || pathsInWorkspace.indexOf(path)) { + if (pathsInExtensions.has(path) || pathsInWorkspace.has(path)) { onChange.fire(); } })); return { get uris() { - return pathsInWorkspace.concat(pathsInExtensions); + return [...pathsInWorkspace].concat([...pathsInExtensions]); }, get onDidChange() { return onChange.event; @@ -44,10 +44,10 @@ export function getCustomDataSource(toDispose: Disposable[]) { } -function getCustomDataPathsInAllWorkspaces(): string[] { +function getCustomDataPathsInAllWorkspaces(): Set { const workspaceFolders = workspace.workspaceFolders; - const dataPaths: string[] = []; + const dataPaths = new Set(); if (!workspaceFolders) { return dataPaths; @@ -60,10 +60,10 @@ function getCustomDataPathsInAllWorkspaces(): string[] { const uri = Uri.parse(path); if (uri.scheme === 'file') { // only resolve file paths relative to extension - dataPaths.push(resolvePath(rootFolder, path).toString()); + dataPaths.add(resolvePath(rootFolder, path).toString()); } else { // others schemes - dataPaths.push(path); + dataPaths.add(path); } } } @@ -88,8 +88,8 @@ function getCustomDataPathsInAllWorkspaces(): string[] { return dataPaths; } -function getCustomDataPathsFromAllExtensions(): string[] { - const dataPaths: string[] = []; +function getCustomDataPathsFromAllExtensions(): Set { + const dataPaths = new Set(); for (const extension of extensions.all) { const customData = extension.packageJSON?.contributes?.html?.customData; if (Array.isArray(customData)) { @@ -97,10 +97,10 @@ function getCustomDataPathsFromAllExtensions(): string[] { const uri = Uri.parse(rp); if (uri.scheme === 'file') { // only resolve file paths relative to extension - dataPaths.push(joinPath(extension.extensionUri, rp).toString()); + dataPaths.add(joinPath(extension.extensionUri, rp).toString()); } else { // others schemes - dataPaths.push(rp); + dataPaths.add(rp); } } diff --git a/extensions/html-language-features/client/src/requests.ts b/extensions/html-language-features/client/src/requests.ts index 30c75595b7e..e5bc857dabd 100644 --- a/extensions/html-language-features/client/src/requests.ts +++ b/extensions/html-language-features/client/src/requests.ts @@ -21,18 +21,19 @@ export namespace FsReadDirRequest { export function serveFileSystemRequests(client: CommonLanguageClient, runtime: Runtime, subscriptions: { dispose(): any }[]) { subscriptions.push(client.onRequest(FsContentRequest.type, (param: { uri: string; encoding?: string; }) => { const uri = Uri.parse(param.uri); - if (uri.scheme === 'file' && runtime.fs) { - return runtime.fs.getContent(param.uri); - } - - return workspace.fs.readFile(uri).then(buffer => { - return new runtime.TextDecoder(param.encoding).decode(buffer); - }, () => { - // this path also considers TextDocumentContentProvider + if (uri.scheme === 'file') { + if (runtime.fs) { + return runtime.fs.getContent(param.uri); + } else { + return workspace.fs.readFile(uri).then(buffer => { + return new runtime.TextDecoder(param.encoding).decode(buffer); + }); + } + } else { return workspace.openTextDocument(uri).then(doc => { return doc.getText(); }); - }); + } })); subscriptions.push(client.onRequest(FsReadDirRequest.type, (uriString: string) => { const uri = Uri.parse(uriString);