mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 17:48:56 +01:00
Simplify uri transformer creation
This commit is contained in:
@@ -16,18 +16,19 @@ import product from 'vs/platform/product/common/product';
|
||||
import { MessageType, createMessageOfType, isMessageOfType, IExtHostSocketMessage, IExtHostReadyMessage, IExtHostReduceGraceTimeMessage, ExtensionHostExitCode, IExtensionHostInitData } from 'vs/workbench/services/extensions/common/extensionHostProtocol';
|
||||
import { ExtensionHostMain, IExitFn } from 'vs/workbench/api/common/extensionHostMain';
|
||||
import { VSBuffer } from 'vs/base/common/buffer';
|
||||
import { IURITransformer, URITransformer, IRawURITransformer } from 'vs/base/common/uriIpc';
|
||||
import { IURITransformer } from 'vs/base/common/uriIpc';
|
||||
import { Promises } from 'vs/base/node/pfs';
|
||||
import { realpath } from 'vs/base/node/extpath';
|
||||
import { IHostUtils } from 'vs/workbench/api/common/extHostExtensionService';
|
||||
import { ProcessTimeRunOnceScheduler } from 'vs/base/common/async';
|
||||
import { boolean } from 'vs/editor/common/config/editorOptions';
|
||||
import { createURITransformer } from 'vs/workbench/api/node/uriTransformer';
|
||||
|
||||
import 'vs/workbench/api/common/extHost.common.services';
|
||||
import 'vs/workbench/api/node/extHost.node.services';
|
||||
|
||||
interface ParsedExtHostArgs {
|
||||
uriTransformerPath?: string;
|
||||
transformURIs?: boolean;
|
||||
skipWorkspaceStorageLock?: boolean;
|
||||
useHostProxy?: boolean;
|
||||
}
|
||||
@@ -44,10 +45,8 @@ interface ParsedExtHostArgs {
|
||||
})();
|
||||
|
||||
const args = minimist(process.argv.slice(2), {
|
||||
string: [
|
||||
'uriTransformerPath'
|
||||
],
|
||||
boolean: [
|
||||
'transformURIs',
|
||||
'skipWorkspaceStorageLock',
|
||||
'useHostProxy'
|
||||
]
|
||||
@@ -349,14 +348,8 @@ export async function startExtensionHostProcess(): Promise<void> {
|
||||
|
||||
// Attempt to load uri transformer
|
||||
let uriTransformer: IURITransformer | null = null;
|
||||
if (initData.remote.authority && args.uriTransformerPath) {
|
||||
try {
|
||||
const rawURITransformerFactory = <any>require.__$__nodeRequire(args.uriTransformerPath);
|
||||
const rawURITransformer = <IRawURITransformer>rawURITransformerFactory(initData.remote.authority);
|
||||
uriTransformer = new URITransformer(rawURITransformer);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
if (initData.remote.authority && args.transformURIs) {
|
||||
uriTransformer = createURITransformer(initData.remote.authority);
|
||||
}
|
||||
|
||||
const extensionHostMain = new ExtensionHostMain(
|
||||
|
||||
51
src/vs/workbench/api/node/uriTransformer.ts
Normal file
51
src/vs/workbench/api/node/uriTransformer.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { UriParts, IRawURITransformer, URITransformer, IURITransformer } from 'vs/base/common/uriIpc';
|
||||
|
||||
/**
|
||||
* ```
|
||||
* --------------------------------
|
||||
* | UI SIDE | AGENT SIDE |
|
||||
* |---------------|--------------|
|
||||
* | vscode-remote | file |
|
||||
* | file | vscode-local |
|
||||
* --------------------------------
|
||||
* ```
|
||||
*/
|
||||
function createRawURITransformer(remoteAuthority: string): IRawURITransformer {
|
||||
return {
|
||||
transformIncoming: (uri: UriParts): UriParts => {
|
||||
if (uri.scheme === 'vscode-remote') {
|
||||
return { scheme: 'file', path: uri.path, query: uri.query, fragment: uri.fragment };
|
||||
}
|
||||
if (uri.scheme === 'file') {
|
||||
return { scheme: 'vscode-local', path: uri.path, query: uri.query, fragment: uri.fragment };
|
||||
}
|
||||
return uri;
|
||||
},
|
||||
transformOutgoing: (uri: UriParts): UriParts => {
|
||||
if (uri.scheme === 'file') {
|
||||
return { scheme: 'vscode-remote', authority: remoteAuthority, path: uri.path, query: uri.query, fragment: uri.fragment };
|
||||
}
|
||||
if (uri.scheme === 'vscode-local') {
|
||||
return { scheme: 'file', path: uri.path, query: uri.query, fragment: uri.fragment };
|
||||
}
|
||||
return uri;
|
||||
},
|
||||
transformOutgoingScheme: (scheme: string): string => {
|
||||
if (scheme === 'file') {
|
||||
return 'vscode-remote';
|
||||
} else if (scheme === 'vscode-local') {
|
||||
return 'file';
|
||||
}
|
||||
return scheme;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function createURITransformer(remoteAuthority: string): IURITransformer {
|
||||
return new URITransformer(createRawURITransformer(remoteAuthority));
|
||||
}
|
||||
Reference in New Issue
Block a user