diff --git a/src/vs/base/browser/ui/splitview/splitview.ts b/src/vs/base/browser/ui/splitview/splitview.ts index 5f44fc9a363d246abfb55e2bed1abf10ca8e84f2..b4142731b13e74dee26415bb95c0154b17839897 100644 --- a/src/vs/base/browser/ui/splitview/splitview.ts +++ b/src/vs/base/browser/ui/splitview/splitview.ts @@ -117,10 +117,6 @@ export class SplitView extends Disposable { private _onDidSashReset = this._register(new Emitter()); readonly onDidSashReset = this._onDidSashReset.event; - get items(): ReadonlyArray { - return this.viewItems.map(item => item.view); - } - get length(): number { return this.viewItems.length; } diff --git a/src/vs/workbench/contrib/callHierarchy/browser/callHierarchyList.ts b/src/vs/workbench/contrib/callHierarchy/browser/callHierarchyList.ts deleted file mode 100644 index 5512f4cb91bbedb82739a8a56ac4482a230ff1d4..0000000000000000000000000000000000000000 --- a/src/vs/workbench/contrib/callHierarchy/browser/callHierarchyList.ts +++ /dev/null @@ -1,252 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { CallHierarchyProvider, CallHierarchyDirection } from 'vs/workbench/contrib/callHierarchy/common/callHierarchy'; -import { WorkbenchList } from 'vs/platform/list/browser/listService'; -import * as callHierarchyTree from 'vs/workbench/contrib/callHierarchy/browser/callHierarchyTree'; -import { Location, symbolKindToCssClass } from 'vs/editor/common/modes'; -import { IListVirtualDelegate, IListRenderer } from 'vs/base/browser/ui/list/list'; -import { IconLabel } from 'vs/base/browser/ui/iconLabel/iconLabel'; -import { CancellationTokenSource } from 'vs/base/common/cancellation'; -import { Emitter, Event } from 'vs/base/common/event'; -import { IView, Orientation } from 'vs/base/browser/ui/splitview/splitview'; -import { Dimension, addClass } from 'vs/base/browser/dom'; -import { ITextModelService } from 'vs/editor/common/services/resolverService'; -import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget'; -import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; -import { Disposable } from 'vs/base/common/lifecycle'; - -export type ListElement = callHierarchyTree.Call | Location; - -class LocationTemplate { - label: IconLabel; -} - -export class LocationRenderer implements IListRenderer { - - static id = 'LocationRenderer'; - - templateId: string = LocationRenderer.id; - - constructor( - @ITextModelService private readonly _textModelService: ITextModelService, - ) { } - - renderTemplate(container: HTMLElement): LocationTemplate { - const label = new IconLabel(container, { supportHighlights: true }); - return { label }; - } - - renderElement(element: Location, _index: number, template: LocationTemplate): void { - this._textModelService.createModelReference(element.uri).then(reference => { - const model = reference.object.textEditorModel; - const text = model.getLineContent(element.range.startLineNumber); - const indent = model.getLineFirstNonWhitespaceColumn(element.range.startLineNumber) - 1; - - const prefix = String(element.range.startLineNumber); - const shift = (1 + indent /*left*/) - (prefix.length + 2 /*right*/); - - template.label.setLabel(`${prefix}: ${text.substr(indent)}`, undefined, { - matches: [{ start: element.range.startColumn - shift, end: element.range.endColumn - shift }], - extraClasses: ['location'] - }); - reference.dispose(); - }); - } - - disposeTemplate(template: LocationTemplate): void { - template.label.dispose(); - } -} - -class CallRenderingTemplate { - iconLabel: IconLabel; -} - -export class CallRenderer implements IListRenderer { - - static id = 'CallRenderer'; - - templateId: string = CallRenderer.id; - - renderTemplate(container: HTMLElement): CallRenderingTemplate { - const iconLabel = new IconLabel(container, { supportHighlights: true }); - return { iconLabel }; - } - - renderElement(element: callHierarchyTree.Call, _index: number, template: CallRenderingTemplate): void { - template.iconLabel.setLabel( - element.item.name, - element.item.detail, - { - labelEscapeNewLines: true, - extraClasses: ['call', symbolKindToCssClass(element.item.kind, true)] - } - ); - } - - disposeTemplate(template: CallRenderingTemplate): void { - template.iconLabel.dispose(); - } -} - -export class Delegate implements IListVirtualDelegate { - getHeight(element: ListElement): number { - return 23; - } - getTemplateId(element: ListElement): string { - if (element instanceof callHierarchyTree.Call) { - return CallRenderer.id; - } else { - return LocationRenderer.id; - } - } -} - - -export class CallColumn extends Disposable implements IView { - - private _list: WorkbenchList; - private _token: CancellationTokenSource; - - readonly element: HTMLElement = document.createElement('div'); - readonly minimumSize: number = 100; - readonly maximumSize: number = Number.MAX_VALUE; - - private readonly _onDidChange = new Emitter(); - readonly onDidChange: Event = this._onDidChange.event; - - private readonly _fakeEvent = new UIEvent('fake'); - - constructor( - readonly index: number, - readonly root: callHierarchyTree.Call, - private readonly _provider: CallHierarchyProvider, - private readonly _direction: CallHierarchyDirection, - private readonly _emitter: Emitter<{ column: CallColumn, element: ListElement, focus: boolean }>, - private readonly _getDim: () => Dimension, - @IInstantiationService private readonly _instantiationService: IInstantiationService, - ) { - super(); - addClass(this.element, 'column'); - - this._list = this._register(>this._instantiationService.createInstance( - WorkbenchList, - this.element, - new Delegate(), - [ - new CallRenderer(), - this._instantiationService.createInstance(LocationRenderer) - ], - {} - )); - - this._register(this._list.onFocusChange(e => { - if (e.browserEvent !== this._fakeEvent && e.elements.length === 1) { - this._emitter.fire({ column: this, element: e.elements[0], focus: true }); - } - })); - this._register(this._list.onSelectionChange(e => { - if (e.browserEvent !== this._fakeEvent && e.elements.length === 1) { - this._emitter.fire({ column: this, element: e.elements[0], focus: false }); - } - })); - - this._token = this._register(new CancellationTokenSource()); - - Promise.resolve(this._provider.resolveCallHierarchyItem(this.root.item, this._direction, this._token.token)).then(calls => { - if (calls && calls.length > 0) { - const input: ListElement[] = []; - for (const [item, locations] of calls) { - input.push(new callHierarchyTree.Call(this._direction, item, locations)); - input.push(...locations); - } - this._list.splice(0, this._list.length, input); - this._list.focusFirst(this._fakeEvent); - this._list.setSelection([0], this._fakeEvent); - - } else { - // show message - } - }).catch(err => { - console.error(err); - }); - } - - layout(size: number, orientation: Orientation): void { - const { height, width } = this._getDim(); - this._list.layout(height, Math.min(size, Math.ceil(width / 6))); - } - - focus(): void { - this._list.domFocus(); - } -} - - -export class LocationColumn extends Disposable implements IView { - - readonly element: HTMLElement = document.createElement('div'); - readonly minimumSize: number = 100; - readonly maximumSize: number = Number.MAX_VALUE; - - private readonly _onDidChange = new Emitter(); - readonly onDidChange: Event = this._onDidChange.event; - - private _editor: EmbeddedCodeEditorWidget; - - constructor( - private _location: Location, - private readonly _getDim: () => Dimension, - editor: ICodeEditor, - @ITextModelService private readonly _textModelService: ITextModelService, - ) { - super(); - addClass(this.element, 'column'); - - // todo@joh pretty random selection of options - let options: IEditorOptions = { - readOnly: true, - scrollBeyondLastLine: false, - lineNumbers: 'off', - scrollbar: { - verticalScrollbarSize: 14, - horizontal: 'auto', - useShadows: true, - verticalHasArrows: false, - horizontalHasArrows: false - }, - overviewRulerLanes: 2, - fixedOverflowWidgets: true, - minimap: { - enabled: false - }, - codeLens: false, - glyphMargin: false, - }; - - this._editor = editor.invokeWithinContext(accessor => { - return this._register(accessor.get(IInstantiationService).createInstance(EmbeddedCodeEditorWidget, this.element, options, editor)); - }); - - this._textModelService.createModelReference(this._location.uri).then(reference => { - this._editor.setModel(reference.object.textEditorModel); - this._editor.revealRangeInCenter(this._location.range); - this._editor.setSelection(this._location.range); - this._register(reference); - }); - } - - layout(size: number) { - this._editor.layout({ height: this._getDim().height, width: size }); - } - - focus(): void { - this._editor.focus(); - } -} - diff --git a/src/vs/workbench/contrib/callHierarchy/browser/callHierarchyPeek.ts b/src/vs/workbench/contrib/callHierarchy/browser/callHierarchyPeek.ts index 6c7a134217f23f69c5cbd1aca86931f96de424b3..a7659455780e1c7b77dd097a03950f09c283b049 100644 --- a/src/vs/workbench/contrib/callHierarchy/browser/callHierarchyPeek.ts +++ b/src/vs/workbench/contrib/callHierarchy/browser/callHierarchyPeek.ts @@ -11,14 +11,13 @@ import { CallHierarchyItem, CallHierarchyProvider, CallHierarchyDirection } from import { WorkbenchAsyncDataTree } from 'vs/platform/list/browser/listService'; import { FuzzyScore } from 'vs/base/common/filters'; import * as callHTree from 'vs/workbench/contrib/callHierarchy/browser/callHierarchyTree'; -import * as callHList from 'vs/workbench/contrib/callHierarchy/browser/callHierarchyList'; import { IAsyncDataTreeOptions } from 'vs/base/browser/ui/tree/asyncDataTree'; import { localize } from 'vs/nls'; import { ScrollType } from 'vs/editor/common/editorCommon'; import { IRange, Range } from 'vs/editor/common/core/range'; import { SplitView, Orientation, Sizing } from 'vs/base/browser/ui/splitview/splitview'; import { Dimension, addClass } from 'vs/base/browser/dom'; -import { Emitter, Event } from 'vs/base/common/event'; +import { Event } from 'vs/base/common/event'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget'; import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; @@ -57,10 +56,10 @@ export class CallHierarchyTreePeekWidget extends PeekViewWidget { } dispose(): void { - super.dispose(); this._splitView.dispose(); this._tree.dispose(); this._editor.dispose(); + super.dispose(); } protected _fillBody(container: HTMLElement): void { @@ -228,116 +227,3 @@ export class CallHierarchyTreePeekWidget extends PeekViewWidget { this._splitView.layout(width); } } - -export class CallHierarchyColumnPeekWidget extends PeekViewWidget { - - private readonly _emitter = new Emitter<{ column: callHList.CallColumn, element: callHList.ListElement, focus: boolean }>(); - private _splitView: SplitView; - private _dim: Dimension; - - constructor( - editor: ICodeEditor, - private readonly _provider: CallHierarchyProvider, - private readonly _direction: CallHierarchyDirection, - private readonly _root: CallHierarchyItem, - @IEditorService private readonly _editorService: IEditorService, - @IInstantiationService private readonly _instantiationService: IInstantiationService, - ) { - super(editor, { showFrame: true, showArrow: true, isResizeable: true, isAccessible: true }); - this.create(); - } - - dispose(): void { - super.dispose(); - this._splitView.dispose(); - this._emitter.dispose(); - } - - protected _fillBody(container: HTMLElement): void { - addClass(container, 'call-hierarchy-columns'); - - this._splitView = new SplitView(container, { orientation: Orientation.HORIZONTAL }); - this._emitter.event(e => { - const { element, column, focus } = e; - - // remove old - while (column.index + 1 < this._splitView.length) { - this._splitView.removeView(this._splitView.length - 1); - } - const getDim = () => this._dim || { height: undefined, width: undefined }; - - // add new - if (element instanceof callHTree.Call) { - let newColumn = this._instantiationService.createInstance( - callHList.CallColumn, - column.index + 1, - element, - this._provider, - this._direction, - this._emitter, - getDim - ); - this._disposables.push(newColumn); - this._splitView.addView(newColumn, Sizing.Distribute); - - if (!focus) { - setTimeout(() => newColumn.focus()); - } - - let parts = this._splitView.items.map(column => column instanceof callHList.CallColumn ? column.root.item.name : undefined).filter(e => Boolean(e)); - this.setTitle(localize('title', "Call Hierarchy for '{0}'", parts.join(' > '))); - - } else { - - if (!focus) { - this.dispose(); - this._editorService.openEditor({ - resource: element.uri, - options: { selection: element.range } - }); - } else { - let newColumn = this._instantiationService.createInstance( - callHList.LocationColumn, - element, - getDim, - this.editor - ); - this._disposables.push(newColumn); - this._splitView.addView(newColumn, Sizing.Distribute); - } - } - }); - } - - show(where: IRange) { - this.editor.revealRangeInCenterIfOutsideViewport(where, ScrollType.Smooth); - super.show(where, 16); - this.setTitle(localize('title', "Call Hierarchy for '{0}'", this._root.name)); - - // add root items... - const item = this._instantiationService.createInstance( - callHList.CallColumn, - 0, - new callHTree.Call(this._direction, this._root, []), - this._provider, - this._direction, - this._emitter, - () => this._dim || { height: undefined, width: undefined } - ); - this._disposables.push(item); - this._splitView.addView(item, item.minimumSize); - setTimeout(() => item.focus()); - } - - protected _onWidth(width: number) { - if (this._dim) { - this._doLayoutBody(this._dim.height, width); - } - } - - protected _doLayoutBody(height: number, width: number): void { - super._doLayoutBody(height, width); - this._dim = { height, width }; - this._splitView.layout(width); - } -}