提交 815a3cb8 编写于 作者: M Matt Bierner

Strict null check more files related to quick open

上级 66614c07
......@@ -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",
......@@ -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",
......@@ -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",
......@@ -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",
......
......@@ -214,7 +214,7 @@ export class QuickOpenEntryGroup extends QuickOpenEntry {
return this.groupLabel;
}
setGroupLabel(groupLabel: string): void {
setGroupLabel(groupLabel: string | undefined): void {
this.groupLabel = groupLabel;
}
......
......@@ -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;
}
......@@ -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;
}
......
......@@ -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);
......@@ -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);
}
......@@ -214,14 +214,14 @@ 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
......@@ -229,15 +229,15 @@ abstract class BaseCommandEntry extends QuickOpenEntryGroup {
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 {
......@@ -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}`;
......@@ -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];
......
......@@ -61,7 +61,7 @@ export class GotoLineAction extends QuickOpenAction {
if (restoreOptions) {
Event.once(this._quickOpenService.onHide)(() => {
activeTextEditorWidget.updateOptions(restoreOptions);
activeTextEditorWidget.updateOptions(restoreOptions!);
});
}
......@@ -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
......@@ -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!);
}
}
......@@ -208,8 +211,8 @@ 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();
......@@ -217,9 +220,11 @@ export class GotoLineHandler extends QuickOpenHandler {
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.");
......@@ -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
], []);
});
}
......
......@@ -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)));
}
}
......@@ -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);
......
......@@ -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;
}
}
......@@ -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));
}
......@@ -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 {
......@@ -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 });
......
......@@ -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,
......@@ -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) {
......@@ -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 {
......@@ -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;
......@@ -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);
}
}
......
......@@ -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;
}
......
......@@ -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';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册