Skip to content

Commit

Permalink
Strict null check more files related to quick open
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Feb 5, 2019
1 parent 66614c0 commit 815a3cb
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 47 deletions.
8 changes: 8 additions & 0 deletions src/tsconfig.strictNullChecks.json
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,18 @@
"./vs/workbench/parts/preferences/browser/settingsWidgets.ts",
"./vs/workbench/parts/preferences/common/smartSnippetInserter.ts",
"./vs/workbench/parts/preferences/test/common/smartSnippetInserter.test.ts",
"./vs/workbench/parts/quickopen/browser/commandsHandler.ts",
"./vs/workbench/parts/quickopen/browser/gotoLineHandler.ts",
"./vs/workbench/parts/quickopen/browser/helpHandler.ts",
"./vs/workbench/parts/quickopen/browser/viewPickerHandler.ts",
"./vs/workbench/parts/relauncher/electron-browser/relauncher.contribution.ts",
"./vs/workbench/parts/scm/common/scm.ts",
"./vs/workbench/parts/scm/electron-browser/dirtydiffDecorator.ts",
"./vs/workbench/parts/scm/electron-browser/scmActivity.ts",
"./vs/workbench/parts/scm/electron-browser/scmMenus.ts",
"./vs/workbench/parts/scm/electron-browser/scmUtil.ts",
"./vs/workbench/parts/search/browser/openFileHandler.ts",
"./vs/workbench/parts/search/browser/openSymbolHandler.ts",
"./vs/workbench/parts/search/browser/patternInputWidget.ts",
"./vs/workbench/parts/search/browser/replaceContributions.ts",
"./vs/workbench/parts/search/browser/replaceService.ts",
Expand All @@ -581,6 +586,7 @@
"./vs/workbench/parts/search/common/search.ts",
"./vs/workbench/parts/search/common/searchModel.ts",
"./vs/workbench/parts/search/test/browser/mockSearchTree.ts",
"./vs/workbench/parts/search/test/browser/openFileHandler.test.ts",
"./vs/workbench/parts/search/test/common/searchModel.test.ts",
"./vs/workbench/parts/search/test/common/searchResult.test.ts",
"./vs/workbench/parts/snippets/electron-browser/configureSnippets.ts",
Expand Down Expand Up @@ -619,6 +625,7 @@
"./vs/workbench/parts/tasks/test/common/problemMatcher.test.ts",
"./vs/workbench/parts/tasks/test/electron-browser/configuration.test.ts",
"./vs/workbench/parts/terminal/browser/terminalFindWidget.ts",
"./vs/workbench/parts/terminal/browser/terminalQuickOpen.ts",
"./vs/workbench/parts/terminal/browser/terminalTab.ts",
"./vs/workbench/parts/terminal/browser/terminalWidgetManager.ts",
"./vs/workbench/parts/terminal/common/terminal.ts",
Expand Down Expand Up @@ -648,6 +655,7 @@
"./vs/workbench/parts/welcome/gettingStarted/electron-browser/gettingStarted.ts",
"./vs/workbench/parts/welcome/gettingStarted/electron-browser/telemetryOptOut.ts",
"./vs/workbench/parts/welcome/gettingStarted/test/common/gettingStarted.test.ts",
"./vs/workbench/parts/welcome/overlay/browser/welcomeOverlay.ts",
"./vs/workbench/parts/welcome/page/electron-browser/vs_code_welcome_page.ts",
"./vs/workbench/parts/welcome/page/electron-browser/welcomePage.contribution.ts",
"./vs/workbench/parts/welcome/page/electron-browser/welcomePage.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/parts/quickopen/browser/quickOpenModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class QuickOpenEntryGroup extends QuickOpenEntry {
return this.groupLabel;
}

