mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-21 04:20:11 -04:00
Merge VS Code 1.31.1 (#4283)
This commit is contained in:
@@ -25,7 +25,7 @@ export namespace PeekContext {
|
||||
export const notInPeekEditor: ContextKeyExpr = inPeekEditor.toNegated();
|
||||
}
|
||||
|
||||
export function getOuterEditor(accessor: ServicesAccessor): ICodeEditor {
|
||||
export function getOuterEditor(accessor: ServicesAccessor): ICodeEditor | null {
|
||||
let editor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
|
||||
if (editor instanceof EmbeddedCodeEditorWidget) {
|
||||
return editor.getParentEditor();
|
||||
@@ -34,13 +34,12 @@ export function getOuterEditor(accessor: ServicesAccessor): ICodeEditor {
|
||||
}
|
||||
|
||||
export interface IPeekViewStyles extends IStyles {
|
||||
headerBackgroundColor?: Color;
|
||||
primaryHeadingColor?: Color;
|
||||
secondaryHeadingColor?: Color;
|
||||
headerBackgroundColor?: Color | null;
|
||||
primaryHeadingColor?: Color | null;
|
||||
secondaryHeadingColor?: Color | null;
|
||||
}
|
||||
|
||||
export interface IPeekViewOptions extends IOptions, IPeekViewStyles {
|
||||
}
|
||||
export type IPeekViewOptions = IOptions & IPeekViewStyles;
|
||||
|
||||
const defaultOptions: IPeekViewOptions = {
|
||||
headerBackgroundColor: Color.white,
|
||||
@@ -92,16 +91,16 @@ export abstract class PeekViewWidget extends ZoneWidget {
|
||||
protected _applyStyles(): void {
|
||||
super._applyStyles();
|
||||
let options = <IPeekViewOptions>this.options;
|
||||
if (this._headElement) {
|
||||
if (this._headElement && options.headerBackgroundColor) {
|
||||
this._headElement.style.backgroundColor = options.headerBackgroundColor.toString();
|
||||
}
|
||||
if (this._primaryHeading) {
|
||||
if (this._primaryHeading && options.primaryHeadingColor) {
|
||||
this._primaryHeading.style.color = options.primaryHeadingColor.toString();
|
||||
}
|
||||
if (this._secondaryHeading) {
|
||||
if (this._secondaryHeading && options.secondaryHeadingColor) {
|
||||
this._secondaryHeading.style.color = options.secondaryHeadingColor.toString();
|
||||
}
|
||||
if (this._bodyElement) {
|
||||
if (this._bodyElement && options.frameColor) {
|
||||
this._bodyElement.style.borderColor = options.frameColor.toString();
|
||||
}
|
||||
}
|
||||
@@ -138,7 +137,7 @@ export abstract class PeekViewWidget extends ZoneWidget {
|
||||
|
||||
this._actionbarWidget.push(new Action('peekview.close', nls.localize('label.close', "Close"), 'close-peekview-action', true, () => {
|
||||
this.dispose();
|
||||
return null;
|
||||
return Promise.resolve();
|
||||
}), { label: false, icon: true });
|
||||
}
|
||||
|
||||
@@ -186,11 +185,11 @@ export abstract class PeekViewWidget extends ZoneWidget {
|
||||
}
|
||||
|
||||
protected _doLayoutHead(heightInPixel: number, widthInPixel: number): void {
|
||||
this._headElement.style.height = strings.format('{0}px', heightInPixel);
|
||||
this._headElement.style.height = `${heightInPixel}px`;
|
||||
this._headElement.style.lineHeight = this._headElement.style.height;
|
||||
}
|
||||
|
||||
protected _doLayoutBody(heightInPixel: number, widthInPixel: number): void {
|
||||
this._bodyElement.style.height = strings.format('{0}px', heightInPixel);
|
||||
this._bodyElement.style.height = `${heightInPixel}px`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
|
||||
export const defaultReferenceSearchOptions: RequestOptions = {
|
||||
getMetaTitle(model) {
|
||||
return model.references.length > 1 && nls.localize('meta.titleReference', " – {0} references", model.references.length);
|
||||
return model.references.length > 1 ? nls.localize('meta.titleReference', " – {0} references", model.references.length) : '';
|
||||
}
|
||||
};
|
||||
|
||||
@@ -78,15 +78,17 @@ export class ReferenceAction extends EditorAction {
|
||||
});
|
||||
}
|
||||
|
||||
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
let controller = ReferencesController.get(editor);
|
||||
if (!controller) {
|
||||
return;
|
||||
}
|
||||
let range = editor.getSelection();
|
||||
let model = editor.getModel();
|
||||
let references = createCancelablePromise(token => provideReferences(model, range.getStartPosition(), token).then(references => new ReferencesModel(references)));
|
||||
controller.toggleWidget(range, references, defaultReferenceSearchOptions);
|
||||
if (editor.hasModel()) {
|
||||
const range = editor.getSelection();
|
||||
const model = editor.getModel();
|
||||
const references = createCancelablePromise(token => provideReferences(model, range.getStartPosition(), token).then(references => new ReferencesModel(references)));
|
||||
controller.toggleWidget(range, references, defaultReferenceSearchOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +106,7 @@ let findReferencesCommand: ICommandHandler = (accessor: ServicesAccessor, resour
|
||||
|
||||
const codeEditorService = accessor.get(ICodeEditorService);
|
||||
return codeEditorService.openCodeEditor({ resource }, codeEditorService.getFocusedCodeEditor()).then(control => {
|
||||
if (!isCodeEditor(control)) {
|
||||
if (!isCodeEditor(control) || !control.hasModel()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -139,10 +141,11 @@ let showReferencesCommand: ICommandHandler = (accessor: ServicesAccessor, resour
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return Promise.resolve(controller.toggleWidget(
|
||||
return controller.toggleWidget(
|
||||
new Range(position.lineNumber, position.column, position.lineNumber, position.column),
|
||||
createCancelablePromise(_ => Promise.resolve(new ReferencesModel(references))),
|
||||
defaultReferenceSearchOptions)).then(() => true);
|
||||
defaultReferenceSearchOptions
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ export const ctxReferenceSearchVisible = new RawContextKey<boolean>('referenceSe
|
||||
|
||||
export interface RequestOptions {
|
||||
getMetaTitle(model: ReferencesModel): string;
|
||||
onGoto?: (reference: Location) => Thenable<any>;
|
||||
onGoto?: (reference: Location) => Promise<any>;
|
||||
}
|
||||
|
||||
export abstract class ReferencesController implements editorCommon.IEditorContribution {
|
||||
@@ -192,7 +192,7 @@ export abstract class ReferencesController implements editorCommon.IEditorContri
|
||||
this._requestIdPool += 1; // Cancel pending requests
|
||||
}
|
||||
|
||||
private _gotoReference(ref: Location): Thenable<any> {
|
||||
private _gotoReference(ref: Location): Promise<any> {
|
||||
this._widget.hide();
|
||||
|
||||
this._ignoreModelChangeEvent = true;
|
||||
|
||||
@@ -11,7 +11,7 @@ import * as strings from 'vs/base/common/strings';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { defaultGenerator } from 'vs/base/common/idGenerator';
|
||||
import { Range, IRange } from 'vs/editor/common/core/range';
|
||||
import { Location } from 'vs/editor/common/modes';
|
||||
import { Location, LocationLink } from 'vs/editor/common/modes';
|
||||
import { ITextModelService, ITextEditorModel } from 'vs/editor/common/services/resolverService';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
|
||||
@@ -170,7 +170,7 @@ export class ReferencesModel implements IDisposable {
|
||||
readonly _onDidChangeReferenceRange = new Emitter<OneReference>();
|
||||
readonly onDidChangeReferenceRange: Event<OneReference> = this._onDidChangeReferenceRange.event;
|
||||
|
||||
constructor(references: Location[]) {
|
||||
constructor(references: LocationLink[]) {
|
||||
this._disposables = [];
|
||||
// grouping and sorting
|
||||
references.sort(ReferencesModel._compareReferences);
|
||||
@@ -187,7 +187,7 @@ export class ReferencesModel implements IDisposable {
|
||||
if (current.children.length === 0
|
||||
|| !Range.equalsRange(ref.range, current.children[current.children.length - 1].range)) {
|
||||
|
||||
let oneRef = new OneReference(current, ref.range);
|
||||
let oneRef = new OneReference(current, ref.targetSelectionRange || ref.range);
|
||||
this._disposables.push(oneRef.onRefChanged((e) => this._onDidChangeReferenceRange.fire(e)));
|
||||
this.references.push(oneRef);
|
||||
current.children.push(oneRef);
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
|
||||
|
||||
import { ReferencesModel, FileReferences, OneReference } from './referencesModel';
|
||||
import { IDataSource } from 'vs/base/browser/ui/tree/asyncDataTree';
|
||||
import { ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { ITreeRenderer, ITreeNode } from 'vs/base/browser/ui/tree/tree';
|
||||
import { ITreeRenderer, ITreeNode, IAsyncDataSource } from 'vs/base/browser/ui/tree/tree';
|
||||
import { IconLabel } from 'vs/base/browser/ui/iconLabel/iconLabel';
|
||||
import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
|
||||
import { ILabelService } from 'vs/platform/label/common/label';
|
||||
@@ -21,24 +20,22 @@ import { escape } from 'vs/base/common/strings';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
|
||||
import { IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
|
||||
import { IListVirtualDelegate, IKeyboardNavigationLabelProvider, IIdentityProvider } from 'vs/base/browser/ui/list/list';
|
||||
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { basename } from 'vs/base/common/paths';
|
||||
import { FuzzyScore, createMatches, IMatch } from 'vs/base/common/filters';
|
||||
|
||||
//#region data source
|
||||
|
||||
export type TreeElement = FileReferences | OneReference;
|
||||
|
||||
export class DataSource implements IDataSource<TreeElement> {
|
||||
export class DataSource implements IAsyncDataSource<ReferencesModel | FileReferences, TreeElement> {
|
||||
|
||||
root: ReferencesModel | FileReferences;
|
||||
constructor(@ITextModelService private readonly _resolverService: ITextModelService) { }
|
||||
|
||||
constructor(
|
||||
@ITextModelService private readonly _resolverService: ITextModelService,
|
||||
) {
|
||||
//
|
||||
}
|
||||
|
||||
hasChildren(element: TreeElement): boolean {
|
||||
if (!element) {
|
||||
hasChildren(element: ReferencesModel | FileReferences | TreeElement): boolean {
|
||||
if (element instanceof ReferencesModel) {
|
||||
return true;
|
||||
}
|
||||
if (element instanceof FileReferences && !element.failure) {
|
||||
@@ -47,10 +44,11 @@ export class DataSource implements IDataSource<TreeElement> {
|
||||
return false;
|
||||
}
|
||||
|
||||
getChildren(element: TreeElement): Thenable<TreeElement[]> {
|
||||
if (!element && this.root instanceof FileReferences) {
|
||||
element = this.root;
|
||||
getChildren(element: ReferencesModel | FileReferences | TreeElement): TreeElement[] | Promise<TreeElement[]> {
|
||||
if (element instanceof ReferencesModel) {
|
||||
return element.groups;
|
||||
}
|
||||
|
||||
if (element instanceof FileReferences) {
|
||||
return element.resolve(this._resolverService).then(val => {
|
||||
// if (element.failure) {
|
||||
@@ -61,9 +59,7 @@ export class DataSource implements IDataSource<TreeElement> {
|
||||
return val.children;
|
||||
});
|
||||
}
|
||||
if (this.root instanceof ReferencesModel) {
|
||||
return Promise.resolve(this.root.groups);
|
||||
}
|
||||
|
||||
throw new Error('bad tree');
|
||||
}
|
||||
}
|
||||
@@ -83,6 +79,28 @@ export class Delegate implements IListVirtualDelegate<TreeElement> {
|
||||
}
|
||||
}
|
||||
|
||||
export class StringRepresentationProvider implements IKeyboardNavigationLabelProvider<TreeElement> {
|
||||
|
||||
constructor(@IKeybindingService private readonly _keybindingService: IKeybindingService) { }
|
||||
|
||||
getKeyboardNavigationLabel(element: TreeElement): { toString(): string; } {
|
||||
// todo@joao `OneReference` elements are lazy and their "real" label
|
||||
// isn't known yet
|
||||
return basename(element.uri.path);
|
||||
}
|
||||
|
||||
mightProducePrintableCharacter(event: IKeyboardEvent): boolean {
|
||||
return this._keybindingService.mightProducePrintableCharacter(event);
|
||||
}
|
||||
}
|
||||
|
||||
export class IdentityProvider implements IIdentityProvider<TreeElement> {
|
||||
|
||||
getId(element: TreeElement): { toString(): string; } {
|
||||
return element.id;
|
||||
}
|
||||
}
|
||||
|
||||
//#region render: File
|
||||
|
||||
class FileReferencesTemplate extends Disposable {
|
||||
@@ -98,7 +116,7 @@ class FileReferencesTemplate extends Disposable {
|
||||
super();
|
||||
const parent = document.createElement('div');
|
||||
dom.addClass(parent, 'reference-file');
|
||||
this.file = this._register(new IconLabel(parent));
|
||||
this.file = this._register(new IconLabel(parent, { supportHighlights: true }));
|
||||
|
||||
this.badge = new CountBadge(dom.append(parent, dom.$('.count')));
|
||||
this._register(attachBadgeStyler(this.badge, themeService));
|
||||
@@ -106,9 +124,9 @@ class FileReferencesTemplate extends Disposable {
|
||||
container.appendChild(parent);
|
||||
}
|
||||
|
||||
set(element: FileReferences) {
|
||||
set(element: FileReferences, matches: IMatch[]) {
|
||||
let parent = dirname(element.uri);
|
||||
this.file.setValue(getBaseLabel(element.uri), parent ? this._uriLabel.getUriLabel(parent, { relative: true }) : undefined, { title: this._uriLabel.getUriLabel(element.uri) });
|
||||
this.file.setLabel(getBaseLabel(element.uri), parent ? this._uriLabel.getUriLabel(parent, { relative: true }) : undefined, { title: this._uriLabel.getUriLabel(element.uri), matches });
|
||||
const len = element.children.length;
|
||||
this.badge.setCount(len);
|
||||
if (element.failure) {
|
||||
@@ -121,7 +139,7 @@ class FileReferencesTemplate extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
export class FileReferencesRenderer implements ITreeRenderer<FileReferences, void, FileReferencesTemplate> {
|
||||
export class FileReferencesRenderer implements ITreeRenderer<FileReferences, FuzzyScore, FileReferencesTemplate> {
|
||||
|
||||
static readonly id = 'FileReferencesRenderer';
|
||||
|
||||
@@ -132,11 +150,8 @@ export class FileReferencesRenderer implements ITreeRenderer<FileReferences, voi
|
||||
renderTemplate(container: HTMLElement): FileReferencesTemplate {
|
||||
return this._instantiationService.createInstance(FileReferencesTemplate, container);
|
||||
}
|
||||
renderElement(node: ITreeNode<FileReferences, void>, index: number, template: FileReferencesTemplate): void {
|
||||
template.set(node.element);
|
||||
}
|
||||
disposeElement(element: ITreeNode<FileReferences, void>, index: number, templateData: FileReferencesTemplate): void {
|
||||
//
|
||||
renderElement(node: ITreeNode<FileReferences, FuzzyScore>, index: number, template: FileReferencesTemplate): void {
|
||||
template.set(node.element, createMatches(node.filterData));
|
||||
}
|
||||
disposeTemplate(templateData: FileReferencesTemplate): void {
|
||||
templateData.dispose();
|
||||
@@ -177,7 +192,7 @@ class OneReferenceTemplate {
|
||||
}
|
||||
}
|
||||
|
||||
export class OneReferenceRenderer implements ITreeRenderer<OneReference, void, OneReferenceTemplate> {
|
||||
export class OneReferenceRenderer implements ITreeRenderer<OneReference, FuzzyScore, OneReferenceTemplate> {
|
||||
|
||||
static readonly id = 'OneReferenceRenderer';
|
||||
|
||||
@@ -186,12 +201,9 @@ export class OneReferenceRenderer implements ITreeRenderer<OneReference, void, O
|
||||
renderTemplate(container: HTMLElement): OneReferenceTemplate {
|
||||
return new OneReferenceTemplate(container);
|
||||
}
|
||||
renderElement(element: ITreeNode<OneReference, void>, index: number, templateData: OneReferenceTemplate): void {
|
||||
renderElement(element: ITreeNode<OneReference, FuzzyScore>, index: number, templateData: OneReferenceTemplate): void {
|
||||
templateData.set(element.element);
|
||||
}
|
||||
disposeElement(): void {
|
||||
//
|
||||
}
|
||||
disposeTemplate(): void {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import { IModelDeltaDecoration, TrackedRangeStickiness } from 'vs/editor/common/
|
||||
import { ModelDecorationOptions, TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { Location } from 'vs/editor/common/modes';
|
||||
import { ITextEditorModel, ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { AriaProvider, DataSource, Delegate, FileReferencesRenderer, OneReferenceRenderer, TreeElement } from 'vs/editor/contrib/referenceSearch/referencesTree';
|
||||
import { AriaProvider, DataSource, Delegate, FileReferencesRenderer, OneReferenceRenderer, TreeElement, StringRepresentationProvider, IdentityProvider } from 'vs/editor/contrib/referenceSearch/referencesTree';
|
||||
import * as nls from 'vs/nls';
|
||||
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
@@ -31,6 +31,10 @@ import { activeContrastBorder, contrastBorder, registerColor } from 'vs/platform
|
||||
import { ITheme, IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
|
||||
import { PeekViewWidget } from './peekViewWidget';
|
||||
import { FileReferences, OneReference, ReferencesModel } from './referencesModel';
|
||||
import { ITreeRenderer, IAsyncDataSource } from 'vs/base/browser/ui/tree/tree';
|
||||
import { IAsyncDataTreeOptions } from 'vs/base/browser/ui/tree/asyncDataTree';
|
||||
import { IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
|
||||
import { FuzzyScore } from 'vs/base/common/filters';
|
||||
|
||||
class DecorationsManager implements IDisposable {
|
||||
|
||||
@@ -69,6 +73,9 @@ class DecorationsManager implements IDisposable {
|
||||
}
|
||||
|
||||
private _addDecorations(reference: FileReferences): void {
|
||||
if (!this._editor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
this._callOnModelChange.push(this._editor.getModel().onDidChangeDecorations((event) => this._onDecorationChanged()));
|
||||
|
||||
const newDecorations: IModelDeltaDecoration[] = [];
|
||||
@@ -95,8 +102,13 @@ class DecorationsManager implements IDisposable {
|
||||
private _onDecorationChanged(): void {
|
||||
const toRemove: string[] = [];
|
||||
|
||||
const model = this._editor.getModel();
|
||||
if (!model) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._decorations.forEach((reference, decorationId) => {
|
||||
const newRange = this._editor.getModel().getDecorationRange(decorationId);
|
||||
const newRange = model.getDecorationRange(decorationId);
|
||||
|
||||
if (!newRange) {
|
||||
return;
|
||||
@@ -217,7 +229,7 @@ export interface LayoutData {
|
||||
export interface SelectionEvent {
|
||||
kind: 'goto' | 'show' | 'side' | 'open';
|
||||
source: 'editor' | 'tree' | 'title';
|
||||
element: Location;
|
||||
element?: Location;
|
||||
}
|
||||
|
||||
export const ctxReferenceWidgetSearchTreeFocused = new RawContextKey<boolean>('referenceSearchTreeFocused', true);
|
||||
@@ -227,15 +239,14 @@ export const ctxReferenceWidgetSearchTreeFocused = new RawContextKey<boolean>('r
|
||||
*/
|
||||
export class ReferenceWidget extends PeekViewWidget {
|
||||
|
||||
private _model: ReferencesModel;
|
||||
private _model: ReferencesModel | undefined;
|
||||
private _decorationsManager: DecorationsManager;
|
||||
|
||||
private _disposeOnNewModel: IDisposable[] = [];
|
||||
private _callOnDispose: IDisposable[] = [];
|
||||
private _onDidSelectReference = new Emitter<SelectionEvent>();
|
||||
|
||||
private _treeDataSource: DataSource;
|
||||
private _tree: WorkbenchAsyncDataTree<TreeElement>;
|
||||
private _tree: WorkbenchAsyncDataTree<ReferencesModel | FileReferences, TreeElement, FuzzyScore>;
|
||||
private _treeContainer: HTMLElement;
|
||||
private _sash: VSash;
|
||||
private _preview: ICodeEditor;
|
||||
@@ -243,6 +254,8 @@ export class ReferenceWidget extends PeekViewWidget {
|
||||
private _previewNotAvailableMessage: TextModel;
|
||||
private _previewContainer: HTMLElement;
|
||||
private _messageContainer: HTMLElement;
|
||||
private height: number | undefined;
|
||||
private width: number | undefined;
|
||||
|
||||
constructor(
|
||||
editor: ICodeEditor,
|
||||
@@ -272,7 +285,7 @@ export class ReferenceWidget extends PeekViewWidget {
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.setModel(null);
|
||||
this.setModel(undefined);
|
||||
this._callOnDispose = dispose(this._callOnDispose);
|
||||
dispose<IDisposable>(this._preview, this._previewNotAvailableMessage, this._tree, this._sash, this._previewModelReference);
|
||||
super.dispose();
|
||||
@@ -330,38 +343,42 @@ export class ReferenceWidget extends PeekViewWidget {
|
||||
this._previewNotAvailableMessage = TextModel.createFromString(nls.localize('missingPreviewMessage', "no preview available"));
|
||||
|
||||
// sash
|
||||
this._sash = new VSash(containerElement, this.layoutData.ratio || .8);
|
||||
this._sash = new VSash(containerElement, this.layoutData.ratio || 0.8);
|
||||
this._sash.onDidChangePercentages(() => {
|
||||
let [left, right] = this._sash.percentages;
|
||||
this._previewContainer.style.width = left;
|
||||
this._treeContainer.style.width = right;
|
||||
this._preview.layout();
|
||||
this._tree.layout();
|
||||
this._tree.layout(this.height, this.width && this.width * (1 - this._sash.ratio));
|
||||
this.layoutData.ratio = this._sash.ratio;
|
||||
});
|
||||
|
||||
// tree
|
||||
this._treeContainer = dom.append(containerElement, dom.$('div.ref-tree.inline'));
|
||||
|
||||
const renderer = [
|
||||
const renderers = [
|
||||
this._instantiationService.createInstance(FileReferencesRenderer),
|
||||
this._instantiationService.createInstance(OneReferenceRenderer),
|
||||
];
|
||||
|
||||
const treeOptions = {
|
||||
const treeOptions: IAsyncDataTreeOptions<TreeElement, FuzzyScore> = {
|
||||
ariaLabel: nls.localize('treeAriaLabel', "References"),
|
||||
keyboardSupport: this._defaultTreeKeyboardSupport,
|
||||
accessibilityProvider: new AriaProvider()
|
||||
accessibilityProvider: new AriaProvider(),
|
||||
keyboardNavigationLabelProvider: this._instantiationService.createInstance(StringRepresentationProvider),
|
||||
identityProvider: new IdentityProvider()
|
||||
};
|
||||
|
||||
this._treeDataSource = this._instantiationService.createInstance(DataSource);
|
||||
const treeDataSource = this._instantiationService.createInstance(DataSource);
|
||||
|
||||
this._tree = this._instantiationService.createInstance(
|
||||
WorkbenchAsyncDataTree, this._treeContainer, new Delegate(),
|
||||
renderer as any,
|
||||
this._treeDataSource,
|
||||
this._tree = this._instantiationService.createInstance<HTMLElement, IListVirtualDelegate<TreeElement>, ITreeRenderer<any, FuzzyScore, any>[], IAsyncDataSource<ReferencesModel | FileReferences, TreeElement>, IAsyncDataTreeOptions<TreeElement, FuzzyScore>, WorkbenchAsyncDataTree<ReferencesModel | FileReferences, TreeElement, FuzzyScore>>(
|
||||
WorkbenchAsyncDataTree,
|
||||
this._treeContainer,
|
||||
new Delegate(),
|
||||
renderers,
|
||||
treeDataSource,
|
||||
treeOptions
|
||||
) as any as WorkbenchAsyncDataTree<TreeElement>;
|
||||
);
|
||||
|
||||
ctxReferenceWidgetSearchTreeFocused.bindTo(this._tree.contextKeyService);
|
||||
|
||||
@@ -385,7 +402,7 @@ export class ReferenceWidget extends PeekViewWidget {
|
||||
goto = true;
|
||||
|
||||
} else if (e.browserEvent instanceof MouseEvent) {
|
||||
aside = e.browserEvent.metaKey || e.browserEvent.metaKey || e.browserEvent.altKey;
|
||||
aside = e.browserEvent.ctrlKey || e.browserEvent.metaKey || e.browserEvent.altKey;
|
||||
goto = e.browserEvent.detail === 2;
|
||||
}
|
||||
if (aside) {
|
||||
@@ -403,6 +420,9 @@ export class ReferenceWidget extends PeekViewWidget {
|
||||
protected _doLayoutBody(heightInPixel: number, widthInPixel: number): void {
|
||||
super._doLayoutBody(heightInPixel, widthInPixel);
|
||||
|
||||
this.height = heightInPixel;
|
||||
this.width = widthInPixel;
|
||||
|
||||
const height = heightInPixel + 'px';
|
||||
this._sash.height = heightInPixel;
|
||||
this._sash.width = widthInPixel;
|
||||
@@ -414,12 +434,12 @@ export class ReferenceWidget extends PeekViewWidget {
|
||||
this._treeContainer.style.height = height;
|
||||
this._treeContainer.style.width = right;
|
||||
// forward
|
||||
this._tree.layout(heightInPixel);
|
||||
this._tree.layout(heightInPixel, widthInPixel * (1 - this._sash.ratio));
|
||||
this._preview.layout();
|
||||
|
||||
// store layout data
|
||||
this.layoutData = {
|
||||
heightInLines: this._viewZone.heightInLines,
|
||||
heightInLines: this._viewZone ? this._viewZone.heightInLines : 0,
|
||||
ratio: this._sash.ratio
|
||||
};
|
||||
}
|
||||
@@ -441,7 +461,7 @@ export class ReferenceWidget extends PeekViewWidget {
|
||||
});
|
||||
}
|
||||
|
||||
public setModel(newModel: ReferencesModel): Thenable<any> {
|
||||
public setModel(newModel: ReferencesModel | undefined): Promise<any> | undefined {
|
||||
// clean up
|
||||
this._disposeOnNewModel = dispose(this._disposeOnNewModel);
|
||||
this._model = newModel;
|
||||
@@ -451,13 +471,16 @@ export class ReferenceWidget extends PeekViewWidget {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private _onNewModel(): Thenable<any> {
|
||||
private _onNewModel(): Promise<any> {
|
||||
if (!this._model) {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
if (this._model.empty) {
|
||||
this.setTitle('');
|
||||
this._messageContainer.innerHTML = nls.localize('noResults', "No results");
|
||||
dom.show(this._messageContainer);
|
||||
return Promise.resolve(void 0);
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
dom.hide(this._messageContainer);
|
||||
@@ -478,7 +501,7 @@ export class ReferenceWidget extends PeekViewWidget {
|
||||
return;
|
||||
}
|
||||
this._onDidSelectReference.fire({
|
||||
element: { uri: element.uri, range: target.range },
|
||||
element: { uri: element.uri, range: target.range! },
|
||||
kind: (event.ctrlKey || event.metaKey || event.altKey) ? 'side' : 'open',
|
||||
source: 'editor'
|
||||
});
|
||||
@@ -493,11 +516,10 @@ export class ReferenceWidget extends PeekViewWidget {
|
||||
this.focus();
|
||||
|
||||
// pick input and a reference to begin with
|
||||
this._treeDataSource.root = this._model.groups.length === 1 ? this._model.groups[0] : this._model;
|
||||
return this._tree.refresh(null);
|
||||
return this._tree.setInput(this._model.groups.length === 1 ? this._model.groups[0] : this._model);
|
||||
}
|
||||
|
||||
private _getFocusedReference(): OneReference {
|
||||
private _getFocusedReference(): OneReference | undefined {
|
||||
const [element] = this._tree.getFocus();
|
||||
if (element instanceof OneReference) {
|
||||
return element;
|
||||
@@ -521,14 +543,14 @@ export class ReferenceWidget extends PeekViewWidget {
|
||||
|
||||
// Update widget header
|
||||
if (reference.uri.scheme !== Schemas.inMemory) {
|
||||
this.setTitle(basenameOrAuthority(reference.uri), this._uriLabel.getUriLabel(dirname(reference.uri)));
|
||||
this.setTitle(basenameOrAuthority(reference.uri), this._uriLabel.getUriLabel(dirname(reference.uri)!));
|
||||
} else {
|
||||
this.setTitle(nls.localize('peekView.alternateTitle', "References"));
|
||||
}
|
||||
|
||||
const promise = this._textModelResolverService.createModelReference(reference.uri);
|
||||
|
||||
if (this._treeDataSource.root === reference.parent) {
|
||||
if (this._tree.getInput() === reference.parent) {
|
||||
this._tree.reveal(reference);
|
||||
} else {
|
||||
if (revealParent) {
|
||||
|
||||
@@ -23,16 +23,16 @@ suite('references', function () {
|
||||
}]);
|
||||
|
||||
let ref = model.nearestReference(URI.file('/src/can'), new Position(1, 1));
|
||||
assert.equal(ref.uri.path, '/src/can');
|
||||
assert.equal(ref!.uri.path, '/src/can');
|
||||
|
||||
ref = model.nearestReference(URI.file('/src/someOtherFileInSrc'), new Position(1, 1));
|
||||
assert.equal(ref.uri.path, '/src/can');
|
||||
assert.equal(ref!.uri.path, '/src/can');
|
||||
|
||||
ref = model.nearestReference(URI.file('/out/someOtherFile'), new Position(1, 1));
|
||||
assert.equal(ref.uri.path, '/out/obj/can');
|
||||
assert.equal(ref!.uri.path, '/out/obj/can');
|
||||
|
||||
ref = model.nearestReference(URI.file('/out/obj/can2222'), new Position(1, 1));
|
||||
assert.equal(ref.uri.path, '/out/obj/can2');
|
||||
assert.equal(ref!.uri.path, '/out/obj/can2');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user