mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 00:28:52 +01:00
use regex, not Uri.parse, to detect custom scheme
This commit is contained in:
@@ -7,6 +7,8 @@ import { Uri, workspace } from 'vscode';
|
||||
import { RequestType, CommonLanguageClient } from 'vscode-languageclient';
|
||||
import { Runtime } from './htmlClient';
|
||||
|
||||
export const uriScheme = /^(?<scheme>\w[\w\d+.-]*):/;
|
||||
|
||||
export namespace FsContentRequest {
|
||||
export const type: RequestType<{ uri: string; encoding?: string; }, string, any> = new RequestType('fs/content');
|
||||
}
|
||||
@@ -20,34 +22,34 @@ 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') {
|
||||
const uri = param.uri.match(uriScheme);
|
||||
if (uri?.groups?.scheme === 'file') {
|
||||
if (runtime.fs) {
|
||||
return runtime.fs.getContent(param.uri);
|
||||
} else {
|
||||
return workspace.fs.readFile(uri).then(buffer => {
|
||||
return workspace.fs.readFile(Uri.parse(param.uri)).then(buffer => {
|
||||
return new runtime.TextDecoder(param.encoding).decode(buffer);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return workspace.openTextDocument(uri).then(doc => {
|
||||
return workspace.openTextDocument(Uri.parse(param.uri)).then(doc => {
|
||||
return doc.getText();
|
||||
});
|
||||
}
|
||||
}));
|
||||
subscriptions.push(client.onRequest(FsReadDirRequest.type, (uriString: string) => {
|
||||
const uri = Uri.parse(uriString);
|
||||
if (uri.scheme === 'file' && runtime.fs) {
|
||||
const uri = uriString.match(uriScheme);
|
||||
if (uri?.groups?.scheme === 'file' && runtime.fs) {
|
||||
return runtime.fs.readDirectory(uriString);
|
||||
}
|
||||
return workspace.fs.readDirectory(uri);
|
||||
return workspace.fs.readDirectory(Uri.parse(uriString));
|
||||
}));
|
||||
subscriptions.push(client.onRequest(FsStatRequest.type, (uriString: string) => {
|
||||
const uri = Uri.parse(uriString);
|
||||
if (uri.scheme === 'file' && runtime.fs) {
|
||||
const uri = uriString.match(uriScheme);
|
||||
if (uri?.groups?.scheme === 'file' && runtime.fs) {
|
||||
return runtime.fs.stat(uriString);
|
||||
}
|
||||
return workspace.fs.stat(uri);
|
||||
return workspace.fs.stat(Uri.parse(uriString));
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user