some reference search lipstick...

This commit is contained in:
Johannes Rieken
2019-11-01 15:37:00 +01:00
parent a20de9e7ec
commit d4f92da59e
3 changed files with 41 additions and 67 deletions
@@ -18,18 +18,15 @@ import { IMatch } from 'vs/base/common/filters';
import { Constants } from 'vs/base/common/uint';
export class OneReference {
readonly id: string;
private readonly _onRefChanged = new Emitter<this>();
readonly onRefChanged: Event<this> = this._onRefChanged.event;
readonly id: string = defaultGenerator.nextId();
constructor(
readonly isProviderFirst: boolean,
readonly parent: FileReferences,
private _range: IRange,
readonly isProviderFirst: boolean
) {
this.id = defaultGenerator.nextId();
}
private _rangeCallback: (ref: OneReference) => void
) { }
get uri(): URI {
return this.parent.uri;
@@ -41,7 +38,7 @@ export class OneReference {
set range(value: IRange) {
this._range = value;
this._onRefChanged.fire(this);
this._rangeCallback(this);
}
getAriaMessage(): string {
@@ -56,8 +53,7 @@ export class FilePreview implements IDisposable {
constructor(
private readonly _modelReference: IReference<ITextEditorModel>
) {
}
) { }
dispose(): void {
dispose(this._modelReference);
@@ -88,29 +84,20 @@ export class FilePreview implements IDisposable {
export class FileReferences implements IDisposable {
private _children: OneReference[];
readonly children: OneReference[] = [];
private _preview?: FilePreview;
private _resolved?: boolean;
private _loadFailure: any;
private _loadFailure?: any;
constructor(private readonly _parent: ReferencesModel, private readonly _uri: URI) {
this._children = [];
}
constructor(
readonly parent: ReferencesModel,
readonly uri: URI
) { }
get id(): string {
return this._uri.toString();
}
get parent(): ReferencesModel {
return this._parent;
}
get children(): OneReference[] {
return this._children;
}
get uri(): URI {
return this._uri;
dispose(): void {
dispose(this._preview);
this._preview = undefined;
}
get preview(): FilePreview | undefined {
@@ -136,7 +123,7 @@ export class FileReferences implements IDisposable {
return Promise.resolve(this);
}
return Promise.resolve(textModelResolverService.createModelReference(this._uri).then(modelReference => {
return Promise.resolve(textModelResolverService.createModelReference(this.uri).then(modelReference => {
const model = modelReference.object;
if (!model) {
@@ -150,19 +137,12 @@ export class FileReferences implements IDisposable {
}, err => {
// something wrong here
this._children = [];
this.children.length = 0;
this._resolved = true;
this._loadFailure = err;
return this;
}));
}
dispose(): void {
if (this._preview) {
this._preview.dispose();
this._preview = undefined;
}
}
}
export class ReferencesModel implements IDisposable {
@@ -189,23 +169,31 @@ export class ReferencesModel implements IDisposable {
}
// append, check for equality first!
if (current.children.length === 0
|| !Range.equalsRange(ref.range, current.children[current.children.length - 1].range)) {
if (current.children.length === 0 || !Range.equalsRange(ref.range, current.children[current.children.length - 1].range)) {
let oneRef = new OneReference(current, ref.targetSelectionRange || ref.range, providersFirst === ref);
this._disposables.add(oneRef.onRefChanged((e) => this._onDidChangeReferenceRange.fire(e)));
const oneRef = new OneReference(
providersFirst === ref, current, ref.targetSelectionRange || ref.range,
ref => this._onDidChangeReferenceRange.fire(ref)
);
this.references.push(oneRef);
current.children.push(oneRef);
}
}
}
get empty(): boolean {
dispose(): void {
dispose(this.groups);
this._disposables.dispose();
this._onDidChangeReferenceRange.dispose();
this.groups.length = 0;
}
get isEmpty(): boolean {
return this.groups.length === 0;
}
getAriaMessage(): string {
if (this.empty) {
if (this.isEmpty) {
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);
@@ -281,21 +269,7 @@ export class ReferencesModel implements IDisposable {
return this.references[0];
}
dispose(): void {
dispose(this.groups);
this._disposables.dispose();
this.groups.length = 0;
}
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);
}
return strings.compare(a.uri.toString(), b.uri.toString()) || Range.compareRangesUsingStarts(a.range, b.range);
}
}
@@ -101,7 +101,7 @@ export class StringRepresentationProvider implements IKeyboardNavigationLabelPro
export class IdentityProvider implements IIdentityProvider<TreeElement> {
getId(element: TreeElement): { toString(): string; } {
return element.id;
return element.uri;
}
}
@@ -53,7 +53,7 @@ class DecorationsManager implements IDisposable {
this._onModelChanged();
}
public dispose(): void {
dispose(): void {
this._callOnModelChange.dispose();
this._callOnDispose.dispose();
this.removeDecorations();
@@ -145,7 +145,7 @@ class DecorationsManager implements IDisposable {
this._editor.deltaDecorations(toRemove, []);
}
public removeDecorations(): void {
removeDecorations(): void {
let toRemove: string[] = [];
this._decorations.forEach((value, key) => {
toRemove.push(key);
@@ -156,8 +156,8 @@ class DecorationsManager implements IDisposable {
}
export class LayoutData {
public ratio: number = 0.7;
public heightInLines: number = 18;
ratio: number = 0.7;
heightInLines: number = 18;
static fromJSON(raw: string): LayoutData {
let ratio: number | undefined;
@@ -397,7 +397,7 @@ export class ReferenceWidget extends PeekViewWidget {
this._splitView.resizeView(0, widthInPixel * this.layoutData.ratio);
}
public setSelection(selection: OneReference): Promise<any> {
setSelection(selection: OneReference): Promise<any> {
return this._revealReference(selection, true).then(() => {
if (!this._model) {
// disposed
@@ -409,7 +409,7 @@ export class ReferenceWidget extends PeekViewWidget {
});
}
public setModel(newModel: ReferencesModel | undefined): Promise<any> {
setModel(newModel: ReferencesModel | undefined): Promise<any> {
// clean up
this._disposeOnNewModel.clear();
this._model = newModel;
@@ -424,7 +424,7 @@ export class ReferenceWidget extends PeekViewWidget {
return Promise.resolve(undefined);
}
if (this._model.empty) {
if (this._model.isEmpty) {
this.setTitle('');
this._messageContainer.innerHTML = nls.localize('noResults', "No results");
dom.show(this._messageContainer);