提交 c549276d 编写于 作者: M Matt Bierner

Strict null check references widget

上级 82e9561f
......@@ -245,6 +245,7 @@
"./vs/editor/contrib/referenceSearch/peekViewWidget.ts",
"./vs/editor/contrib/referenceSearch/referencesModel.ts",
"./vs/editor/contrib/referenceSearch/referencesTree.ts",
"./vs/editor/contrib/referenceSearch/referencesWidget.ts",
"./vs/editor/contrib/referenceSearch/test/referencesModel.test.ts",
"./vs/editor/contrib/rename/rename.ts",
"./vs/editor/contrib/rename/renameInputField.ts",
......@@ -872,6 +873,7 @@
"./vs/workbench/services/themes/common/workbenchThemeService.ts",
"./vs/workbench/services/themes/electron-browser/fileIconThemeData.ts",
"./vs/workbench/services/themes/electron-browser/fileIconThemeStore.ts",
"./vs/workbench/services/themes/electron-browser/themeCompatibility.ts",
"./vs/workbench/services/timer/electron-browser/timerService.ts",
"./vs/workbench/services/title/common/titleService.ts",
"./vs/workbench/services/viewlet/browser/viewlet.ts",
......
......@@ -72,6 +72,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[] = [];
......@@ -98,8 +101,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;
......@@ -220,7 +228,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);
......@@ -424,7 +432,7 @@ export class ReferenceWidget extends PeekViewWidget {
// store layout data
this.layoutData = {
heightInLines: this._viewZone.heightInLines,
heightInLines: this._viewZone ? this._viewZone.heightInLines : 0,
ratio: this._sash.ratio
};
}
......@@ -446,7 +454,7 @@ export class ReferenceWidget extends PeekViewWidget {
});
}
public setModel(newModel: ReferencesModel | undefined): Promise<any> {
public setModel(newModel: ReferencesModel | undefined): Promise<any> | undefined {
// clean up
this._disposeOnNewModel = dispose(this._disposeOnNewModel);
this._model = newModel;
......@@ -457,6 +465,9 @@ export class ReferenceWidget extends PeekViewWidget {
}
private _onNewModel(): Promise<any> {
if (!this._model) {
return Promise.resolve(undefined);
}
if (this._model.empty) {
this.setTitle('');
......@@ -483,7 +494,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'
});
......@@ -501,7 +512,7 @@ export class ReferenceWidget extends PeekViewWidget {
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;
......@@ -525,7 +536,7 @@ 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"));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册