mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 17:52:34 -05:00
This reverts commit d15a3fcc98.
This commit is contained in:
@@ -21,33 +21,13 @@ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteA
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { FileService } from 'vs/workbench/services/files/common/fileService';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { WorkspaceService } from 'vs/workbench/services/configuration/browser/configurationService';
|
||||
import { ConfigurationCache } from 'vs/workbench/services/configuration/browser/configurationCache';
|
||||
import { ConfigurationFileService } from 'vs/workbench/services/configuration/common/configuration';
|
||||
import { WebResources } from 'vs/workbench/browser/web.resources';
|
||||
|
||||
interface IWindowConfiguration {
|
||||
settingsUri: URI;
|
||||
remoteAuthority: string;
|
||||
folderUri?: URI;
|
||||
workspaceUri?: URI;
|
||||
}
|
||||
|
||||
class CodeRendererMain extends Disposable {
|
||||
|
||||
private workbench: Workbench;
|
||||
|
||||
constructor(private readonly configuration: IWindowConfiguration) {
|
||||
super();
|
||||
}
|
||||
|
||||
async open(): Promise<void> {
|
||||
const services = await this.initServices();
|
||||
const services = this.initServices();
|
||||
|
||||
await domContentLoaded();
|
||||
mark('willStartWorkbench');
|
||||
@@ -62,9 +42,6 @@ class CodeRendererMain extends Disposable {
|
||||
// Layout
|
||||
this._register(addDisposableListener(window, EventType.RESIZE, () => this.workbench.layout()));
|
||||
|
||||
// Resource Loading
|
||||
this._register(new WebResources(<IFileService>services.serviceCollection.get(IFileService)));
|
||||
|
||||
// Workbench Lifecycle
|
||||
this._register(this.workbench.onShutdown(() => this.dispose()));
|
||||
|
||||
@@ -72,7 +49,7 @@ class CodeRendererMain extends Disposable {
|
||||
this.workbench.startup();
|
||||
}
|
||||
|
||||
private async initServices(): Promise<{ serviceCollection: ServiceCollection, logService: ILogService }> {
|
||||
private initServices(): { serviceCollection: ServiceCollection, logService: ILogService } {
|
||||
const serviceCollection = new ServiceCollection();
|
||||
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
@@ -85,7 +62,7 @@ class CodeRendererMain extends Disposable {
|
||||
serviceCollection.set(ILogService, logService);
|
||||
|
||||
// Environment
|
||||
const environmentService = this.createEnvironmentService();
|
||||
const environmentService = new SimpleWorkbenchEnvironmentService();
|
||||
serviceCollection.set(IWorkbenchEnvironmentService, environmentService);
|
||||
|
||||
// Product
|
||||
@@ -110,101 +87,12 @@ class CodeRendererMain extends Disposable {
|
||||
fileService.registerProvider(Schemas.vscodeRemote, remoteFileSystemProvider);
|
||||
}
|
||||
|
||||
const payload = await this.resolveWorkspaceInitializationPayload();
|
||||
|
||||
await Promise.all([
|
||||
this.createWorkspaceService(payload, fileService, remoteAgentService, logService).then(service => {
|
||||
|
||||
// Workspace
|
||||
serviceCollection.set(IWorkspaceContextService, service);
|
||||
|
||||
// Configuration
|
||||
serviceCollection.set(IConfigurationService, service);
|
||||
|
||||
return service;
|
||||
}),
|
||||
]);
|
||||
|
||||
return { serviceCollection, logService };
|
||||
}
|
||||
|
||||
private createEnvironmentService(): IWorkbenchEnvironmentService {
|
||||
const environmentService = new SimpleWorkbenchEnvironmentService();
|
||||
environmentService.appRoot = '/web/';
|
||||
environmentService.args = { _: [] };
|
||||
environmentService.appSettingsHome = '/web/settings';
|
||||
environmentService.settingsResource = this.configuration.settingsUri;
|
||||
environmentService.appKeybindingsPath = '/web/settings/keybindings.json';
|
||||
environmentService.logsPath = '/web/logs';
|
||||
environmentService.debugExtensionHost = {
|
||||
port: null,
|
||||
break: false
|
||||
};
|
||||
return environmentService;
|
||||
}
|
||||
|
||||
private async createWorkspaceService(payload: IWorkspaceInitializationPayload, fileService: FileService, remoteAgentService: IRemoteAgentService, logService: ILogService): Promise<WorkspaceService> {
|
||||
|
||||
const workspaceService = new WorkspaceService({ userSettingsResource: this.configuration.settingsUri, remoteAuthority: this.configuration.remoteAuthority, configurationCache: new ConfigurationCache() }, new ConfigurationFileService(fileService), remoteAgentService);
|
||||
|
||||
try {
|
||||
await workspaceService.initialize(payload);
|
||||
|
||||
return workspaceService;
|
||||
} catch (error) {
|
||||
onUnexpectedError(error);
|
||||
logService.error(error);
|
||||
|
||||
return workspaceService;
|
||||
}
|
||||
}
|
||||
|
||||
private async resolveWorkspaceInitializationPayload(): Promise<IWorkspaceInitializationPayload> {
|
||||
|
||||
const hash = (uri: URI) => {
|
||||
return crypto.subtle.digest('SHA-1', new TextEncoder().encode(uri.toString())).then(buffer => {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#Converting_a_digest_to_a_hex_string
|
||||
return Array.prototype.map.call(new Uint8Array(buffer), (value: number) => `00${value.toString(16)}`.slice(-2)).join('');
|
||||
});
|
||||
};
|
||||
|
||||
// Multi-root workspace
|
||||
if (this.configuration.workspaceUri) {
|
||||
const id = await hash(this.configuration.workspaceUri);
|
||||
return { id, configPath: this.configuration.workspaceUri };
|
||||
}
|
||||
|
||||
// Single-folder workspace
|
||||
if (this.configuration.folderUri) {
|
||||
const id = await hash(this.configuration.folderUri);
|
||||
return { id, folder: this.configuration.folderUri };
|
||||
}
|
||||
|
||||
return { id: 'empty-window' };
|
||||
}
|
||||
}
|
||||
|
||||
export interface IWindowConfigurationContents {
|
||||
settingsPath: string;
|
||||
folderPath?: string;
|
||||
workspacePath?: string;
|
||||
}
|
||||
export function main(): Promise<void> {
|
||||
const renderer = new CodeRendererMain();
|
||||
|
||||
export function main(windowConfigurationContents: IWindowConfigurationContents): Promise<void> {
|
||||
const windowConfiguration: IWindowConfiguration = {
|
||||
settingsUri: toResource(windowConfigurationContents.settingsPath),
|
||||
folderUri: windowConfigurationContents.folderPath ? toResource(windowConfigurationContents.folderPath) : undefined,
|
||||
workspaceUri: windowConfigurationContents.workspacePath ? toResource(windowConfigurationContents.workspacePath) : undefined,
|
||||
remoteAuthority: document.location.host
|
||||
};
|
||||
const renderer = new CodeRendererMain(windowConfiguration);
|
||||
return renderer.open();
|
||||
}
|
||||
|
||||
function toResource(path: string): URI {
|
||||
return URI.from({
|
||||
scheme: Schemas.vscodeRemote,
|
||||
authority: document.location.host,
|
||||
path
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user