setGroupLabel(groupLabel: string): void {
setGroupLabel(groupLabel: string | undefined): void {
this.groupLabel = groupLabel;
}

Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/browser/quickopen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ export class QuickOpenHandler {
/**
* The ARIA label to apply when this quick open handler is active in quick open.
*/
getAriaLabel() {
getAriaLabel(): string | null {
return null;
}

/**
* Extra CSS class name to add to the quick open widget to do custom styling of entries.
*/
getClass() {
getClass(): string | null {
return null;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ export class QuickOpenHandler {
/**
* Allows to return a label that will be placed to the side of the results from this handler or null if none.
*/
getGroupLabel() {
getGroupLabel(): string | null {
return null;
}

Expand Down
18 changes: 9 additions & 9 deletions src/vs/workbench/parts/quickopen/browser/commandsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CommandsHistory extends Disposable {

private load(): void {
const raw = this.storageService.get(CommandsHistory.PREF_KEY_CACHE, StorageScope.GLOBAL);
let serializedCache: ISerializedCommandHistory;
let serializedCache: ISerializedCommandHistory | undefined;
if (raw) {
try {
serializedCache = JSON.parse(raw);
Expand All @@ -118,7 +118,7 @@ class CommandsHistory extends Disposable {
commandHistory.set(commandId, commandCounter++); // set counter to command
}

peek(commandId: string): number {
peek(commandId: string): number | undefined {
return commandHistory.peek(commandId);
}

Expand Down Expand Up @@ -214,30 +214,30 @@ abstract class BaseCommandEntry extends QuickOpenEntryGroup {
private description: string;
private alias: string;
private labelLowercase: string;
private keybindingAriaLabel: string;
private readonly keybindingAriaLabel?: string;

constructor(
private commandId: string,
private keybinding: ResolvedKeybinding,
private label: string,
alias: string,
highlights: { label: IHighlight[], alias: IHighlight[] },
highlights: { label: IHighlight[], alias?: IHighlight[] },
private onBeforeRun: (commandId: string) => void,
@INotificationService private readonly notificationService: INotificationService,
@ITelemetryService protected telemetryService: ITelemetryService
) {
super();

this.labelLowercase = this.label.toLowerCase();
this.keybindingAriaLabel = keybinding ? keybinding.getAriaLabel() : undefined;
this.keybindingAriaLabel = keybinding ? keybinding.getAriaLabel() || undefined : undefined;

if (this.label !== alias) {
this.alias = alias;
} else {
highlights.alias = null;
highlights.alias = undefined;
}

this.setHighlights(highlights.label, null, highlights.alias);
this.setHighlights(highlights.label, undefined, highlights.alias);
}

getCommandId(): string {
Expand Down Expand Up @@ -541,7 +541,7 @@ export class CommandsHandler extends QuickOpenHandler {

// Add an 'alias' in original language when running in different locale
const aliasTitle = (language !== LANGUAGE_DEFAULT && typeof action.item.title !== 'string') ? action.item.title.original : null;
const aliasCategory = (language !== LANGUAGE_DEFAULT && category && typeof action.item.category !== 'string') ? action.item.category.original : null;
const aliasCategory = (language !== LANGUAGE_DEFAULT && category && action.item.category && typeof action.item.category !== 'string') ? action.item.category.original : null;
let alias;
if (aliasTitle && category) {
alias = aliasCategory ? `${aliasCategory}: ${aliasTitle}` : `${category}: ${aliasTitle}`;
Expand All @@ -560,7 +560,7 @@ export class CommandsHandler extends QuickOpenHandler {
}

getAutoFocus(searchValue: string, context: { model: IModel<QuickOpenEntry>, quickNavigateConfiguration?: IQuickNavigateConfiguration }): IAutoFocus {
let autoFocusPrefixMatch = searchValue.trim();
let autoFocusPrefixMatch: string | undefined = searchValue.trim();

if (autoFocusPrefixMatch && this.commandHistoryEnabled) {
const firstEntry = context.model && context.model.entries[0];
Expand Down
38 changes: 22 additions & 16 deletions src/vs/workbench/parts/quickopen/browser/gotoLineHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class GotoLineAction extends QuickOpenAction {

if (restoreOptions) {
Event.once(this._quickOpenService.onHide)(() => {
activeTextEditorWidget.updateOptions(restoreOptions);
activeTextEditorWidget.updateOptions(restoreOptions!);
});
}

Expand Down Expand Up @@ -93,13 +93,16 @@ class GotoLineEntry extends EditorQuickOpenEntry {
const maxLineNumber = this.getMaxLineNumber();

if (this.invalidRange(maxLineNumber)) {
const currentLine = this.editorService.activeTextEditorWidget.getPosition().lineNumber;
const position = this.editorService.activeTextEditorWidget.getPosition();
if (position) {
const currentLine = position.lineNumber;

if (maxLineNumber > 0) {
return nls.localize('gotoLineLabelEmptyWithLimit', "Current Line: {0}. Type a line number between 1 and {1} to navigate to.", currentLine, maxLineNumber);
}
if (maxLineNumber > 0) {
return nls.localize('gotoLineLabelEmptyWithLimit', "Current Line: {0}. Type a line number between 1 and {1} to navigate to.", currentLine, maxLineNumber);
}

return nls.localize('gotoLineLabelEmpty', "Current Line: {0}. Type a line number to navigate to.", currentLine);
return nls.localize('gotoLineLabelEmpty', "Current Line: {0}. Type a line number to navigate to.", currentLine);
}
}

// Input valid, indicate action
Expand Down Expand Up @@ -181,7 +184,7 @@ class GotoLineEntry extends EditorQuickOpenEntry {

// Decorate if possible
if (types.isFunction(activeTextEditorWidget.changeDecorations)) {
this.handler.decorateOutline(range, activeTextEditorWidget, this.editorService.activeControl.group);
this.handler.decorateOutline(range, activeTextEditorWidget, this.editorService.activeControl.group!);
}
}

Expand All @@ -208,18 +211,20 @@ export class GotoLineHandler extends QuickOpenHandler {

static readonly ID = 'workbench.picker.line';

private rangeHighlightDecorationId: IEditorLineDecoration;
private lastKnownEditorViewState: IEditorViewState;
private rangeHighlightDecorationId: IEditorLineDecoration | null;
private lastKnownEditorViewState: IEditorViewState | null;

constructor(@IEditorService private readonly editorService: IEditorService) {
super();
}

getAriaLabel(): string {
if (this.editorService.activeTextEditorWidget) {
const currentLine = this.editorService.activeTextEditorWidget.getPosition().lineNumber;

return nls.localize('gotoLineLabelEmpty', "Current Line: {0}. Type a line number to navigate to.", currentLine);
const position = this.editorService.activeTextEditorWidget.getPosition();
if (position) {
const currentLine = position.lineNumber;
return nls.localize('gotoLineLabelEmpty', "Current Line: {0}. Type a line number to navigate to.", currentLine);
}
}

return nls.localize('cannotRunGotoLine', "Open a text file first to go to a line.");
Expand Down Expand Up @@ -288,14 +293,15 @@ export class GotoLineHandler extends QuickOpenHandler {
}

clearDecorations(): void {
if (this.rangeHighlightDecorationId) {
const rangeHighlightDecorationId = this.rangeHighlightDecorationId;
if (rangeHighlightDecorationId) {
this.editorService.visibleControls.forEach(editor => {
if (editor.group.id === this.rangeHighlightDecorationId.groupId) {
if (editor.group && editor.group.id === rangeHighlightDecorationId.groupId) {
const editorControl = <IEditor>editor.getControl();
editorControl.changeDecorations(changeAccessor => {
changeAccessor.deltaDecorations([
this.rangeHighlightDecorationId.lineDecorationId,
this.rangeHighlightDecorationId.rangeHighlightId
rangeHighlightDecorationId.lineDecorationId,
rangeHighlightDecorationId.rangeHighlightId
], []);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/parts/quickopen/browser/viewPickerHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class ViewPickerHandler extends QuickOpenHandler {
const result: ViewEntry[] = [];
if (views.length) {
for (const view of views) {
if (this.contextKeyService.contextMatchesRules(view.when)) {
if (this.contextKeyService.contextMatchesRules(view.when || null)) {
result.push(new ViewEntry(view.name, viewlet.name, () => this.viewsService.openView(view.id, true)));
}
}
Expand All @@ -155,7 +155,7 @@ export class ViewPickerHandler extends QuickOpenHandler {

// Viewlet Views
viewlets.forEach((viewlet, index) => {
const viewContainer: ViewContainer = Registry.as<IViewContainersRegistry>(ViewContainerExtensions.ViewContainersRegistry).get(viewlet.id);
const viewContainer = Registry.as<IViewContainersRegistry>(ViewContainerExtensions.ViewContainersRegistry).get(viewlet.id);
if (viewContainer) {
const viewEntriesForViewlet: ViewEntry[] = getViewEntriesForViewlet(viewlet, viewContainer);
viewEntries.push(...viewEntriesForViewlet);
Expand Down
15 changes: 6 additions & 9 deletions src/vs/workbench/parts/search/browser/openFileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,11 @@ export class FileEntry extends EditorQuickOpenEntry {
const input: IResourceInput = {
resource: this.resource,
options: {
pinned: !this.configurationService.getValue<IWorkbenchEditorConfiguration>().workbench.editor.enablePreviewFromQuickOpen
pinned: !this.configurationService.getValue<IWorkbenchEditorConfiguration>().workbench.editor.enablePreviewFromQuickOpen,
selection: this.range ? this.range : undefined
}
};

if (this.range) {
input.options.selection = this.range;
}

return input;
}
}
Expand Down Expand Up @@ -178,7 +175,7 @@ export class OpenFileHandler extends QuickOpenHandler {
for (const fileMatch of complete.results) {

const label = paths.basename(fileMatch.resource.fsPath);
const description = this.labelService.getUriLabel(resources.dirname(fileMatch.resource), { relative: true });
const description = this.labelService.getUriLabel(resources.dirname(fileMatch.resource)!, { relative: true });

results.push(this.instantiationService.createInstance(FileEntry, fileMatch.resource, label, description, iconClass));
}
Expand All @@ -188,14 +185,14 @@ export class OpenFileHandler extends QuickOpenHandler {
});
}

private getAbsolutePathResult(query: IPreparedQuery): Promise<URI | null> {
private getAbsolutePathResult(query: IPreparedQuery): Promise<URI | undefined> {
if (paths.isAbsolute(query.original)) {
const resource = URI.file(query.original);

return this.fileService.resolveFile(resource).then(stat => stat.isDirectory ? undefined : resource, error => undefined);
}

return Promise.resolve(null);
return Promise.resolve(undefined);
}

private doResolveQueryOptions(query: IPreparedQuery, cacheKey?: string, maxSortedResults?: number): IFileQueryBuilderOptions {
Expand Down Expand Up @@ -273,7 +270,7 @@ export class CacheState {
private loadingPhase = LoadingPhase.Created;
private promise: Promise<void>;

constructor(cacheQuery: (cacheKey: string) => IFileQuery, private doLoad: (query: IFileQuery) => Promise<any>, private doDispose: (cacheKey: string) => Promise<void>, private previous: CacheState) {
constructor(cacheQuery: (cacheKey: string) => IFileQuery, private doLoad: (query: IFileQuery) => Promise<any>, private doDispose: (cacheKey: string) => Promise<void>, private previous: CacheState | null) {
this.query = cacheQuery(this._cacheKey);
if (this.previous) {
const current = objects.assign({}, this.query, { cacheKey: null });
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/parts/search/browser/openSymbolHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Schemas } from 'vs/base/common/network';
import { IOpenerService } from 'vs/platform/opener/common/opener';

class SymbolEntry extends EditorQuickOpenEntry {
private bearingResolve: Promise<this>;
private bearingResolve: Promise<this | undefined>;

constructor(
private bearing: IWorkspaceSymbol,
Expand All @@ -48,7 +48,7 @@ class SymbolEntry extends EditorQuickOpenEntry {
return nls.localize('entryAriaLabel', "{0}, symbols picker", this.getLabel());
}

getDescription(): string {
getDescription(): string | null {
const containerName = this.bearing.containerName;
if (this.bearing.location.uri) {
if (containerName) {
Expand All @@ -58,7 +58,7 @@ class SymbolEntry extends EditorQuickOpenEntry {
return this.labelService.getUriLabel(this.bearing.location.uri, { relative: true });
}

return containerName;
return containerName || null;
}

getIcon(): string {
Expand Down Expand Up @@ -105,7 +105,7 @@ class SymbolEntry extends EditorQuickOpenEntry {
};

if (this.bearing.location.range) {
input.options.selection = Range.collapseToStart(this.bearing.location.range);
input.options!.selection = Range.collapseToStart(this.bearing.location.range);
}

return input;
Expand Down Expand Up @@ -206,7 +206,7 @@ export class OpenSymbolHandler extends QuickOpenHandler {
}

const entry = this.instantiationService.createInstance(SymbolEntry, element, provider);
entry.setHighlights(filters.matchesFuzzy2(searchValue, entry.getLabel()));
entry.setHighlights(filters.matchesFuzzy2(searchValue, entry.getLabel()) || []);
bucket.push(entry);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/parts/terminal/browser/terminalQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ export class TerminalPickerHandler extends QuickOpenHandler {
return true;
}

const highlights = matchesFuzzy(normalizedSearchValueLowercase, e.getLabel(), true);
const label = e.getLabel();
if (!label) {
return false;
}
const highlights = matchesFuzzy(normalizedSearchValueLowercase, label, true);
if (!highlights) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class WelcomeOverlay {
const container = this.partService.getContainer(Parts.EDITOR_PART);

const offset = this.partService.getTitleBarOffset();
this._overlay = dom.append(container.parentElement, $('.welcomeOverlay'));
this._overlay = dom.append(container.parentElement!, $('.welcomeOverlay'));
this._overlay.style.top = `${offset}px`;
this._overlay.style.height = `calc(100% - ${offset}px)`;
this._overlay.style.display = 'none';
Expand Down

0 comments on commit 815a3cb

Please sign in to comment.