mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
Merge master
This commit is contained in:
@@ -191,6 +191,9 @@ export class ExtHostAPIImplementation {
|
||||
onDidChangeTextEditorOptions: (listener: (e: vscode.TextEditorOptionsChangeEvent) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) => {
|
||||
return pluginHostEditors.onDidChangeTextEditorOptions(listener, thisArgs, disposables);
|
||||
},
|
||||
onDidChangeTextEditorViewColumn(listener, thisArg?, disposables?) {
|
||||
return pluginHostEditors.onDidChangeTextEditorViewColumn(listener, thisArg, disposables);
|
||||
},
|
||||
showInformationMessage: (message, ...items) => {
|
||||
return pluginHostMessageService.showMessage(Severity.Info, message, items);
|
||||
},
|
||||
|
||||
@@ -22,7 +22,7 @@ import {IThreadService} from 'vs/platform/thread/common/thread';
|
||||
|
||||
export function registerApiCommands(threadService: IThreadService) {
|
||||
const commands = threadService.getRemotable(ExtHostCommands);
|
||||
new ExtHostApiCommands(commands);
|
||||
new ExtHostApiCommands(commands).registerCommands();
|
||||
}
|
||||
|
||||
class ExtHostApiCommands {
|
||||
@@ -32,7 +32,9 @@ class ExtHostApiCommands {
|
||||
|
||||
constructor(commands: ExtHostCommands) {
|
||||
this._commands = commands;
|
||||
}
|
||||
|
||||
registerCommands() {
|
||||
this._register('vscode.executeWorkspaceSymbolProvider', this._executeWorkspaceSymbolProvider, {
|
||||
description: 'Execute all workspace symbol provider.',
|
||||
args: [{ name: 'query', constraint: String }],
|
||||
@@ -145,6 +147,19 @@ class ExtHostApiCommands {
|
||||
],
|
||||
returns: 'A promise that resolves to an array of TextEdits.'
|
||||
});
|
||||
|
||||
|
||||
this._register('vscode.previewHtml', (uri: URI, position?: vscode.ViewColumn) => {
|
||||
return this._commands.executeCommand('_workbench.previewHtml', uri,
|
||||
typeof position === 'number' ? typeConverters.fromViewColumn(position) : void 0);
|
||||
|
||||
}, {
|
||||
description: 'Preview an html document.',
|
||||
args: [
|
||||
{ name: 'uri', description: 'Uri of the document to preview.', constraint: URI },
|
||||
{ name: 'column', description: '(optional) Column in which to preview.' },
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
// --- command impl
|
||||
|
||||
@@ -18,17 +18,23 @@ import {Position as EditorPosition} from 'vs/platform/editor/common/editor';
|
||||
import {IModelService} from 'vs/editor/common/services/modelService';
|
||||
import {MainThreadEditorsTracker, TextEditorRevealType, MainThreadTextEditor, ITextEditorConfiguration} from 'vs/workbench/api/node/mainThreadEditors';
|
||||
import * as TypeConverters from './extHostTypeConverters';
|
||||
import {TextDocument, TextEditorSelectionChangeEvent, TextEditorOptionsChangeEvent, TextEditorOptions, ViewColumn} from 'vscode';
|
||||
import {TextDocument, TextEditorSelectionChangeEvent, TextEditorOptionsChangeEvent, TextEditorOptions, TextEditorViewColumnChangeEvent, ViewColumn} from 'vscode';
|
||||
import {EventType} from 'vs/workbench/common/events';
|
||||
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
|
||||
import {IEventService} from 'vs/platform/event/common/event';
|
||||
import {equals as arrayEquals} from 'vs/base/common/arrays';
|
||||
import {equals as objectEquals} from 'vs/base/common/objects';
|
||||
|
||||
export interface ITextEditorAddData {
|
||||
id: string;
|
||||
document: URI;
|
||||
options: ITextEditorConfiguration;
|
||||
selections: ISelection[];
|
||||
editorPosition: EditorPosition;
|
||||
}
|
||||
|
||||
export interface ITextEditorPositionData {
|
||||
[id: string]: EditorPosition;
|
||||
}
|
||||
|
||||
@Remotable.PluginHostContext('ExtHostEditors')
|
||||
@@ -40,6 +46,9 @@ export class ExtHostEditors {
|
||||
public onDidChangeTextEditorOptions: Event<TextEditorOptionsChangeEvent>;
|
||||
private _onDidChangeTextEditorOptions: Emitter<TextEditorOptionsChangeEvent>;
|
||||
|
||||
public onDidChangeTextEditorViewColumn: Event<TextEditorViewColumnChangeEvent>;
|
||||
private _onDidChangeTextEditorViewColumn: Emitter<TextEditorViewColumnChangeEvent>;
|
||||
|
||||
private _editors: { [id: string]: ExtHostTextEditor };
|
||||
private _proxy: MainThreadEditors;
|
||||
private _onDidChangeActiveTextEditor: Emitter<vscode.TextEditor>;
|
||||
@@ -56,6 +65,9 @@ export class ExtHostEditors {
|
||||
this._onDidChangeTextEditorOptions = new Emitter<TextEditorOptionsChangeEvent>();
|
||||
this.onDidChangeTextEditorOptions = this._onDidChangeTextEditorOptions.event;
|
||||
|
||||
this._onDidChangeTextEditorViewColumn = new Emitter<TextEditorViewColumnChangeEvent>();
|
||||
this.onDidChangeTextEditorViewColumn = this._onDidChangeTextEditorViewColumn.event;
|
||||
|
||||
this._modelService = threadService.getRemotable(ExtHostModelService);
|
||||
this._proxy = threadService.getRemotable(MainThreadEditors);
|
||||
this._onDidChangeActiveTextEditor = new Emitter<vscode.TextEditor>();
|
||||
@@ -95,7 +107,7 @@ export class ExtHostEditors {
|
||||
|
||||
_acceptTextEditorAdd(data: ITextEditorAddData): void {
|
||||
let document = this._modelService.getDocumentData(data.document);
|
||||
let newEditor = new ExtHostTextEditor(this._proxy, data.id, document, data.selections.map(TypeConverters.toSelection), data.options);
|
||||
let newEditor = new ExtHostTextEditor(this._proxy, data.id, document, data.selections.map(TypeConverters.toSelection), data.options, TypeConverters.toViewColumn(data.editorPosition));
|
||||
this._editors[data.id] = newEditor;
|
||||
}
|
||||
|
||||
@@ -129,6 +141,17 @@ export class ExtHostEditors {
|
||||
this._onDidChangeActiveTextEditor.fire(this.getActiveTextEditor());
|
||||
}
|
||||
|
||||
_acceptEditorPositionData(data: ITextEditorPositionData): void {
|
||||
for (let id in data) {
|
||||
let textEditor = this._editors[id];
|
||||
let viewColumn = TypeConverters.toViewColumn(data[id]);
|
||||
if (textEditor.viewColumn !== viewColumn) {
|
||||
textEditor._acceptViewColumn(viewColumn);
|
||||
this._onDidChangeTextEditorViewColumn.fire({ textEditor, viewColumn });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_acceptTextEditorRemove(id: string): void {
|
||||
// make sure the removed editor is not visible
|
||||
let newVisibleEditors = this._visibleEditorIds.filter(visibleEditorId => visibleEditorId !== id);
|
||||
@@ -271,13 +294,15 @@ class ExtHostTextEditor implements vscode.TextEditor {
|
||||
private _documentData: ExtHostDocumentData;
|
||||
private _selections: Selection[];
|
||||
private _options: TextEditorOptions;
|
||||
private _viewColumn: vscode.ViewColumn;
|
||||
|
||||
constructor(proxy: MainThreadEditors, id: string, document: ExtHostDocumentData, selections: Selection[], options: EditorOptions) {
|
||||
constructor(proxy: MainThreadEditors, id: string, document: ExtHostDocumentData, selections: Selection[], options: EditorOptions, viewColumn: vscode.ViewColumn) {
|
||||
this._proxy = proxy;
|
||||
this._id = id;
|
||||
this._documentData = document;
|
||||
this._selections = selections;
|
||||
this._options = options;
|
||||
this._viewColumn = viewColumn;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
@@ -319,6 +344,20 @@ class ExtHostTextEditor implements vscode.TextEditor {
|
||||
this._options = options;
|
||||
}
|
||||
|
||||
// ---- view column
|
||||
|
||||
get viewColumn(): vscode.ViewColumn {
|
||||
return this._viewColumn;
|
||||
}
|
||||
|
||||
set viewColumn(value) {
|
||||
throw readonly('viewColumn');
|
||||
}
|
||||
|
||||
_acceptViewColumn(value: vscode.ViewColumn) {
|
||||
this._viewColumn = value;
|
||||
}
|
||||
|
||||
// ---- selections
|
||||
|
||||
get selection(): Selection {
|
||||
@@ -423,6 +462,7 @@ export class MainThreadEditors {
|
||||
private _textEditorsMap: { [editorId: string]: MainThreadTextEditor; };
|
||||
private _activeTextEditor: string;
|
||||
private _visibleEditors: string[];
|
||||
private _editorPositionData: ITextEditorPositionData;
|
||||
|
||||
constructor(
|
||||
@IThreadService threadService: IThreadService,
|
||||
@@ -440,6 +480,7 @@ export class MainThreadEditors {
|
||||
this._textEditorsMap = Object.create(null);
|
||||
this._activeTextEditor = null;
|
||||
this._visibleEditors = [];
|
||||
this._editorPositionData = null;
|
||||
|
||||
this._editorTracker = new MainThreadEditorsTracker(editorService, modelService);
|
||||
this._toDispose.push(this._editorTracker);
|
||||
@@ -450,6 +491,7 @@ export class MainThreadEditors {
|
||||
this._toDispose.push(this._editorTracker.onDidUpdateTextEditors(() => this._updateActiveAndVisibleTextEditors()));
|
||||
this._toDispose.push(this._editorTracker.onChangedFocusedTextEditor((focusedTextEditorId) => this._updateActiveAndVisibleTextEditors()));
|
||||
this._toDispose.push(eventService.addListener2(EventType.EDITOR_INPUT_CHANGED, () => this._updateActiveAndVisibleTextEditors()));
|
||||
this._toDispose.push(eventService.addListener2(EventType.EDITOR_POSITION_CHANGED, () => this._updateActiveAndVisibleTextEditors()));
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
@@ -473,7 +515,8 @@ export class MainThreadEditors {
|
||||
id: id,
|
||||
document: textEditor.getModel().getAssociatedResource(),
|
||||
options: textEditor.getConfiguration(),
|
||||
selections: textEditor.getSelections()
|
||||
selections: textEditor.getSelections(),
|
||||
editorPosition: this._findEditorPosition(textEditor)
|
||||
});
|
||||
|
||||
this._textEditorsListenersMap[id] = toDispose;
|
||||
@@ -489,16 +532,22 @@ export class MainThreadEditors {
|
||||
}
|
||||
|
||||
private _updateActiveAndVisibleTextEditors(): void {
|
||||
|
||||
// active and visible editors
|
||||
let visibleEditors = this._editorTracker.getVisibleTextEditorIds();
|
||||
let activeEditor = this._findActiveTextEditorId();
|
||||
|
||||
if (activeEditor === this._activeTextEditor && arrayEquals(this._visibleEditors, visibleEditors, (a, b) => a === b)) {
|
||||
// no change
|
||||
return;
|
||||
if (activeEditor !== this._activeTextEditor || !arrayEquals(this._visibleEditors, visibleEditors, (a, b) => a === b)) {
|
||||
this._activeTextEditor = activeEditor;
|
||||
this._visibleEditors = visibleEditors;
|
||||
this._proxy._acceptActiveEditorAndVisibleEditors(this._activeTextEditor, this._visibleEditors);
|
||||
}
|
||||
|
||||
// editor columns
|
||||
let editorPositionData = this._getTextEditorPositionData();
|
||||
if (!objectEquals(this._editorPositionData, editorPositionData)) {
|
||||
this._editorPositionData = editorPositionData;
|
||||
this._proxy._acceptEditorPositionData(this._editorPositionData);
|
||||
}
|
||||
this._activeTextEditor = activeEditor;
|
||||
this._visibleEditors = visibleEditors;
|
||||
this._proxy._acceptActiveEditorAndVisibleEditors(this._activeTextEditor, this._visibleEditors);
|
||||
}
|
||||
|
||||
private _findActiveTextEditorId(): string {
|
||||
@@ -527,6 +576,33 @@ export class MainThreadEditors {
|
||||
return this._editorTracker.findTextEditorIdFor((<ICommonDiffEditor>editor).getModifiedEditor());
|
||||
}
|
||||
|
||||
private _findEditorPosition(editor: MainThreadTextEditor): EditorPosition {
|
||||
for (let workbenchEditor of this._workbenchEditorService.getVisibleEditors()) {
|
||||
if (editor.matches(workbenchEditor)) {
|
||||
return workbenchEditor.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _getTextEditorPositionData(): ITextEditorPositionData {
|
||||
let result: ITextEditorPositionData = Object.create(null);
|
||||
for (let workbenchEditor of this._workbenchEditorService.getVisibleEditors()) {
|
||||
let editor = <IEditor>workbenchEditor.getControl();
|
||||
// Substitute for (editor instanceof ICodeEditor)
|
||||
if (!editor || typeof editor.getEditorType !== 'function') {
|
||||
// Not a text editor...
|
||||
continue;
|
||||
}
|
||||
if (editor.getEditorType() === EditorType.ICodeEditor) {
|
||||
let id = this._editorTracker.findTextEditorIdFor(<ICommonCodeEditor>editor);
|
||||
if (id) {
|
||||
result[id] = workbenchEditor.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// --- from plugin host process
|
||||
|
||||
_tryShowTextDocument(resource: URI, position: EditorPosition, preserveFocus: boolean): TPromise<string> {
|
||||
|
||||
@@ -111,6 +111,18 @@ export function fromViewColumn(column?: vscode.ViewColumn): EditorPosition {
|
||||
return editorColumn;
|
||||
}
|
||||
|
||||
export function toViewColumn(position?: EditorPosition): vscode.ViewColumn {
|
||||
if (typeof position !== 'number') {
|
||||
return;
|
||||
}
|
||||
if (position === EditorPosition.LEFT) {
|
||||
return <number> types.ViewColumn.One;
|
||||
} else if (position === EditorPosition.CENTER) {
|
||||
return <number> types.ViewColumn.Two;
|
||||
} else if (position === EditorPosition.RIGHT) {
|
||||
return <number> types.ViewColumn.Three;
|
||||
}
|
||||
}
|
||||
|
||||
export function fromFormattedString(value: vscode.MarkedString): IHTMLContentElement {
|
||||
if (typeof value === 'string') {
|
||||
@@ -198,9 +210,11 @@ export namespace SymbolKind {
|
||||
return 'class';
|
||||
case types.SymbolKind.Interface:
|
||||
return 'interface';
|
||||
case types.SymbolKind.Module:
|
||||
case types.SymbolKind.Namespace:
|
||||
return 'namespace';
|
||||
case types.SymbolKind.Package:
|
||||
return 'package';
|
||||
case types.SymbolKind.Module:
|
||||
return 'module';
|
||||
case types.SymbolKind.Property:
|
||||
return 'property';
|
||||
@@ -216,6 +230,12 @@ export namespace SymbolKind {
|
||||
return 'number';
|
||||
case types.SymbolKind.Boolean:
|
||||
return 'boolean';
|
||||
case types.SymbolKind.Object:
|
||||
return 'object';
|
||||
case types.SymbolKind.Key:
|
||||
return 'key';
|
||||
case types.SymbolKind.Null:
|
||||
return 'null';
|
||||
}
|
||||
return 'property';
|
||||
}
|
||||
@@ -234,9 +254,11 @@ export namespace SymbolKind {
|
||||
return types.SymbolKind.Class;
|
||||
case 'interface':
|
||||
return types.SymbolKind.Interface;
|
||||
case 'namespace':
|
||||
return types.SymbolKind.Namespace;
|
||||
case 'package':
|
||||
return types.SymbolKind.Package;
|
||||
case 'module':
|
||||
// case types.SymbolKind.Namespace:
|
||||
// case types.SymbolKind.Package:
|
||||
return types.SymbolKind.Module;
|
||||
case 'property':
|
||||
return types.SymbolKind.Property;
|
||||
@@ -252,6 +274,12 @@ export namespace SymbolKind {
|
||||
return types.SymbolKind.Number;
|
||||
case 'boolean':
|
||||
return types.SymbolKind.Boolean;
|
||||
case 'object':
|
||||
return types.SymbolKind.Object;
|
||||
case 'key':
|
||||
return types.SymbolKind.Key;
|
||||
case 'null':
|
||||
return types.SymbolKind.Null;
|
||||
}
|
||||
return types.SymbolKind.Property;
|
||||
}
|
||||
|
||||
@@ -536,6 +536,9 @@ export enum SymbolKind {
|
||||
Number,
|
||||
Boolean,
|
||||
Array,
|
||||
Object,
|
||||
Key,
|
||||
Null
|
||||
}
|
||||
|
||||
export class SymbolInformation {
|
||||
|
||||
Reference in New Issue
Block a user