debt - move things from browser to common that are easy to move

This commit is contained in:
Johannes Rieken
2015-12-07 13:04:07 +01:00
parent 3dd0a89aba
commit ba2988de9d
5 changed files with 10 additions and 10 deletions

View File

@@ -1,112 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import {TPromise} from 'vs/base/common/winjs.base';
import {onUnexpectedError} from 'vs/base/common/errors';
import {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
import {IOutputService, OUTPUT_EDITOR_INPUT_ID} from 'vs/workbench/parts/output/common/output';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {Position} from 'vs/platform/editor/common/editor';
import * as TypeConverters from 'vs/workbench/api/common/pluginHostTypeConverters';
export class ExtHostOutputChannel implements vscode.OutputChannel {
private _proxy: MainThreadOutputService;
private _name: string;
private _disposed: boolean;
constructor(name: string, proxy: MainThreadOutputService) {
this._name = name;
this._proxy = proxy;
}
get name(): string {
return this._name;
}
dispose(): void {
if (!this._disposed) {
this._proxy.clear(this._name).then(() => {
this._disposed = true;
});
}
}
append(value: string): void {
this._proxy.append(this._name, value);
}
appendLine(value: string): void {
this.append(value + '\n');
}
clear(): void {
this._proxy.clear(this._name);
}
show(column?: vscode.ViewColumn): void {
this._proxy.reveal(this._name, TypeConverters.fromViewColumn(column));
}
hide(): void {
this._proxy.close(this._name);
}
}
export class ExtHostOutputService {
private _proxy: MainThreadOutputService;
constructor(threadService: IThreadService) {
this._proxy = threadService.getRemotable(MainThreadOutputService);
}
createOutputChannel(name: string): vscode.OutputChannel {
name = name.trim();
if (!name) {
throw new Error('illegal argument `name`. must not be falsy');
} else {
return new ExtHostOutputChannel(name, this._proxy);
}
}
}
@Remotable.MainContext('MainThreadOutputService')
export class MainThreadOutputService {
private _outputService: IOutputService;
private _editorService: IWorkbenchEditorService;
constructor( @IOutputService outputService: IOutputService, @IWorkbenchEditorService editorService: IWorkbenchEditorService) {
this._outputService = outputService;
this._editorService = editorService;
}
public append(channel: string, value: string): TPromise<void> {
this._outputService.append(channel, value);
return undefined;
}
public clear(channel: string): TPromise<void> {
this._outputService.clearOutput(channel);
return undefined;
}
public reveal(channel: string, position: Position): TPromise<void> {
this._outputService.showOutput(channel, position);
return undefined;
}
public close(channel: string): TPromise<void> {
let editors = this._editorService.getVisibleEditors();
for (let editor of editors) {
if (editor.input.getId() === OUTPUT_EDITOR_INPUT_ID) {
this._editorService.closeEditor(editor).done(null, onUnexpectedError);
return undefined;
}
}
}
}

View File

@@ -12,11 +12,11 @@ import {PluginHostFileSystemEventService} from 'vs/workbench/api/common/pluginHo
import {PluginHostModelService, setWordDefinitionFor} from 'vs/workbench/api/common/pluginHostDocuments';
import {PluginHostConfiguration} from 'vs/workbench/api/common/pluginHostConfiguration';
import {PluginHostDiagnostics} from 'vs/workbench/api/common/pluginHostDiagnostics';
import {PluginHostWorkspace} from 'vs/workbench/api/browser/pluginHostWorkspace';
import {PluginHostWorkspace} from 'vs/workbench/api/common/pluginHostWorkspace';
import {PluginHostQuickOpen} from 'vs/workbench/api/browser/pluginHostQuickOpen';
import {PluginHostStatusBar} from 'vs/workbench/api/browser/pluginHostStatusBar';
import {PluginHostCommands} from 'vs/workbench/api/common/pluginHostCommands';
import {ExtHostOutputService} from 'vs/workbench/api/browser/extHostOutputService';
import {ExtHostOutputService} from 'vs/workbench/api/common/extHostOutputService';
import {PluginHostMessageService} from 'vs/workbench/api/common/pluginHostMessageService';
import {PluginHostTelemetryService} from 'vs/workbench/api/common/pluginHostTelemetry';
import {PluginHostEditors} from 'vs/workbench/api/common/pluginHostEditors';

View File

@@ -1,142 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import URI from 'vs/base/common/uri';
import {ISearchService, QueryType} from 'vs/platform/search/common/search';
import {IWorkspaceContextService, IWorkspace} from 'vs/platform/workspace/common/workspace';
import {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IEventService} from 'vs/platform/event/common/event';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {ITextFileService, ITextFileOperationResult} from 'vs/workbench/parts/files/common/files';
import {Uri, FileSystemWatcher} from 'vscode';
import {ICodeEditor} from 'vs/editor/browser/editorBrowser';
import {bulkEdit, IResourceEdit} from 'vs/editor/common/services/bulkEdit';
import {TPromise} from 'vs/base/common/winjs.base';
import {fromRange} from 'vs/workbench/api/common/pluginHostTypeConverters';
export class PluginHostWorkspace {
private _proxy: MainThreadWorkspace;
private _workspacePath: string;
constructor( @IThreadService threadService: IThreadService, workspacePath:string) {
this._proxy = threadService.getRemotable(MainThreadWorkspace);
this._workspacePath = workspacePath;
}
getPath(): string {
return this._workspacePath;
}
getRelativePath(pathOrUri: string|Uri): string {
let path: string;
if (typeof pathOrUri === 'string') {
path = pathOrUri;
} else {
path = pathOrUri.fsPath;
}
if (this._workspacePath && this._workspacePath.length < path.length) {
// return relative(workspacePath, path);
return path.substring(this._workspacePath.length);
}
return path
}
findFiles(include: string, exclude: string, maxResults?:number): Thenable<Uri[]> {
return this._proxy.findFiles(include, exclude, maxResults);
}
saveAll(includeUntitled?: boolean): Thenable<boolean> {
return this._proxy.saveAll(includeUntitled);
}
appyEdit(edit: vscode.WorkspaceEdit): TPromise<boolean> {
let resourceEdits: IResourceEdit[] = [];
let entries = edit.entries();
for (let entry of entries) {
let [uri, edits] = entry;
for (let edit of edits) {
resourceEdits.push({
resource: <URI>uri,
newText: edit.newText,
range: fromRange(edit.range)
});
}
}
return this._proxy.applyWorkspaceEdit(resourceEdits);
}
}
@Remotable.MainContext('MainThreadWorkspace')
export class MainThreadWorkspace {
private _searchService: ISearchService;
private _workspace: IWorkspace;
private _textFileService: ITextFileService;
private _editorService:IWorkbenchEditorService;
private _eventService:IEventService;
constructor( @ISearchService searchService: ISearchService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@ITextFileService textFileService,
@IWorkbenchEditorService editorService,
@IEventService eventService) {
this._searchService = searchService;
this._workspace = contextService.getWorkspace();
this._textFileService = textFileService;
this._editorService = editorService;
this._eventService = eventService;
}
findFiles(include: string, exclude: string, maxResults: number): Thenable<Uri[]> {
if (!this._workspace) {
return;
}
return this._searchService.search({
rootResources: [this._workspace.resource],
type: QueryType.File,
maxResults,
includePattern: { [include]: true },
excludePattern: { [exclude]: true },
}).then(result => {
return result.results.map(m => m.resource);
});
}
saveAll(includeUntitled?: boolean): Thenable<boolean> {
return this._textFileService.saveAll(includeUntitled).then(result => {
return result.results.every(each => each.success === true);;
});
}
applyWorkspaceEdit(edits: IResourceEdit[]): TPromise<boolean> {
let codeEditor: ICodeEditor;
let editor = this._editorService.getActiveEditor();
if (editor) {
let candidate = <ICodeEditor> editor.getControl();
if (typeof candidate.getEditorType === 'function') {
// enough proof
codeEditor = candidate;
}
}
return bulkEdit(this._eventService, this._editorService, codeEditor, edits)
.then(() => true);
}
}