mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
221
src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts
Normal file
221
src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts
Normal file
@@ -0,0 +1,221 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as nls from 'vs/nls';
|
||||
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IEditorService } from 'vs/platform/editor/common/editor';
|
||||
import { optional } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
|
||||
import { IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { Position, IPosition } from 'vs/editor/common/core/position';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { editorAction, ServicesAccessor, EditorAction, CommonEditorRegistry, commonEditorContribution } from 'vs/editor/common/editorCommonExtensions';
|
||||
import { Location, ReferenceProviderRegistry } from 'vs/editor/common/modes';
|
||||
import { IPeekViewService, PeekContext, getOuterEditor } from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget';
|
||||
import { ReferencesController, RequestOptions, ctxReferenceSearchVisible } from './referencesController';
|
||||
import { ReferencesModel } from './referencesModel';
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import { onUnexpectedExternalError } from 'vs/base/common/errors';
|
||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
|
||||
const defaultReferenceSearchOptions: RequestOptions = {
|
||||
getMetaTitle(model) {
|
||||
return model.references.length > 1 && nls.localize('meta.titleReference', " – {0} references", model.references.length);
|
||||
}
|
||||
};
|
||||
|
||||
@commonEditorContribution
|
||||
export class ReferenceController implements editorCommon.IEditorContribution {
|
||||
|
||||
private static ID = 'editor.contrib.referenceController';
|
||||
|
||||
constructor(
|
||||
editor: editorCommon.ICommonCodeEditor,
|
||||
@IContextKeyService contextKeyService: IContextKeyService,
|
||||
@optional(IPeekViewService) peekViewService: IPeekViewService
|
||||
) {
|
||||
if (peekViewService) {
|
||||
PeekContext.inPeekEditor.bindTo(contextKeyService);
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
}
|
||||
|
||||
public getId(): string {
|
||||
return ReferenceController.ID;
|
||||
}
|
||||
}
|
||||
|
||||
@editorAction
|
||||
export class ReferenceAction extends EditorAction {
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
id: 'editor.action.referenceSearch.trigger',
|
||||
label: nls.localize('references.action.label', "Find All References"),
|
||||
alias: 'Find All References',
|
||||
precondition: ContextKeyExpr.and(
|
||||
EditorContextKeys.hasReferenceProvider,
|
||||
PeekContext.notInPeekEditor,
|
||||
EditorContextKeys.isInEmbeddedEditor.toNegated()),
|
||||
kbOpts: {
|
||||
kbExpr: EditorContextKeys.textFocus,
|
||||
primary: KeyMod.Shift | KeyCode.F12
|
||||
},
|
||||
menuOpts: {
|
||||
group: 'navigation',
|
||||
order: 1.5
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public run(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor): void {
|
||||
let controller = ReferencesController.get(editor);
|
||||
if (!controller) {
|
||||
return;
|
||||
}
|
||||
let range = editor.getSelection();
|
||||
let model = editor.getModel();
|
||||
let references = provideReferences(model, range.getStartPosition()).then(references => new ReferencesModel(references));
|
||||
controller.toggleWidget(range, references, defaultReferenceSearchOptions);
|
||||
}
|
||||
}
|
||||
|
||||
let findReferencesCommand: ICommandHandler = (accessor: ServicesAccessor, resource: URI, position: IPosition) => {
|
||||
|
||||
if (!(resource instanceof URI)) {
|
||||
throw new Error('illegal argument, uri');
|
||||
}
|
||||
if (!position) {
|
||||
throw new Error('illegal argument, position');
|
||||
}
|
||||
|
||||
return accessor.get(IEditorService).openEditor({ resource }).then(editor => {
|
||||
|
||||
let control = editor.getControl();
|
||||
if (!editorCommon.isCommonCodeEditor(control)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let controller = ReferencesController.get(control);
|
||||
if (!controller) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let references = provideReferences(control.getModel(), Position.lift(position)).then(references => new ReferencesModel(references));
|
||||
let range = new Range(position.lineNumber, position.column, position.lineNumber, position.column);
|
||||
return TPromise.as(controller.toggleWidget(range, references, defaultReferenceSearchOptions));
|
||||
});
|
||||
};
|
||||
|
||||
let showReferencesCommand: ICommandHandler = (accessor: ServicesAccessor, resource: URI, position: IPosition, references: Location[]) => {
|
||||
if (!(resource instanceof URI)) {
|
||||
throw new Error('illegal argument, uri expected');
|
||||
}
|
||||
|
||||
return accessor.get(IEditorService).openEditor({ resource: resource }).then(editor => {
|
||||
|
||||
let control = editor.getControl();
|
||||
if (!editorCommon.isCommonCodeEditor(control)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let controller = ReferencesController.get(control);
|
||||
if (!controller) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return TPromise.as(controller.toggleWidget(
|
||||
new Range(position.lineNumber, position.column, position.lineNumber, position.column),
|
||||
TPromise.as(new ReferencesModel(references)),
|
||||
defaultReferenceSearchOptions)).then(() => true);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
// register commands
|
||||
|
||||
CommandsRegistry.registerCommand('editor.action.findReferences', findReferencesCommand);
|
||||
|
||||
CommandsRegistry.registerCommand('editor.action.showReferences', {
|
||||
handler: showReferencesCommand,
|
||||
description: {
|
||||
description: 'Show references at a position in a file',
|
||||
args: [
|
||||
{ name: 'uri', description: 'The text document in which to show references', constraint: URI },
|
||||
{ name: 'position', description: 'The position at which to show', constraint: Position.isIPosition },
|
||||
{ name: 'locations', description: 'An array of locations.', constraint: Array },
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
function closeActiveReferenceSearch(accessor: ServicesAccessor, args: any) {
|
||||
var outerEditor = getOuterEditor(accessor);
|
||||
if (!outerEditor) {
|
||||
return;
|
||||
}
|
||||
|
||||
let controller = ReferencesController.get(outerEditor);
|
||||
if (!controller) {
|
||||
return;
|
||||
}
|
||||
|
||||
controller.closeWidget();
|
||||
}
|
||||
|
||||
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||
id: 'closeReferenceSearch',
|
||||
weight: CommonEditorRegistry.commandWeight(50),
|
||||
primary: KeyCode.Escape,
|
||||
secondary: [KeyMod.Shift | KeyCode.Escape],
|
||||
when: ContextKeyExpr.and(ctxReferenceSearchVisible, ContextKeyExpr.not('config.editor.stablePeek')),
|
||||
handler: closeActiveReferenceSearch
|
||||
});
|
||||
|
||||
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||
id: 'closeReferenceSearchEditor',
|
||||
weight: CommonEditorRegistry.commandWeight(-101),
|
||||
primary: KeyCode.Escape,
|
||||
secondary: [KeyMod.Shift | KeyCode.Escape],
|
||||
when: ContextKeyExpr.and(PeekContext.inPeekEditor, ContextKeyExpr.not('config.editor.stablePeek')),
|
||||
handler: closeActiveReferenceSearch
|
||||
});
|
||||
|
||||
|
||||
export function provideReferences(model: editorCommon.IReadOnlyModel, position: Position): TPromise<Location[]> {
|
||||
|
||||
// collect references from all providers
|
||||
const promises = ReferenceProviderRegistry.ordered(model).map(provider => {
|
||||
return asWinJsPromise((token) => {
|
||||
return provider.provideReferences(model, position, { includeDeclaration: true }, token);
|
||||
}).then(result => {
|
||||
if (Array.isArray(result)) {
|
||||
return <Location[]>result;
|
||||
}
|
||||
return undefined;
|
||||
}, err => {
|
||||
onUnexpectedExternalError(err);
|
||||
});
|
||||
});
|
||||
|
||||
return TPromise.join(promises).then(references => {
|
||||
let result: Location[] = [];
|
||||
for (let ref of references) {
|
||||
if (ref) {
|
||||
result.push(...ref);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
CommonEditorRegistry.registerDefaultLanguageCommand('_executeReferenceProvider', provideReferences);
|
||||
@@ -0,0 +1,262 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as nls from 'vs/nls';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IEditorService } from 'vs/platform/editor/common/editor';
|
||||
import { fromPromise, stopwatch } from 'vs/base/common/event';
|
||||
import { IInstantiationService, optional } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IMessageService } from 'vs/platform/message/common/message';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions';
|
||||
import { IPeekViewService } from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget';
|
||||
import { ReferencesModel, OneReference } from './referencesModel';
|
||||
import { ReferenceWidget, LayoutData } from './referencesWidget';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
|
||||
export const ctxReferenceSearchVisible = new RawContextKey<boolean>('referenceSearchVisible', false);
|
||||
|
||||
export interface RequestOptions {
|
||||
getMetaTitle(model: ReferencesModel): string;
|
||||
onGoto?: (reference: OneReference) => TPromise<any>;
|
||||
}
|
||||
|
||||
@editorContribution
|
||||
export class ReferencesController implements editorCommon.IEditorContribution {
|
||||
|
||||
private static ID = 'editor.contrib.referencesController';
|
||||
|
||||
private _editor: ICodeEditor;
|
||||
private _widget: ReferenceWidget;
|
||||
private _model: ReferencesModel;
|
||||
private _requestIdPool = 0;
|
||||
private _disposables: IDisposable[] = [];
|
||||
private _ignoreModelChangeEvent = false;
|
||||
|
||||
private _referenceSearchVisible: IContextKey<boolean>;
|
||||
|
||||
public static get(editor: editorCommon.ICommonCodeEditor): ReferencesController {
|
||||
return editor.getContribution<ReferencesController>(ReferencesController.ID);
|
||||
}
|
||||
|
||||
public constructor(
|
||||
editor: ICodeEditor,
|
||||
@IContextKeyService contextKeyService: IContextKeyService,
|
||||
@IEditorService private _editorService: IEditorService,
|
||||
@ITextModelService private _textModelResolverService: ITextModelService,
|
||||
@ITelemetryService private _telemetryService: ITelemetryService,
|
||||
@IMessageService private _messageService: IMessageService,
|
||||
@IInstantiationService private _instantiationService: IInstantiationService,
|
||||
@IWorkspaceContextService private _contextService: IWorkspaceContextService,
|
||||
@IStorageService private _storageService: IStorageService,
|
||||
@IThemeService private _themeService: IThemeService,
|
||||
@IConfigurationService private _configurationService: IConfigurationService,
|
||||
@optional(IPeekViewService) private _peekViewService: IPeekViewService,
|
||||
@optional(IEnvironmentService) private _environmentService: IEnvironmentService
|
||||
) {
|
||||
this._editor = editor;
|
||||
this._referenceSearchVisible = ctxReferenceSearchVisible.bindTo(contextKeyService);
|
||||
}
|
||||
|
||||
public getId(): string {
|
||||
return ReferencesController.ID;
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
if (this._widget) {
|
||||
this._widget.dispose();
|
||||
this._widget = null;
|
||||
}
|
||||
this._editor = null;
|
||||
}
|
||||
|
||||
public toggleWidget(range: Range, modelPromise: TPromise<ReferencesModel>, options: RequestOptions): void {
|
||||
|
||||
// close current widget and return early is position didn't change
|
||||
let widgetPosition: Position;
|
||||
if (this._widget) {
|
||||
widgetPosition = this._widget.position;
|
||||
}
|
||||
this.closeWidget();
|
||||
if (!!widgetPosition && range.containsPosition(widgetPosition)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
this._referenceSearchVisible.set(true);
|
||||
|
||||
// close the widget on model/mode changes
|
||||
this._disposables.push(this._editor.onDidChangeModelLanguage(() => { this.closeWidget(); }));
|
||||
this._disposables.push(this._editor.onDidChangeModel(() => {
|
||||
if (!this._ignoreModelChangeEvent) {
|
||||
this.closeWidget();
|
||||
}
|
||||
}));
|
||||
const storageKey = 'peekViewLayout';
|
||||
const data = <LayoutData>JSON.parse(this._storageService.get(storageKey, undefined, '{}'));
|
||||
this._widget = new ReferenceWidget(this._editor, data, this._textModelResolverService, this._contextService, this._themeService, this._instantiationService, this._environmentService);
|
||||
this._widget.setTitle(nls.localize('labelLoading', "Loading..."));
|
||||
this._widget.show(range);
|
||||
this._disposables.push(this._widget.onDidClose(() => {
|
||||
modelPromise.cancel();
|
||||
|
||||
this._storageService.store(storageKey, JSON.stringify(this._widget.layoutData));
|
||||
this._widget = null;
|
||||
this.closeWidget();
|
||||
}));
|
||||
|
||||
this._disposables.push(this._widget.onDidSelectReference(event => {
|
||||
let { element, kind } = event;
|
||||
switch (kind) {
|
||||
case 'open':
|
||||
if (event.source === 'editor'
|
||||
&& this._configurationService.lookup('editor.stablePeek').value) {
|
||||
|
||||
// when stable peek is configured we don't close
|
||||
// the peek window on selecting the editor
|
||||
break;
|
||||
}
|
||||
case 'side':
|
||||
this._openReference(element, kind === 'side');
|
||||
break;
|
||||
case 'goto':
|
||||
if (options.onGoto) {
|
||||
options.onGoto(element);
|
||||
} else {
|
||||
this._gotoReference(element);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}));
|
||||
|
||||
const requestId = ++this._requestIdPool;
|
||||
|
||||
const promise = modelPromise.then(model => {
|
||||
|
||||
// still current request? widget still open?
|
||||
if (requestId !== this._requestIdPool || !this._widget) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (this._model) {
|
||||
this._model.dispose();
|
||||
}
|
||||
|
||||
this._model = model;
|
||||
|
||||
// measure time it stays open
|
||||
const startTime = Date.now();
|
||||
this._disposables.push({
|
||||
dispose: () => {
|
||||
this._telemetryService.publicLog('zoneWidgetShown', {
|
||||
mode: 'reference search',
|
||||
elapsedTime: Date.now() - startTime
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// show widget
|
||||
return this._widget.setModel(this._model).then(() => {
|
||||
|
||||
// set title
|
||||
this._widget.setMetaTitle(options.getMetaTitle(this._model));
|
||||
|
||||
// set 'best' selection
|
||||
let uri = this._editor.getModel().uri;
|
||||
let pos = new Position(range.startLineNumber, range.startColumn);
|
||||
let selection = this._model.nearestReference(uri, pos);
|
||||
if (selection) {
|
||||
return this._widget.setSelection(selection);
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
}, error => {
|
||||
this._messageService.show(Severity.Error, error);
|
||||
});
|
||||
|
||||
const onDone = stopwatch(fromPromise(promise));
|
||||
const mode = this._editor.getModel().getLanguageIdentifier().language;
|
||||
|
||||
onDone(duration => this._telemetryService.publicLog('findReferences', {
|
||||
duration,
|
||||
mode
|
||||
}));
|
||||
}
|
||||
|
||||
public closeWidget(): void {
|
||||
if (this._widget) {
|
||||
this._widget.dispose();
|
||||
this._widget = null;
|
||||
}
|
||||
this._referenceSearchVisible.reset();
|
||||
this._disposables = dispose(this._disposables);
|
||||
if (this._model) {
|
||||
this._model.dispose();
|
||||
this._model = null;
|
||||
}
|
||||
this._editor.focus();
|
||||
this._requestIdPool += 1; // Cancel pending requests
|
||||
}
|
||||
|
||||
private _gotoReference(ref: OneReference): void {
|
||||
this._widget.hide();
|
||||
|
||||
this._ignoreModelChangeEvent = true;
|
||||
const { uri, range } = ref;
|
||||
|
||||
this._editorService.openEditor({
|
||||
resource: uri,
|
||||
options: { selection: range }
|
||||
}).done(openedEditor => {
|
||||
this._ignoreModelChangeEvent = false;
|
||||
|
||||
if (!openedEditor || openedEditor.getControl() !== this._editor) {
|
||||
// TODO@Alex TODO@Joh
|
||||
// when opening the current reference we might end up
|
||||
// in a different editor instance. that means we also have
|
||||
// a different instance of this reference search controller
|
||||
// and cannot hold onto the widget (which likely doesn't
|
||||
// exist). Instead of bailing out we should find the
|
||||
// 'sister' action and pass our current model on to it.
|
||||
this.closeWidget();
|
||||
return;
|
||||
}
|
||||
|
||||
this._widget.show(range);
|
||||
this._widget.focus();
|
||||
|
||||
}, (err) => {
|
||||
this._ignoreModelChangeEvent = false;
|
||||
onUnexpectedError(err);
|
||||
});
|
||||
}
|
||||
|
||||
private _openReference(ref: OneReference, sideBySide: boolean): void {
|
||||
const { uri, range } = ref;
|
||||
this._editorService.openEditor({
|
||||
resource: uri,
|
||||
options: { selection: range }
|
||||
}, sideBySide);
|
||||
|
||||
// clear stage
|
||||
if (!sideBySide) {
|
||||
this.closeWidget();
|
||||
}
|
||||
}
|
||||
}
|
||||
313
src/vs/editor/contrib/referenceSearch/browser/referencesModel.ts
Normal file
313
src/vs/editor/contrib/referenceSearch/browser/referencesModel.ts
Normal file
@@ -0,0 +1,313 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { localize } from 'vs/nls';
|
||||
import { EventEmitter } from 'vs/base/common/eventEmitter';
|
||||
import Event, { fromEventEmitter } from 'vs/base/common/event';
|
||||
import { basename, dirname } from 'vs/base/common/paths';
|
||||
import { IDisposable, dispose, IReference } from 'vs/base/common/lifecycle';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { defaultGenerator } from 'vs/base/common/idGenerator';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { Range, IRange } from 'vs/editor/common/core/range';
|
||||
import { Location } from 'vs/editor/common/modes';
|
||||
import { ITextModelService, ITextEditorModel } from 'vs/editor/common/services/resolverService';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
|
||||
export class OneReference {
|
||||
|
||||
private _id: string;
|
||||
|
||||
constructor(
|
||||
private _parent: FileReferences,
|
||||
private _range: IRange,
|
||||
private _eventBus: EventEmitter
|
||||
) {
|
||||
this._id = defaultGenerator.nextId();
|
||||
}
|
||||
|
||||
public get id(): string {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get model(): FileReferences {
|
||||
return this._parent;
|
||||
}
|
||||
|
||||
public get parent(): FileReferences {
|
||||
return this._parent;
|
||||
}
|
||||
|
||||
public get uri(): URI {
|
||||
return this._parent.uri;
|
||||
}
|
||||
|
||||
public get name(): string {
|
||||
return this._parent.name;
|
||||
}
|
||||
|
||||
public get directory(): string {
|
||||
return this._parent.directory;
|
||||
}
|
||||
|
||||
public get range(): IRange {
|
||||
return this._range;
|
||||
}
|
||||
|
||||
public set range(value: IRange) {
|
||||
this._range = value;
|
||||
this._eventBus.emit('ref/changed', this);
|
||||
}
|
||||
|
||||
public getAriaMessage(): string {
|
||||
return localize(
|
||||
'aria.oneReference', "symbol in {0} on line {1} at column {2}",
|
||||
basename(this.uri.fsPath), this.range.startLineNumber, this.range.startColumn
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class FilePreview implements IDisposable {
|
||||
|
||||
constructor(private _modelReference: IReference<ITextEditorModel>) {
|
||||
|
||||
}
|
||||
|
||||
private get _model() { return this._modelReference.object.textEditorModel; }
|
||||
|
||||
public preview(range: IRange, n: number = 8): { before: string; inside: string; after: string } {
|
||||
const model = this._model;
|
||||
|
||||
if (!model) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const { startLineNumber, startColumn, endLineNumber, endColumn } = range;
|
||||
const word = model.getWordUntilPosition({ lineNumber: startLineNumber, column: startColumn - n });
|
||||
const beforeRange = new Range(startLineNumber, word.startColumn, startLineNumber, startColumn);
|
||||
const afterRange = new Range(endLineNumber, endColumn, endLineNumber, Number.MAX_VALUE);
|
||||
|
||||
const ret = {
|
||||
before: model.getValueInRange(beforeRange).replace(/^\s+/, strings.empty),
|
||||
inside: model.getValueInRange(range),
|
||||
after: model.getValueInRange(afterRange).replace(/\s+$/, strings.empty)
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
if (this._modelReference) {
|
||||
this._modelReference.dispose();
|
||||
this._modelReference = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class FileReferences implements IDisposable {
|
||||
|
||||
private _children: OneReference[];
|
||||
private _preview: FilePreview;
|
||||
private _resolved: boolean;
|
||||
private _loadFailure: any;
|
||||
|
||||
constructor(private _parent: ReferencesModel, private _uri: URI) {
|
||||
this._children = [];
|
||||
}
|
||||
|
||||
public get id(): string {
|
||||
return this._uri.toString();
|
||||
}
|
||||
|
||||
public get parent(): ReferencesModel {
|
||||
return this._parent;
|
||||
}
|
||||
|
||||
public get children(): OneReference[] {
|
||||
return this._children;
|
||||
}
|
||||
|
||||
public get uri(): URI {
|
||||
return this._uri;
|
||||
}
|
||||
|
||||
public get name(): string {
|
||||
return basename(this.uri.fsPath);
|
||||
}
|
||||
|
||||
public get directory(): string {
|
||||
return dirname(this.uri.fsPath);
|
||||
}
|
||||
|
||||
public get preview(): FilePreview {
|
||||
return this._preview;
|
||||
}
|
||||
|
||||
public get failure(): any {
|
||||
return this._loadFailure;
|
||||
}
|
||||
|
||||
getAriaMessage(): string {
|
||||
const len = this.children.length;
|
||||
if (len === 1) {
|
||||
return localize('aria.fileReferences.1', "1 symbol in {0}, full path {1}", basename(this.uri.fsPath), this.uri.fsPath);
|
||||
} else {
|
||||
return localize('aria.fileReferences.N', "{0} symbols in {1}, full path {2}", len, basename(this.uri.fsPath), this.uri.fsPath);
|
||||
}
|
||||
}
|
||||
|
||||
public resolve(textModelResolverService: ITextModelService): TPromise<FileReferences> {
|
||||
|
||||
if (this._resolved) {
|
||||
return TPromise.as(this);
|
||||
}
|
||||
|
||||
return textModelResolverService.createModelReference(this._uri).then(modelReference => {
|
||||
const model = modelReference.object;
|
||||
|
||||
if (!model) {
|
||||
modelReference.dispose();
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
this._preview = new FilePreview(modelReference);
|
||||
this._resolved = true;
|
||||
return this;
|
||||
|
||||
}, err => {
|
||||
// something wrong here
|
||||
this._children = [];
|
||||
this._resolved = true;
|
||||
this._loadFailure = err;
|
||||
return this;
|
||||
});
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
if (this._preview) {
|
||||
this._preview.dispose();
|
||||
this._preview = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ReferencesModel implements IDisposable {
|
||||
|
||||
private _groups: FileReferences[] = [];
|
||||
private _references: OneReference[] = [];
|
||||
private _eventBus = new EventEmitter();
|
||||
|
||||
onDidChangeReferenceRange: Event<OneReference> = fromEventEmitter<OneReference>(this._eventBus, 'ref/changed');
|
||||
|
||||
constructor(references: Location[]) {
|
||||
|
||||
// grouping and sorting
|
||||
references.sort(ReferencesModel._compareReferences);
|
||||
|
||||
let current: FileReferences;
|
||||
for (let ref of references) {
|
||||
if (!current || current.uri.toString() !== ref.uri.toString()) {
|
||||
// new group
|
||||
current = new FileReferences(this, ref.uri);
|
||||
this.groups.push(current);
|
||||
}
|
||||
|
||||
// append, check for equality first!
|
||||
if (current.children.length === 0
|
||||
|| !Range.equalsRange(ref.range, current.children[current.children.length - 1].range)) {
|
||||
|
||||
let oneRef = new OneReference(current, ref.range, this._eventBus);
|
||||
this._references.push(oneRef);
|
||||
current.children.push(oneRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public get empty(): boolean {
|
||||
return this._groups.length === 0;
|
||||
}
|
||||
|
||||
public get references(): OneReference[] {
|
||||
return this._references;
|
||||
}
|
||||
|
||||
public get groups(): FileReferences[] {
|
||||
return this._groups;
|
||||
}
|
||||
|
||||
getAriaMessage(): string {
|
||||
if (this.empty) {
|
||||
return localize('aria.result.0', "No results found");
|
||||
} else if (this.references.length === 1) {
|
||||
return localize('aria.result.1', "Found 1 symbol in {0}", this.references[0].uri.fsPath);
|
||||
} else if (this.groups.length === 1) {
|
||||
return localize('aria.result.n1', "Found {0} symbols in {1}", this.references.length, this.groups[0].uri.fsPath);
|
||||
} else {
|
||||
return localize('aria.result.nm', "Found {0} symbols in {1} files", this.references.length, this.groups.length);
|
||||
}
|
||||
}
|
||||
|
||||
public nextReference(reference: OneReference): OneReference {
|
||||
|
||||
var idx = reference.parent.children.indexOf(reference),
|
||||
len = reference.parent.children.length,
|
||||
totalLength = reference.parent.parent.groups.length;
|
||||
|
||||
if (idx + 1 < len || totalLength === 1) {
|
||||
return reference.parent.children[(idx + 1) % len];
|
||||
}
|
||||
|
||||
idx = reference.parent.parent.groups.indexOf(reference.parent);
|
||||
idx = (idx + 1) % totalLength;
|
||||
|
||||
return reference.parent.parent.groups[idx].children[0];
|
||||
}
|
||||
|
||||
public nearestReference(resource: URI, position: Position): OneReference {
|
||||
|
||||
const nearest = this._references.map((ref, idx) => {
|
||||
return {
|
||||
idx,
|
||||
prefixLen: strings.commonPrefixLength(ref.uri.toString(), resource.toString()),
|
||||
offsetDist: Math.abs(ref.range.startLineNumber - position.lineNumber) * 100 + Math.abs(ref.range.startColumn - position.column)
|
||||
};
|
||||
}).sort((a, b) => {
|
||||
if (a.prefixLen > b.prefixLen) {
|
||||
return -1;
|
||||
} else if (a.prefixLen < b.prefixLen) {
|
||||
return 1;
|
||||
} else if (a.offsetDist < b.offsetDist) {
|
||||
return -1;
|
||||
} else if (a.offsetDist > b.offsetDist) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
})[0];
|
||||
|
||||
if (nearest) {
|
||||
return this._references[nearest.idx];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this._groups = dispose(this._groups);
|
||||
}
|
||||
|
||||
private static _compareReferences(a: Location, b: Location): number {
|
||||
const auri = a.uri.toString();
|
||||
const buri = b.uri.toString();
|
||||
if (auri < buri) {
|
||||
return -1;
|
||||
} else if (auri > buri) {
|
||||
return 1;
|
||||
} else {
|
||||
return Range.compareRangesUsingStarts(a.range, b.range);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/* -- zone widget */
|
||||
.monaco-editor .zone-widget .zone-widget-container.reference-zone-widget {
|
||||
border-top-width: 1px;
|
||||
border-bottom-width: 1px;
|
||||
}
|
||||
|
||||
.monaco-editor .zone-widget .zone-widget-container.reference-zone-widget.results-loaded {
|
||||
-webkit-transition: height 100ms ease-in;
|
||||
transition: height 100ms ease-in;
|
||||
}
|
||||
|
||||
.monaco-editor .reference-zone-widget .inline {
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.monaco-editor .reference-zone-widget .messages {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
padding: 3em 0;
|
||||
}
|
||||
|
||||
.monaco-editor .reference-zone-widget .ref-tree {
|
||||
line-height: 22px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.monaco-editor .reference-zone-widget .ref-tree .reference {
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.monaco-editor .reference-zone-widget .ref-tree .reference-file {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.monaco-editor .reference-zone-widget .monaco-count-badge {
|
||||
margin-right: .5em;
|
||||
height: 15px;
|
||||
padding: 0 .5em .5em .5em
|
||||
}
|
||||
|
||||
/* High Contrast Theming */
|
||||
|
||||
.monaco-editor.hc-black .reference-zone-widget .ref-tree .reference-file {
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
@@ -0,0 +1,923 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import 'vs/css!./referencesWidget';
|
||||
import * as nls from 'vs/nls';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { getPathLabel } from 'vs/base/common/labels';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { IDisposable, dispose, IReference } from 'vs/base/common/lifecycle';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { Color } from 'vs/base/common/color';
|
||||
import { $, Builder } from 'vs/base/browser/builder';
|
||||
import * as dom from 'vs/base/browser/dom';
|
||||
import { Sash, ISashEvent, IVerticalSashLayoutProvider } from 'vs/base/browser/ui/sash/sash';
|
||||
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
||||
import { IMouseEvent } from 'vs/base/browser/mouseEvent';
|
||||
import { GestureEvent } from 'vs/base/browser/touch';
|
||||
import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
|
||||
import { FileLabel } from 'vs/base/browser/ui/iconLabel/iconLabel';
|
||||
import * as tree from 'vs/base/parts/tree/browser/tree';
|
||||
import { DefaultController } from 'vs/base/parts/tree/browser/treeDefaults';
|
||||
import { Tree } from 'vs/base/parts/tree/browser/treeImpl';
|
||||
import { IInstantiationService, optional } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { Range, IRange } from 'vs/editor/common/core/range';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { Model } from 'vs/editor/common/model/model';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
|
||||
import { PeekViewWidget, IPeekViewService } from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget';
|
||||
import { FileReferences, OneReference, ReferencesModel } from './referencesModel';
|
||||
import { ITextModelService, ITextEditorModel } from 'vs/editor/common/services/resolverService';
|
||||
import { registerColor, activeContrastBorder, contrastBorder } from 'vs/platform/theme/common/colorRegistry';
|
||||
import { registerThemingParticipant, ITheme, IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { attachListStyler, attachBadgeStyler } from 'vs/platform/theme/common/styler';
|
||||
import { IModelDecorationsChangedEvent } from 'vs/editor/common/model/textModelEvents';
|
||||
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDecorations';
|
||||
import URI from 'vs/base/common/uri';
|
||||
|
||||
class DecorationsManager implements IDisposable {
|
||||
|
||||
private static DecorationOptions = ModelDecorationOptions.register({
|
||||
stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
||||
className: 'reference-decoration'
|
||||
});
|
||||
|
||||
private _decorations = new Map<string, OneReference>();
|
||||
private _decorationIgnoreSet = new Set<string>();
|
||||
private _callOnDispose: IDisposable[] = [];
|
||||
private _callOnModelChange: IDisposable[] = [];
|
||||
|
||||
constructor(private _editor: ICodeEditor, private _model: ReferencesModel) {
|
||||
this._callOnDispose.push(this._editor.onDidChangeModel(() => this._onModelChanged()));
|
||||
this._onModelChanged();
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this._callOnModelChange = dispose(this._callOnModelChange);
|
||||
this._callOnDispose = dispose(this._callOnDispose);
|
||||
this.removeDecorations();
|
||||
}
|
||||
|
||||
private _onModelChanged(): void {
|
||||
this._callOnModelChange = dispose(this._callOnModelChange);
|
||||
const model = this._editor.getModel();
|
||||
if (model) {
|
||||
for (const ref of this._model.groups) {
|
||||
if (ref.uri.toString() === model.uri.toString()) {
|
||||
this._addDecorations(ref);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _addDecorations(reference: FileReferences): void {
|
||||
this._callOnModelChange.push(this._editor.getModel().onDidChangeDecorations((event) => this._onDecorationChanged(event)));
|
||||
|
||||
this._editor.changeDecorations(accessor => {
|
||||
|
||||
const newDecorations: editorCommon.IModelDeltaDecoration[] = [];
|
||||
const newDecorationsActualIndex: number[] = [];
|
||||
|
||||
for (let i = 0, len = reference.children.length; i < len; i++) {
|
||||
let oneReference = reference.children[i];
|
||||
if (this._decorationIgnoreSet.has(oneReference.id)) {
|
||||
continue;
|
||||
}
|
||||
newDecorations.push({
|
||||
range: oneReference.range,
|
||||
options: DecorationsManager.DecorationOptions
|
||||
});
|
||||
newDecorationsActualIndex.push(i);
|
||||
}
|
||||
|
||||
const decorations = accessor.deltaDecorations([], newDecorations);
|
||||
for (let i = 0; i < decorations.length; i++) {
|
||||
this._decorations.set(decorations[i], reference.children[newDecorationsActualIndex[i]]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private _onDecorationChanged(event: IModelDecorationsChangedEvent): void {
|
||||
const changedDecorations = event.changedDecorations,
|
||||
toRemove: string[] = [];
|
||||
|
||||
for (let i = 0, len = changedDecorations.length; i < len; i++) {
|
||||
let reference = this._decorations.get(changedDecorations[i]);
|
||||
if (!reference) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const newRange = this._editor.getModel().getDecorationRange(changedDecorations[i]);
|
||||
let ignore = false;
|
||||
|
||||
if (Range.equalsRange(newRange, reference.range)) {
|
||||
continue;
|
||||
|
||||
} else if (Range.spansMultipleLines(newRange)) {
|
||||
ignore = true;
|
||||
|
||||
} else {
|
||||
const lineLength = reference.range.endColumn - reference.range.startColumn;
|
||||
const newLineLength = newRange.endColumn - newRange.startColumn;
|
||||
|
||||
if (lineLength !== newLineLength) {
|
||||
ignore = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (ignore) {
|
||||
this._decorationIgnoreSet.add(reference.id);
|
||||
toRemove.push(changedDecorations[i]);
|
||||
} else {
|
||||
reference.range = newRange;
|
||||
}
|
||||
}
|
||||
|
||||
this._editor.changeDecorations((accessor) => {
|
||||
for (let i = 0, len = toRemove.length; i < len; i++) {
|
||||
this._decorations.delete(toRemove[i]);
|
||||
}
|
||||
accessor.deltaDecorations(toRemove, []);
|
||||
});
|
||||
}
|
||||
|
||||
public removeDecorations(): void {
|
||||
this._editor.changeDecorations(accessor => {
|
||||
this._decorations.forEach((value, key) => {
|
||||
accessor.removeDecoration(key);
|
||||
});
|
||||
this._decorations.clear();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class DataSource implements tree.IDataSource {
|
||||
|
||||
constructor(
|
||||
@ITextModelService private _textModelResolverService: ITextModelService
|
||||
) {
|
||||
//
|
||||
}
|
||||
|
||||
public getId(tree: tree.ITree, element: any): string {
|
||||
if (element instanceof ReferencesModel) {
|
||||
return 'root';
|
||||
} else if (element instanceof FileReferences) {
|
||||
return (<FileReferences>element).id;
|
||||
} else if (element instanceof OneReference) {
|
||||
return (<OneReference>element).id;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public hasChildren(tree: tree.ITree, element: any): boolean {
|
||||
if (element instanceof ReferencesModel) {
|
||||
return true;
|
||||
}
|
||||
if (element instanceof FileReferences && !(<FileReferences>element).failure) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public getChildren(tree: tree.ITree, element: ReferencesModel | FileReferences): TPromise<any[]> {
|
||||
if (element instanceof ReferencesModel) {
|
||||
return TPromise.as(element.groups);
|
||||
} else if (element instanceof FileReferences) {
|
||||
return element.resolve(this._textModelResolverService).then(val => {
|
||||
if (element.failure) {
|
||||
// refresh the element on failure so that
|
||||
// we can update its rendering
|
||||
return tree.refresh(element).then(() => val.children);
|
||||
}
|
||||
return val.children;
|
||||
});
|
||||
} else {
|
||||
return TPromise.as([]);
|
||||
}
|
||||
}
|
||||
|
||||
public getParent(tree: tree.ITree, element: any): TPromise<any> {
|
||||
var result: any = null;
|
||||
if (element instanceof FileReferences) {
|
||||
result = (<FileReferences>element).parent;
|
||||
} else if (element instanceof OneReference) {
|
||||
result = (<OneReference>element).parent;
|
||||
}
|
||||
return TPromise.as(result);
|
||||
}
|
||||
}
|
||||
|
||||
class Controller extends DefaultController {
|
||||
|
||||
static Events = {
|
||||
FOCUSED: 'events/custom/focused',
|
||||
SELECTED: 'events/custom/selected',
|
||||
OPEN_TO_SIDE: 'events/custom/opentoside'
|
||||
};
|
||||
|
||||
public onTap(tree: tree.ITree, element: any, event: GestureEvent): boolean {
|
||||
if (element instanceof FileReferences) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return this._expandCollapse(tree, element);
|
||||
}
|
||||
|
||||
var result = super.onTap(tree, element, event);
|
||||
tree.emit(Controller.Events.FOCUSED, element);
|
||||
return result;
|
||||
}
|
||||
|
||||
public onMouseDown(tree: tree.ITree, element: any, event: IMouseEvent): boolean {
|
||||
if (event.leftButton) {
|
||||
if (element instanceof FileReferences) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return this._expandCollapse(tree, element);
|
||||
}
|
||||
|
||||
var result = super.onClick(tree, element, event);
|
||||
if (event.ctrlKey || event.metaKey) {
|
||||
tree.emit(Controller.Events.OPEN_TO_SIDE, element);
|
||||
} else if (event.detail === 2) {
|
||||
tree.emit(Controller.Events.SELECTED, element);
|
||||
} else {
|
||||
tree.emit(Controller.Events.FOCUSED, element);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public onClick(tree: tree.ITree, element: any, event: IMouseEvent): boolean {
|
||||
if (event.leftButton) {
|
||||
return false; // Already handled by onMouseDown
|
||||
}
|
||||
|
||||
return super.onClick(tree, element, event);
|
||||
}
|
||||
|
||||
private _expandCollapse(tree: tree.ITree, element: any): boolean {
|
||||
|
||||
if (tree.isExpanded(element)) {
|
||||
tree.collapse(element).done(null, onUnexpectedError);
|
||||
} else {
|
||||
tree.expand(element).done(null, onUnexpectedError);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public onEscape(tree: tree.ITree, event: IKeyboardEvent): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public onEnter(tree: tree.ITree, event: IKeyboardEvent): boolean {
|
||||
var element = tree.getFocus();
|
||||
if (element instanceof FileReferences) {
|
||||
return this._expandCollapse(tree, element);
|
||||
}
|
||||
|
||||
var result = super.onEnter(tree, event);
|
||||
if (event.ctrlKey || event.metaKey) {
|
||||
tree.emit(Controller.Events.OPEN_TO_SIDE, element);
|
||||
} else {
|
||||
tree.emit(Controller.Events.SELECTED, element);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public onUp(tree: tree.ITree, event: IKeyboardEvent): boolean {
|
||||
super.onUp(tree, event);
|
||||
this._fakeFocus(tree, event);
|
||||
return true;
|
||||
}
|
||||
|
||||
public onPageUp(tree: tree.ITree, event: IKeyboardEvent): boolean {
|
||||
super.onPageUp(tree, event);
|
||||
this._fakeFocus(tree, event);
|
||||
return true;
|
||||
}
|
||||
|
||||
public onLeft(tree: tree.ITree, event: IKeyboardEvent): boolean {
|
||||
super.onLeft(tree, event);
|
||||
this._fakeFocus(tree, event);
|
||||
return true;
|
||||
}
|
||||
|
||||
public onDown(tree: tree.ITree, event: IKeyboardEvent): boolean {
|
||||
super.onDown(tree, event);
|
||||
this._fakeFocus(tree, event);
|
||||
return true;
|
||||
}
|
||||
|
||||
public onPageDown(tree: tree.ITree, event: IKeyboardEvent): boolean {
|
||||
super.onPageDown(tree, event);
|
||||
this._fakeFocus(tree, event);
|
||||
return true;
|
||||
}
|
||||
|
||||
public onRight(tree: tree.ITree, event: IKeyboardEvent): boolean {
|
||||
super.onRight(tree, event);
|
||||
this._fakeFocus(tree, event);
|
||||
return true;
|
||||
}
|
||||
|
||||
private _fakeFocus(tree: tree.ITree, event: IKeyboardEvent): void {
|
||||
// focus next item
|
||||
var focus = tree.getFocus();
|
||||
tree.setSelection([focus]);
|
||||
// send out event
|
||||
tree.emit(Controller.Events.FOCUSED, focus);
|
||||
}
|
||||
}
|
||||
|
||||
class FileReferencesTemplate {
|
||||
|
||||
readonly file: FileLabel;
|
||||
readonly badge: CountBadge;
|
||||
readonly dispose: () => void;
|
||||
|
||||
constructor(
|
||||
container: HTMLElement,
|
||||
@IWorkspaceContextService private _contextService: IWorkspaceContextService,
|
||||
@optional(IEnvironmentService) private _environmentService: IEnvironmentService,
|
||||
@IThemeService themeService: IThemeService,
|
||||
) {
|
||||
const parent = document.createElement('div');
|
||||
dom.addClass(parent, 'reference-file');
|
||||
container.appendChild(parent);
|
||||
|
||||
this.file = new FileLabel(parent, URI.parse('no:file'), this._contextService, this._environmentService);
|
||||
this.badge = new CountBadge(parent);
|
||||
const styler = attachBadgeStyler(this.badge, themeService);
|
||||
this.dispose = () => styler.dispose();
|
||||
}
|
||||
|
||||
set(element: FileReferences) {
|
||||
this.file.setFile(element.uri, this._contextService, this._environmentService);
|
||||
const len = element.children.length;
|
||||
this.badge.setCount(len);
|
||||
if (element.failure) {
|
||||
this.badge.setTitleFormat(nls.localize('referencesFailre', "Failed to resolve file."));
|
||||
} else if (len > 1) {
|
||||
this.badge.setTitleFormat(nls.localize('referencesCount', "{0} references", len));
|
||||
} else {
|
||||
this.badge.setTitleFormat(nls.localize('referenceCount', "{0} reference", len));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OneReferenceTemplate {
|
||||
|
||||
readonly before: HTMLSpanElement;
|
||||
readonly inside: HTMLSpanElement;
|
||||
readonly after: HTMLSpanElement;
|
||||
|
||||
constructor(container: HTMLElement) {
|
||||
const parent = document.createElement('div');
|
||||
this.before = document.createElement('span');
|
||||
this.inside = document.createElement('span');
|
||||
this.after = document.createElement('span');
|
||||
dom.addClass(this.inside, 'referenceMatch');
|
||||
dom.addClass(parent, 'reference');
|
||||
parent.appendChild(this.before);
|
||||
parent.appendChild(this.inside);
|
||||
parent.appendChild(this.after);
|
||||
container.appendChild(parent);
|
||||
}
|
||||
|
||||
set(element: OneReference): void {
|
||||
const { before, inside, after } = element.parent.preview.preview(element.range);
|
||||
this.before.innerHTML = strings.escape(before);
|
||||
this.inside.innerHTML = strings.escape(inside);
|
||||
this.after.innerHTML = strings.escape(after);
|
||||
}
|
||||
}
|
||||
|
||||
class Renderer implements tree.IRenderer {
|
||||
|
||||
private static _ids = {
|
||||
FileReferences: 'FileReferences',
|
||||
OneReference: 'OneReference'
|
||||
};
|
||||
|
||||
constructor(
|
||||
@IWorkspaceContextService private _contextService: IWorkspaceContextService,
|
||||
@IThemeService private _themeService: IThemeService,
|
||||
@optional(IEnvironmentService) private _environmentService: IEnvironmentService,
|
||||
) {
|
||||
//
|
||||
}
|
||||
|
||||
getHeight(tree: tree.ITree, element: FileReferences | OneReference): number {
|
||||
return 22;
|
||||
}
|
||||
|
||||
getTemplateId(tree: tree.ITree, element: FileReferences | OneReference): string {
|
||||
if (element instanceof FileReferences) {
|
||||
return Renderer._ids.FileReferences;
|
||||
} else if (element instanceof OneReference) {
|
||||
return Renderer._ids.OneReference;
|
||||
}
|
||||
throw element;
|
||||
}
|
||||
|
||||
renderTemplate(tree: tree.ITree, templateId: string, container: HTMLElement) {
|
||||
if (templateId === Renderer._ids.FileReferences) {
|
||||
return new FileReferencesTemplate(container, this._contextService, this._environmentService, this._themeService);
|
||||
} else if (templateId === Renderer._ids.OneReference) {
|
||||
return new OneReferenceTemplate(container);
|
||||
}
|
||||
throw templateId;
|
||||
}
|
||||
|
||||
renderElement(tree: tree.ITree, element: FileReferences | OneReference, templateId: string, templateData: any): void {
|
||||
if (element instanceof FileReferences) {
|
||||
(<FileReferencesTemplate>templateData).set(element);
|
||||
} else if (element instanceof OneReference) {
|
||||
(<OneReferenceTemplate>templateData).set(element);
|
||||
} else {
|
||||
throw templateId;
|
||||
}
|
||||
}
|
||||
|
||||
disposeTemplate(tree: tree.ITree, templateId: string, templateData: FileReferencesTemplate | OneReferenceTemplate): void {
|
||||
if (templateData instanceof FileReferencesTemplate) {
|
||||
templateData.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AriaProvider implements tree.IAccessibilityProvider {
|
||||
|
||||
getAriaLabel(tree: tree.ITree, element: FileReferences | OneReference): string {
|
||||
if (element instanceof FileReferences) {
|
||||
return element.getAriaMessage();
|
||||
} else if (element instanceof OneReference) {
|
||||
return element.getAriaMessage();
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VSash {
|
||||
|
||||
private _disposables: IDisposable[] = [];
|
||||
private _sash: Sash;
|
||||
private _ratio: number;
|
||||
private _height: number;
|
||||
private _width: number;
|
||||
private _onDidChangePercentages = new Emitter<VSash>();
|
||||
|
||||
constructor(container: HTMLElement, ratio: number) {
|
||||
this._ratio = ratio;
|
||||
this._sash = new Sash(container, <IVerticalSashLayoutProvider>{
|
||||
getVerticalSashLeft: () => this._width * this._ratio,
|
||||
getVerticalSashHeight: () => this._height
|
||||
});
|
||||
|
||||
// compute the current widget clientX postion since
|
||||
// the sash works with clientX when dragging
|
||||
let clientX: number;
|
||||
this._disposables.push(this._sash.addListener('start', (e: ISashEvent) => {
|
||||
clientX = e.startX - (this._width * this.ratio);
|
||||
}));
|
||||
|
||||
this._disposables.push(this._sash.addListener('change', (e: ISashEvent) => {
|
||||
// compute the new position of the sash and from that
|
||||
// compute the new ratio that we are using
|
||||
let newLeft = e.currentX - clientX;
|
||||
if (newLeft > 20 && newLeft + 20 < this._width) {
|
||||
this._ratio = newLeft / this._width;
|
||||
this._sash.layout();
|
||||
this._onDidChangePercentages.fire(this);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this._sash.dispose();
|
||||
this._onDidChangePercentages.dispose();
|
||||
dispose(this._disposables);
|
||||
}
|
||||
|
||||
get onDidChangePercentages() {
|
||||
return this._onDidChangePercentages.event;
|
||||
}
|
||||
|
||||
set width(value: number) {
|
||||
this._width = value;
|
||||
this._sash.layout();
|
||||
}
|
||||
|
||||
set height(value: number) {
|
||||
this._height = value;
|
||||
this._sash.layout();
|
||||
}
|
||||
|
||||
get percentages() {
|
||||
let left = 100 * this._ratio;
|
||||
let right = 100 - left;
|
||||
return [`${left}%`, `${right}%`];
|
||||
}
|
||||
|
||||
get ratio() {
|
||||
return this._ratio;
|
||||
}
|
||||
}
|
||||
|
||||
export interface LayoutData {
|
||||
ratio: number;
|
||||
heightInLines: number;
|
||||
}
|
||||
|
||||
export interface SelectionEvent {
|
||||
kind: 'goto' | 'show' | 'side' | 'open';
|
||||
source: 'editor' | 'tree' | 'title';
|
||||
element: OneReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* ZoneWidget that is shown inside the editor
|
||||
*/
|
||||
export class ReferenceWidget extends PeekViewWidget {
|
||||
|
||||
private _model: ReferencesModel;
|
||||
private _decorationsManager: DecorationsManager;
|
||||
|
||||
private _disposeOnNewModel: IDisposable[] = [];
|
||||
private _callOnDispose: IDisposable[] = [];
|
||||
private _onDidSelectReference = new Emitter<SelectionEvent>();
|
||||
|
||||
private _tree: Tree;
|
||||
private _treeContainer: Builder;
|
||||
private _sash: VSash;
|
||||
private _preview: ICodeEditor;
|
||||
private _previewModelReference: IReference<ITextEditorModel>;
|
||||
private _previewNotAvailableMessage: Model;
|
||||
private _previewContainer: Builder;
|
||||
private _messageContainer: Builder;
|
||||
|
||||
constructor(
|
||||
editor: ICodeEditor,
|
||||
public layoutData: LayoutData,
|
||||
private _textModelResolverService: ITextModelService,
|
||||
private _contextService: IWorkspaceContextService,
|
||||
private _themeService: IThemeService,
|
||||
private _instantiationService: IInstantiationService,
|
||||
private _environmentService: IEnvironmentService
|
||||
) {
|
||||
super(editor, { showFrame: false, showArrow: true, isResizeable: true, isAccessible: true });
|
||||
|
||||
this._applyTheme(_themeService.getTheme());
|
||||
this._callOnDispose.push(_themeService.onThemeChange(this._applyTheme.bind(this)));
|
||||
|
||||
this._instantiationService = this._instantiationService.createChild(new ServiceCollection([IPeekViewService, this]));
|
||||
this.create();
|
||||
}
|
||||
|
||||
private _applyTheme(theme: ITheme) {
|
||||
let borderColor = theme.getColor(peekViewBorder) || Color.transparent;
|
||||
this.style({
|
||||
arrowColor: borderColor,
|
||||
frameColor: borderColor,
|
||||
headerBackgroundColor: theme.getColor(peekViewTitleBackground) || Color.transparent,
|
||||
primaryHeadingColor: theme.getColor(peekViewTitleForeground),
|
||||
secondaryHeadingColor: theme.getColor(peekViewTitleInfoForeground)
|
||||
});
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.setModel(null);
|
||||
this._callOnDispose = dispose(this._callOnDispose);
|
||||
dispose<IDisposable>(this._preview, this._previewNotAvailableMessage, this._tree, this._sash, this._previewModelReference);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
get onDidSelectReference(): Event<SelectionEvent> {
|
||||
return this._onDidSelectReference.event;
|
||||
}
|
||||
|
||||
show(where: IRange) {
|
||||
this.editor.revealRangeInCenterIfOutsideViewport(where, editorCommon.ScrollType.Smooth);
|
||||
super.show(where, this.layoutData.heightInLines || 18);
|
||||
}
|
||||
|
||||
focus(): void {
|
||||
this._tree.DOMFocus();
|
||||
}
|
||||
|
||||
protected _onTitleClick(e: MouseEvent): void {
|
||||
if (this._preview && this._preview.getModel()) {
|
||||
this._onDidSelectReference.fire({
|
||||
element: this._getFocusedReference(),
|
||||
kind: e.ctrlKey || e.metaKey ? 'side' : 'open',
|
||||
source: 'title'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected _fillBody(containerElement: HTMLElement): void {
|
||||
var container = $(containerElement);
|
||||
|
||||
this.setCssClass('reference-zone-widget');
|
||||
|
||||
// message pane
|
||||
container.div({ 'class': 'messages' }, div => {
|
||||
this._messageContainer = div.hide();
|
||||
});
|
||||
|
||||
// editor
|
||||
container.div({ 'class': 'preview inline' }, (div: Builder) => {
|
||||
|
||||
var options: IEditorOptions = {
|
||||
scrollBeyondLastLine: false,
|
||||
scrollbar: {
|
||||
verticalScrollbarSize: 14,
|
||||
horizontal: 'auto',
|
||||
useShadows: true,
|
||||
verticalHasArrows: false,
|
||||
horizontalHasArrows: false
|
||||
},
|
||||
overviewRulerLanes: 2,
|
||||
fixedOverflowWidgets: true,
|
||||
minimap: {
|
||||
enabled: false
|
||||
}
|
||||
};
|
||||
|
||||
this._preview = this._instantiationService.createInstance(EmbeddedCodeEditorWidget, div.getHTMLElement(), options, this.editor);
|
||||
this._previewContainer = div.hide();
|
||||
this._previewNotAvailableMessage = Model.createFromString(nls.localize('missingPreviewMessage', "no preview available"));
|
||||
});
|
||||
|
||||
// sash
|
||||
this._sash = new VSash(containerElement, this.layoutData.ratio || .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.layoutData.ratio = this._sash.ratio;
|
||||
});
|
||||
|
||||
// tree
|
||||
container.div({ 'class': 'ref-tree inline' }, (div: Builder) => {
|
||||
var config = <tree.ITreeConfiguration>{
|
||||
dataSource: this._instantiationService.createInstance(DataSource),
|
||||
renderer: this._instantiationService.createInstance(Renderer),
|
||||
controller: new Controller(),
|
||||
accessibilityProvider: new AriaProvider()
|
||||
};
|
||||
|
||||
var options = {
|
||||
allowHorizontalScroll: false,
|
||||
twistiePixels: 20,
|
||||
ariaLabel: nls.localize('treeAriaLabel', "References")
|
||||
};
|
||||
this._tree = new Tree(div.getHTMLElement(), config, options);
|
||||
this._callOnDispose.push(attachListStyler(this._tree, this._themeService));
|
||||
|
||||
this._treeContainer = div.hide();
|
||||
});
|
||||
}
|
||||
|
||||
protected _doLayoutBody(heightInPixel: number, widthInPixel: number): void {
|
||||
super._doLayoutBody(heightInPixel, widthInPixel);
|
||||
|
||||
const height = heightInPixel + 'px';
|
||||
this._sash.height = heightInPixel;
|
||||
this._sash.width = widthInPixel;
|
||||
|
||||
// set height/width
|
||||
const [left, right] = this._sash.percentages;
|
||||
this._previewContainer.style({ height, width: left });
|
||||
this._treeContainer.style({ height, width: right });
|
||||
|
||||
// forward
|
||||
this._tree.layout(heightInPixel);
|
||||
this._preview.layout();
|
||||
|
||||
// store layout data
|
||||
this.layoutData = {
|
||||
heightInLines: this._viewZone.heightInLines,
|
||||
ratio: this._sash.ratio
|
||||
};
|
||||
}
|
||||
|
||||
public _onWidth(widthInPixel: number): void {
|
||||
this._sash.width = widthInPixel;
|
||||
this._preview.layout();
|
||||
}
|
||||
|
||||
public setSelection(selection: OneReference): TPromise<any> {
|
||||
return this._revealReference(selection);
|
||||
}
|
||||
|
||||
public setModel(newModel: ReferencesModel): TPromise<any> {
|
||||
// clean up
|
||||
this._disposeOnNewModel = dispose(this._disposeOnNewModel);
|
||||
this._model = newModel;
|
||||
if (this._model) {
|
||||
return this._onNewModel();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private _onNewModel(): TPromise<any> {
|
||||
|
||||
if (this._model.empty) {
|
||||
this.setTitle('');
|
||||
this._messageContainer.innerHtml(nls.localize('noResults', "No results")).show();
|
||||
return TPromise.as(void 0);
|
||||
}
|
||||
|
||||
this._messageContainer.hide();
|
||||
this._decorationsManager = new DecorationsManager(this._preview, this._model);
|
||||
this._disposeOnNewModel.push(this._decorationsManager);
|
||||
|
||||
// listen on model changes
|
||||
this._disposeOnNewModel.push(this._model.onDidChangeReferenceRange(reference => this._tree.refresh(reference)));
|
||||
|
||||
// listen on selection and focus
|
||||
this._disposeOnNewModel.push(this._tree.addListener(Controller.Events.FOCUSED, (element) => {
|
||||
if (element instanceof OneReference) {
|
||||
this._revealReference(element);
|
||||
this._onDidSelectReference.fire({ element, kind: 'show', source: 'tree' });
|
||||
}
|
||||
}));
|
||||
|
||||
this._disposeOnNewModel.push(this._tree.addListener(Controller.Events.SELECTED, (element: any) => {
|
||||
if (element instanceof OneReference) {
|
||||
this._onDidSelectReference.fire({ element, kind: 'goto', source: 'tree' });
|
||||
}
|
||||
}));
|
||||
this._disposeOnNewModel.push(this._tree.addListener(Controller.Events.OPEN_TO_SIDE, (element: any) => {
|
||||
if (element instanceof OneReference) {
|
||||
this._onDidSelectReference.fire({ element, kind: 'side', source: 'tree' });
|
||||
}
|
||||
}));
|
||||
|
||||
// listen on editor
|
||||
this._disposeOnNewModel.push(this._preview.onMouseDown((e) => {
|
||||
if (e.event.detail === 2) {
|
||||
this._onDidSelectReference.fire({
|
||||
element: this._getFocusedReference(),
|
||||
kind: (e.event.ctrlKey || e.event.metaKey) ? 'side' : 'open',
|
||||
source: 'editor'
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
||||
// make sure things are rendered
|
||||
dom.addClass(this.container, 'results-loaded');
|
||||
this._treeContainer.show();
|
||||
this._previewContainer.show();
|
||||
this._preview.layout();
|
||||
this._tree.layout();
|
||||
this.focus();
|
||||
|
||||
// pick input and a reference to begin with
|
||||
const input = this._model.groups.length === 1 ? this._model.groups[0] : this._model;
|
||||
return this._tree.setInput(input);
|
||||
}
|
||||
|
||||
private _getFocusedReference(): OneReference {
|
||||
const element = this._tree.getFocus();
|
||||
if (element instanceof OneReference) {
|
||||
return element;
|
||||
} else if (element instanceof FileReferences) {
|
||||
if (element.children.length > 0) {
|
||||
return element.children[0];
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private _revealReference(reference: OneReference) {
|
||||
|
||||
// Update widget header
|
||||
if (reference.uri.scheme !== Schemas.inMemory) {
|
||||
this.setTitle(reference.name, getPathLabel(reference.directory, this._contextService, this._environmentService));
|
||||
} else {
|
||||
this.setTitle(nls.localize('peekView.alternateTitle', "References"));
|
||||
}
|
||||
|
||||
const promise = this._textModelResolverService.createModelReference(reference.uri);
|
||||
|
||||
return TPromise.join([promise, this._tree.reveal(reference)]).then(values => {
|
||||
const ref = values[0];
|
||||
|
||||
if (!this._model) {
|
||||
ref.dispose();
|
||||
// disposed
|
||||
return;
|
||||
}
|
||||
|
||||
dispose(this._previewModelReference);
|
||||
|
||||
// show in editor
|
||||
const model = ref.object;
|
||||
if (model) {
|
||||
this._previewModelReference = ref;
|
||||
let isSameModel = (this._preview.getModel() === model.textEditorModel);
|
||||
this._preview.setModel(model.textEditorModel);
|
||||
var sel = Range.lift(reference.range).collapseToStart();
|
||||
this._preview.setSelection(sel);
|
||||
this._preview.revealRangeInCenter(sel, isSameModel ? editorCommon.ScrollType.Smooth : editorCommon.ScrollType.Immediate);
|
||||
} else {
|
||||
this._preview.setModel(this._previewNotAvailableMessage);
|
||||
ref.dispose();
|
||||
}
|
||||
|
||||
// show in tree
|
||||
this._tree.setSelection([reference]);
|
||||
this._tree.setFocus(reference);
|
||||
|
||||
}, onUnexpectedError);
|
||||
}
|
||||
}
|
||||
|
||||
// theming
|
||||
|
||||
export const peekViewTitleBackground = registerColor('peekViewTitle.background', { dark: '#1E1E1E', light: '#FFFFFF', hc: '#0C141F' }, nls.localize('peekViewTitleBackground', 'Background color of the peek view title area.'));
|
||||
export const peekViewTitleForeground = registerColor('peekViewTitleLabel.foreground', { dark: '#FFFFFF', light: '#333333', hc: '#FFFFFF' }, nls.localize('peekViewTitleForeground', 'Color of the peek view title.'));
|
||||
export const peekViewTitleInfoForeground = registerColor('peekViewTitleDescription.foreground', { dark: '#ccccccb3', light: '#6c6c6cb3', hc: '#FFFFFF99' }, nls.localize('peekViewTitleInfoForeground', 'Color of the peek view title info.'));
|
||||
export const peekViewBorder = registerColor('peekView.border', { dark: '#007acc', light: '#007acc', hc: contrastBorder }, nls.localize('peekViewBorder', 'Color of the peek view borders and arrow.'));
|
||||
|
||||
export const peekViewResultsBackground = registerColor('peekViewResult.background', { dark: '#252526', light: '#F3F3F3', hc: Color.black }, nls.localize('peekViewResultsBackground', 'Background color of the peek view result list.'));
|
||||
export const peekViewResultsMatchForeground = registerColor('peekViewResult.lineForeground', { dark: '#bbbbbb', light: '#646465', hc: Color.white }, nls.localize('peekViewResultsMatchForeground', 'Foreground color for line nodes in the peek view result list.'));
|
||||
export const peekViewResultsFileForeground = registerColor('peekViewResult.fileForeground', { dark: Color.white, light: '#1E1E1E', hc: Color.white }, nls.localize('peekViewResultsFileForeground', 'Foreground color for file nodes in the peek view result list.'));
|
||||
export const peekViewResultsSelectionBackground = registerColor('peekViewResult.selectionBackground', { dark: '#3399ff33', light: '#3399ff33', hc: null }, nls.localize('peekViewResultsSelectionBackground', 'Background color of the selected entry in the peek view result list.'));
|
||||
export const peekViewResultsSelectionForeground = registerColor('peekViewResult.selectionForeground', { dark: Color.white, light: '#6C6C6C', hc: Color.white }, nls.localize('peekViewResultsSelectionForeground', 'Foreground color of the selected entry in the peek view result list.'));
|
||||
export const peekViewEditorBackground = registerColor('peekViewEditor.background', { dark: '#001F33', light: '#F2F8FC', hc: Color.black }, nls.localize('peekViewEditorBackground', 'Background color of the peek view editor.'));
|
||||
export const peekViewEditorGutterBackground = registerColor('peekViewEditorGutter.background', { dark: peekViewEditorBackground, light: peekViewEditorBackground, hc: peekViewEditorBackground }, nls.localize('peekViewEditorGutterBackground', 'Background color of the gutter in the peek view editor.'));
|
||||
|
||||
export const peekViewResultsMatchHighlight = registerColor('peekViewResult.matchHighlightBackground', { dark: '#ea5c004d', light: '#ea5c004d', hc: null }, nls.localize('peekViewResultsMatchHighlight', 'Match highlight color in the peek view result list.'));
|
||||
export const peekViewEditorMatchHighlight = registerColor('peekViewEditor.matchHighlightBackground', { dark: '#ff8f0099', light: '#f5d802de', hc: null }, nls.localize('peekViewEditorMatchHighlight', 'Match highlight color in the peek view editor.'));
|
||||
|
||||
|
||||
registerThemingParticipant((theme, collector) => {
|
||||
let findMatchHighlightColor = theme.getColor(peekViewResultsMatchHighlight);
|
||||
if (findMatchHighlightColor) {
|
||||
collector.addRule(`.monaco-editor .reference-zone-widget .ref-tree .referenceMatch { background-color: ${findMatchHighlightColor}; }`);
|
||||
}
|
||||
let referenceHighlightColor = theme.getColor(peekViewEditorMatchHighlight);
|
||||
if (referenceHighlightColor) {
|
||||
collector.addRule(`.monaco-editor .reference-zone-widget .preview .reference-decoration { background-color: ${referenceHighlightColor}; }`);
|
||||
}
|
||||
let hcOutline = theme.getColor(activeContrastBorder);
|
||||
if (hcOutline) {
|
||||
collector.addRule(`.monaco-editor .reference-zone-widget .ref-tree .referenceMatch { border: 1px dotted ${hcOutline}; box-sizing: border-box; }`);
|
||||
collector.addRule(`.monaco-editor .reference-zone-widget .preview .reference-decoration { border: 2px solid ${hcOutline}; box-sizing: border-box; }`);
|
||||
}
|
||||
let resultsBackground = theme.getColor(peekViewResultsBackground);
|
||||
if (resultsBackground) {
|
||||
collector.addRule(`.monaco-editor .reference-zone-widget .ref-tree { background-color: ${resultsBackground}; }`);
|
||||
}
|
||||
let resultsMatchForeground = theme.getColor(peekViewResultsMatchForeground);
|
||||
if (resultsMatchForeground) {
|
||||
collector.addRule(`.monaco-editor .reference-zone-widget .ref-tree { color: ${resultsMatchForeground}; }`);
|
||||
}
|
||||
let resultsFileForeground = theme.getColor(peekViewResultsFileForeground);
|
||||
if (resultsFileForeground) {
|
||||
collector.addRule(`.monaco-editor .reference-zone-widget .ref-tree .reference-file { color: ${resultsFileForeground}; }`);
|
||||
}
|
||||
let resultsSelectedBackground = theme.getColor(peekViewResultsSelectionBackground);
|
||||
if (resultsSelectedBackground) {
|
||||
collector.addRule(`.monaco-editor .reference-zone-widget .ref-tree .monaco-tree.focused .monaco-tree-rows > .monaco-tree-row.selected:not(.highlighted) { background-color: ${resultsSelectedBackground}; }`);
|
||||
}
|
||||
let resultsSelectedForeground = theme.getColor(peekViewResultsSelectionForeground);
|
||||
if (resultsSelectedForeground) {
|
||||
collector.addRule(`.monaco-editor .reference-zone-widget .ref-tree .monaco-tree.focused .monaco-tree-rows > .monaco-tree-row.selected:not(.highlighted) { color: ${resultsSelectedForeground} !important; }`);
|
||||
}
|
||||
let editorBackground = theme.getColor(peekViewEditorBackground);
|
||||
if (editorBackground) {
|
||||
collector.addRule(
|
||||
`.monaco-editor .reference-zone-widget .preview .monaco-editor .monaco-editor-background,` +
|
||||
`.monaco-editor .reference-zone-widget .preview .monaco-editor .inputarea.ime-input {` +
|
||||
` background-color: ${editorBackground};` +
|
||||
`}`);
|
||||
}
|
||||
let editorGutterBackground = theme.getColor(peekViewEditorGutterBackground);
|
||||
if (editorGutterBackground) {
|
||||
collector.addRule(
|
||||
`.monaco-editor .reference-zone-widget .preview .monaco-editor .margin {` +
|
||||
` background-color: ${editorGutterBackground};` +
|
||||
`}`);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { ReferencesModel } from 'vs/editor/contrib/referenceSearch/browser/referencesModel';
|
||||
|
||||
suite('references', function () {
|
||||
|
||||
test('nearestReference', function () {
|
||||
const model = new ReferencesModel([{
|
||||
uri: URI.file('/out/obj/can'),
|
||||
range: new Range(1, 1, 1, 1)
|
||||
}, {
|
||||
uri: URI.file('/out/obj/can2'),
|
||||
range: new Range(1, 1, 1, 1)
|
||||
}, {
|
||||
uri: URI.file('/src/can'),
|
||||
range: new Range(1, 1, 1, 1)
|
||||
}]);
|
||||
|
||||
let ref = model.nearestReference(URI.file('/src/can'), new Position(1, 1));
|
||||
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');
|
||||
|
||||
ref = model.nearestReference(URI.file('/out/someOtherFile'), new Position(1, 1));
|
||||
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');
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user