mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 09:38:38 +01:00
[html] clean up request service: add CustomDataRequestService #135459
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user