提交 24fbd1f5 编写于 作者: J Johannes Rieken

add $acceptWorkspaceData to push new info about open folders, #28526

上级 0ace0d0f
......@@ -13,39 +13,41 @@ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfile
import { ICommonCodeEditor, isCommonCodeEditor } from 'vs/editor/common/editorCommon';
import { bulkEdit, IResourceEdit } from 'vs/editor/common/services/bulkEdit';
import { TPromise } from 'vs/base/common/winjs.base';
import { Uri } from 'vscode';
import { MainThreadWorkspaceShape } from '../node/extHost.protocol';
import { MainThreadWorkspaceShape, ExtHostWorkspaceShape, ExtHostContext } from '../node/extHost.protocol';
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
import { IFileService } from 'vs/platform/files/common/files';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { IDisposable } from 'vs/base/common/lifecycle';
export class MainThreadWorkspace extends MainThreadWorkspaceShape {
private _activeSearches: { [id: number]: TPromise<Uri[]> } = Object.create(null);
private _searchService: ISearchService;
private _contextService: IWorkspaceContextService;
private _textFileService: ITextFileService;
private _editorService: IWorkbenchEditorService;
private _textModelResolverService: ITextModelResolverService;
private _fileService: IFileService;
private readonly _toDispose: IDisposable[] = [];
private readonly _activeSearches: { [id: number]: TPromise<URI[]> } = Object.create(null);
private readonly _proxy: ExtHostWorkspaceShape;
constructor(
@ISearchService searchService: ISearchService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@ITextFileService textFileService: ITextFileService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@ITextModelResolverService textModelResolverService: ITextModelResolverService,
@IFileService fileService: IFileService
@ISearchService private readonly _searchService: ISearchService,
@IWorkspaceContextService private readonly _contextService: IWorkspaceContextService,
@ITextFileService private readonly _textFileService: ITextFileService,
@IWorkbenchEditorService private readonly _editorService: IWorkbenchEditorService,
@ITextModelResolverService private readonly _textModelResolverService: ITextModelResolverService,
@IFileService private readonly _fileService: IFileService,
@IThreadService threadService: IThreadService
) {
super();
this._proxy = threadService.get(ExtHostContext.ExtHostWorkspace);
this._contextService.onDidChangeFolders(this._onDidChangeWorkspace, this, this._toDispose);
}
// --- workspace ---
this._searchService = searchService;
this._contextService = contextService;
this._textFileService = textFileService;
this._editorService = editorService;
this._fileService = fileService;
this._textModelResolverService = textModelResolverService;
private _onDidChangeWorkspace(folders: URI[]): void {
this._proxy.$acceptWorkspaceData(folders);
}
// --- search ---
$startSearch(include: string, exclude: string, maxResults: number, requestId: number): Thenable<URI[]> {
const workspace = this._contextService.getWorkspace();
if (!workspace) {
......@@ -84,6 +86,8 @@ export class MainThreadWorkspace extends MainThreadWorkspaceShape {
return undefined;
}
// --- save & edit resources ---
$saveAll(includeUntitled?: boolean): Thenable<boolean> {
return this._textFileService.saveAll(includeUntitled).then(result => {
return result.results.every(each => each.success === true);
......
......@@ -91,6 +91,7 @@ export function createApiFactory(
const extHostTerminalService = col.define(ExtHostContext.ExtHostTerminalService).set<ExtHostTerminalService>(new ExtHostTerminalService(threadService));
const extHostSCM = col.define(ExtHostContext.ExtHostSCM).set<ExtHostSCM>(new ExtHostSCM(threadService, extHostCommands));
const extHostTask = col.define(ExtHostContext.ExtHostTask).set<ExtHostTask>(new ExtHostTask(threadService));
const extHostWorkspace = col.define(ExtHostContext.ExtHostWorkspace).set<ExtHostWorkspace>(new ExtHostWorkspace(threadService, initData.workspace && [initData.workspace.resource]));
col.define(ExtHostContext.ExtHostExtensionService).set(extensionService);
col.finish(false, threadService);
......@@ -99,8 +100,6 @@ export function createApiFactory(
const extHostStatusBar = new ExtHostStatusBar(threadService);
const extHostProgress = new ExtHostProgress(threadService.get(MainContext.MainThreadProgress));
const extHostOutputService = new ExtHostOutputService(threadService);
const workspacePath = initData.workspace ? initData.workspace.resource.fsPath : undefined;
const extHostWorkspace = new ExtHostWorkspace(threadService, workspacePath);
const extHostLanguages = new ExtHostLanguages(threadService);
// Register API-ish commands
......
......@@ -404,6 +404,10 @@ export abstract class ExtHostTreeViewsShape {
$getChildren(treeViewId: string, treeItemHandle: number): TPromise<ITreeItem[]> { throw ni(); }
}
export abstract class ExtHostWorkspaceShape {
$acceptWorkspaceData(folders: URI[]): void { throw ni(); }
}
export abstract class ExtHostExtensionServiceShape {
$activateExtension(extensionDescription: IExtensionDescription): TPromise<void> { throw ni(); }
}
......@@ -524,5 +528,6 @@ export const ExtHostContext = {
ExtHostExtensionService: createExtId<ExtHostExtensionServiceShape>('ExtHostExtensionService', ExtHostExtensionServiceShape),
ExtHostTerminalService: createExtId<ExtHostTerminalServiceShape>('ExtHostTerminalService', ExtHostTerminalServiceShape),
ExtHostSCM: createExtId<ExtHostSCMShape>('ExtHostSCM', ExtHostSCMShape),
ExtHostTask: createExtId<ExtHostTaskShape>('ExtHostTask', ExtHostTaskShape)
ExtHostTask: createExtId<ExtHostTaskShape>('ExtHostTask', ExtHostTaskShape),
ExtHostWorkspace: createExtId<ExtHostWorkspaceShape>('ExtHostWorkspace', ExtHostWorkspaceShape),
};
......@@ -6,26 +6,30 @@
import URI from 'vs/base/common/uri';
import { normalize } from 'vs/base/common/paths';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import { relative } from 'path';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { IResourceEdit } from 'vs/editor/common/services/bulkEdit';
import { TPromise } from 'vs/base/common/winjs.base';
import { fromRange, EndOfLine } from 'vs/workbench/api/node/extHostTypeConverters';
import { MainContext, MainThreadWorkspaceShape } from './extHost.protocol';
import { ExtHostWorkspaceShape, MainContext, MainThreadWorkspaceShape } from './extHost.protocol';
import * as vscode from 'vscode';
export class ExtHostWorkspace {
export class ExtHostWorkspace extends ExtHostWorkspaceShape {
private static _requestIdPool = 0;
private _proxy: MainThreadWorkspaceShape;
private _workspacePath: string;
constructor(threadService: IThreadService, workspacePath: string) {
constructor(threadService: IThreadService, folders: URI[]) {
super();
this._proxy = threadService.get(MainContext.MainThreadWorkspace);
this._workspacePath = workspacePath;
this._workspacePath = isFalsyOrEmpty(folders) ? undefined : folders[0].fsPath;
}
// --- workspace ---
getPath(): string {
return this._workspacePath;
}
......@@ -55,6 +59,12 @@ export class ExtHostWorkspace {
return normalize(result);
}
$acceptWorkspaceData(folders: URI[]): void {
// todo@joh do something, align with ctor URI[] vs IWorkspace
}
// --- search ---
findFiles(include: string, exclude: string, maxResults?: number, token?: vscode.CancellationToken): Thenable<vscode.Uri[]> {
const requestId = ExtHostWorkspace._requestIdPool++;
const result = this._proxy.$startSearch(include, exclude, maxResults, requestId);
......
......@@ -6,6 +6,7 @@
'use strict';
import * as assert from 'assert';
import URI from 'vs/base/common/uri';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { TestThreadService } from './testThreadService';
......@@ -13,7 +14,7 @@ suite('ExtHostWorkspace', function () {
test('asRelativePath', function () {
const ws = new ExtHostWorkspace(new TestThreadService(), '/Coding/Applications/NewsWoWBot');
const ws = new ExtHostWorkspace(new TestThreadService(), [URI.file('/Coding/Applications/NewsWoWBot')]);
assert.equal(ws.getRelativePath('/Coding/Applications/NewsWoWBot/bernd/das/brot'), 'bernd/das/brot');
assert.equal(ws.getRelativePath('/Apps/DartPubCache/hosted/pub.dartlang.org/convert-2.0.1/lib/src/hex.dart'),
......@@ -26,7 +27,7 @@ suite('ExtHostWorkspace', function () {
test('asRelativePath, same paths, #11402', function () {
const root = '/home/aeschli/workspaces/samples/docker';
const input = '/home/aeschli/workspaces/samples/docker';
const ws = new ExtHostWorkspace(new TestThreadService(), root);
const ws = new ExtHostWorkspace(new TestThreadService(), [URI.file(root)]);
assert.equal(ws.getRelativePath(input), input);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册