[html] clean up request service: add CustomDataRequestService #135459

This commit is contained in:
Martin Aeschlimann
2021-11-29 11:25:04 +01:00
parent 414c15079b
commit 3d8b5674c7
19 changed files with 95 additions and 178 deletions

View File

@@ -6,7 +6,7 @@
import { createConnection, Connection, Disposable } from 'vscode-languageserver/node';
import { formatError } from '../utils/runner';
import { RuntimeEnvironment, startServer } from '../htmlServer';
import { getNodeFSRequestService } from './nodeFs';
import { getNodeFileFS } from './nodeFs';
// Create a connection for the server.
@@ -30,7 +30,7 @@ const runtime: RuntimeEnvironment = {
return { dispose: () => clearTimeout(handle) };
}
},
file: getNodeFSRequestService()
fileFs: getNodeFileFS()
};
startServer(connection, runtime);

View File

@@ -3,32 +3,19 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { RequestService, getScheme } from '../requests';
import { FileSystemProvider, getScheme } from '../requests';
import { URI as Uri } from 'vscode-uri';
import * as fs from 'fs';
import { FileType } from 'vscode-css-languageservice';
export function getNodeFSRequestService(): RequestService {
export function getNodeFileFS(): FileSystemProvider {
function ensureFileUri(location: string) {
if (getScheme(location) !== 'file') {
throw new Error('fileRequestService can only handle file URLs');
throw new Error('fileSystemProvider can only handle file URLs');
}
}
return {
getContent(location: string, encoding?: string) {
ensureFileUri(location);
return new Promise((c, e) => {
const uri = Uri.parse(location);
fs.readFile(uri.fsPath, encoding, (err, buf) => {
if (err) {
return e(err);
}
c(buf.toString());
});
});
},
stat(location: string) {
ensureFileUri(location);
return new Promise((c, e) => {