mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
avoid realpathSync, #16388
This commit is contained in:
@@ -41,7 +41,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
|
||||
import { CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import * as vscode from 'vscode';
|
||||
import * as paths from 'vs/base/common/paths';
|
||||
import { realpathSync } from 'fs';
|
||||
import { realpath } from 'fs';
|
||||
import { MainContext, ExtHostContext, InstanceCollection, IInitData } from './extHost.protocol';
|
||||
import * as languageConfiguration from 'vs/editor/common/modes/languageConfiguration';
|
||||
|
||||
@@ -436,22 +436,39 @@ class Extension<T> implements vscode.Extension<T> {
|
||||
}
|
||||
}
|
||||
|
||||
export function defineAPI(factory: IExtensionApiFactory, extensionService: ExtHostExtensionService): void {
|
||||
export function initializeExtensionApi(extensionService: ExtHostExtensionService, apiFactory: IExtensionApiFactory): TPromise<void> {
|
||||
return createExtensionPathIndex(extensionService).then(trie => defineAPI(apiFactory, trie));
|
||||
}
|
||||
|
||||
function createExtensionPathIndex(extensionService: ExtHostExtensionService): TPromise<TrieMap<IExtensionDescription>> {
|
||||
|
||||
// create trie to enable fast 'filename -> extension id' look up
|
||||
const trie = new TrieMap<IExtensionDescription>(TrieMap.PathSplitter);
|
||||
const extensions = extensionService.getAllExtensionDescriptions().map(ext => {
|
||||
if (!ext.main) {
|
||||
return;
|
||||
}
|
||||
return new TPromise((resolve, reject) => {
|
||||
realpath(ext.extensionFolderPath, (err, path) => {
|
||||
if (err) {
|
||||
trie.insert(path, ext);
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(void 0);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return TPromise.join(extensions).then(() => trie);
|
||||
}
|
||||
|
||||
function defineAPI(factory: IExtensionApiFactory, extensionPaths: TrieMap<IExtensionDescription>): void {
|
||||
|
||||
// each extension is meant to get its own api implementation
|
||||
const extApiImpl: { [id: string]: typeof vscode } = Object.create(null);
|
||||
let defaultApiImpl: typeof vscode;
|
||||
|
||||
// create trie to enable fast 'filename -> extension id' look up
|
||||
const trie = new TrieMap<IExtensionDescription>(TrieMap.PathSplitter);
|
||||
const extensions = extensionService.getAllExtensionDescriptions();
|
||||
for (const ext of extensions) {
|
||||
if (ext.main) {
|
||||
const path = realpathSync(ext.extensionFolderPath);
|
||||
trie.insert(path, ext);
|
||||
}
|
||||
}
|
||||
|
||||
const node_module = <any>require.__$__nodeRequire('module');
|
||||
const original = node_module._load;
|
||||
node_module._load = function load(request, parent, isMain) {
|
||||
@@ -460,7 +477,7 @@ export function defineAPI(factory: IExtensionApiFactory, extensionService: ExtHo
|
||||
}
|
||||
|
||||
// get extension id from filename and api for extension
|
||||
const ext = trie.findSubstr(parent.filename);
|
||||
const ext = extensionPaths.findSubstr(parent.filename);
|
||||
if (ext) {
|
||||
let apiImpl = extApiImpl[ext.id];
|
||||
if (!apiImpl) {
|
||||
|
||||
Reference in New Issue
Block a user