提交 9e440ff0 编写于 作者: M Matt Bierner

Strict null work

上级 536691a1
......@@ -585,10 +585,12 @@ export class EditorStatus implements IStatusbarItem {
this.onEOLChange(activeCodeEditor);
const selections = activeCodeEditor.getSelections();
for (const change of e.changes) {
if (selections.some(selection => Range.areIntersecting(selection, change.range))) {
this.onSelectionChange(activeCodeEditor);
break;
if (selections) {
for (const change of e.changes) {
if (selections.some(selection => Range.areIntersecting(selection, change.range))) {
this.onSelectionChange(activeCodeEditor);
break;
}
}
}
}));
......@@ -662,7 +664,7 @@ export class EditorStatus implements IStatusbarItem {
this.updateState(update);
}
private onMetadataChange(editor: IBaseEditor): void {
private onMetadataChange(editor: IBaseEditor | undefined): void {
const update: StateDelta = { metadata: undefined };
if (editor instanceof BaseBinaryResourceEditor || editor instanceof BinaryResourceDiffEditor) {
......@@ -762,7 +764,7 @@ export class EditorStatus implements IStatusbarItem {
// We only support text based editors
if (e && (isCodeEditor(e.getControl()) || isDiffEditor(e.getControl()))) {
const encodingSupport: IEncodingSupport = toEditorWithEncodingSupport(e.input);
const encodingSupport: IEncodingSupport | null = e.input ? toEditorWithEncodingSupport(e.input) : null;
if (encodingSupport) {
const rawEncoding = encodingSupport.getEncoding();
const encodingInfo = SUPPORTED_ENCODINGS[rawEncoding];
......@@ -858,19 +860,19 @@ export class ChangeModeAction extends Action {
}
const textModel = activeTextEditorWidget.getModel();
const resource = toResource(this.editorService.activeEditor, { supportSideBySide: true });
const resource = this.editorService.activeEditor ? toResource(this.editorService.activeEditor, { supportSideBySide: true }) : null;
let hasLanguageSupport = !!resource;
if (resource.scheme === Schemas.untitled && !this.untitledEditorService.hasAssociatedFilePath(resource)) {
if (resource && resource.scheme === Schemas.untitled && !this.untitledEditorService.hasAssociatedFilePath(resource)) {
hasLanguageSupport = false; // no configuration for untitled resources (e.g. "Untitled-1")
}
// Compute mode
let currentModeId: string;
let currentModeId: string | undefined;
let modeId: string;
if (textModel) {
modeId = textModel.getLanguageIdentifier().language;
currentModeId = this.modeService.getLanguageName(modeId);
currentModeId = this.modeService.getLanguageName(modeId) || undefined;
}
// All languages are valid picks
......@@ -910,7 +912,7 @@ export class ChangeModeAction extends Action {
let configureModeAssociations: IQuickPickItem;
let configureModeSettings: IQuickPickItem;
let galleryAction: Action;
if (hasLanguageSupport) {
if (hasLanguageSupport && resource) {
const ext = extname(resource) || basename(resource);
galleryAction = this.instantiationService.createInstance(ShowLanguageExtensionsAction, ext);
......@@ -1026,11 +1028,7 @@ export class ChangeModeAction extends Action {
}
// Make sure to write into the value of the target and not the merged value from USER and WORKSPACE config
let currentAssociations = deepClone((target === ConfigurationTarget.WORKSPACE) ? fileAssociationsConfig.workspace : fileAssociationsConfig.user);
if (!currentAssociations) {
currentAssociations = Object.create(null);
}
const currentAssociations = deepClone((target === ConfigurationTarget.WORKSPACE) ? fileAssociationsConfig.workspace : fileAssociationsConfig.user) || Object.create(null);
currentAssociations[associationKey] = language.id;
this.configurationService.updateValue(FILES_ASSOCIATIONS_CONFIG, currentAssociations, target);
......@@ -1161,7 +1159,10 @@ export class ChangeEncodingAction extends Action {
}
let activeControl = this.editorService.activeControl;
let encodingSupport: IEncodingSupport = toEditorWithEncodingSupport(activeControl.input);
if (!activeControl) {
return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
}
let encodingSupport: IEncodingSupport | null = toEditorWithEncodingSupport(activeControl.input);
if (!encodingSupport) {
return this.quickInputService.pick([{ label: nls.localize('noFileEditor', "No file active at this time") }]);
}
......@@ -1206,7 +1207,7 @@ export class ChangeEncodingAction extends Action {
const configuredEncoding = this.textResourceConfigurationService.getValue(resource, 'files.encoding');
let directMatchIndex: number | undefined;
let aliasMatchIndex: number;
let aliasMatchIndex: number | undefined;
// All encodings are valid picks
const picks: QuickPickInput[] = Object.keys(SUPPORTED_ENCODINGS)
......
......@@ -217,7 +217,7 @@ export abstract class TitleControl extends Themable {
this.editorToolBarMenuDisposables = dispose(this.editorToolBarMenuDisposables);
// Update the resource context
this.resourceContext.set(toResource(this.group.activeEditor, { supportSideBySide: true }));
this.resourceContext.set(this.group.activeEditor ? toResource(this.group.activeEditor, { supportSideBySide: true }) : null);
// Editor actions require the editor control to be there, so we retrieve it via service
const activeControl = this.group.activeControl;
......@@ -312,7 +312,7 @@ export abstract class TitleControl extends Themable {
});
}
private getKeybinding(action: IAction): ResolvedKeybinding {
private getKeybinding(action: IAction): ResolvedKeybinding | undefined {
return this.keybindingService.lookupKeybinding(action.id);
}
......
......@@ -308,7 +308,7 @@ export class SearchAccessibilityProvider implements IAccessibilityProvider<Rende
) {
}
getAriaLabel(element: RenderableMatch): string {
getAriaLabel(element: RenderableMatch): string | null {
if (element instanceof BaseFolderMatch) {
return element.hasResource() ?
nls.localize('folderMatchAriaLabel', "{0} matches in folder root {1}, Search result", element.count(), element.name()) :
......@@ -334,7 +334,7 @@ export class SearchAccessibilityProvider implements IAccessibilityProvider<Rende
return nls.localize('searchResultAria', "Found term {0} at column position {1} in line with text {2}", matchString, range.startColumn + 1, matchText);
}
return undefined;
return null;
}
}
......
......@@ -116,7 +116,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
private currentSelectedFileMatch: FileMatch;
private readonly selectCurrentMatchEmitter: Emitter<string>;
private readonly selectCurrentMatchEmitter: Emitter<string | undefined>;
private delayedRefresh: Delayer<void>;
private changedWhileHidden: boolean;
......@@ -704,7 +704,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
}
selectNextMatch(): void {
const [selected]: RenderableMatch[] = this.tree.getSelection();
const [selected] = this.tree.getSelection();
// Expand the initial selected node, if needed
if (selected instanceof FileMatch) {
......@@ -742,7 +742,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
}
selectPreviousMatch(): void {
const [selected]: RenderableMatch[] = this.tree.getSelection();
const [selected] = this.tree.getSelection();
let navigator = this.tree.navigate(selected);
let prev = navigator.previous();
......@@ -757,7 +757,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
// This is complicated because .last will set the navigator to the last FileMatch,
// so expand it and FF to its last child
this.tree.expand(prev);
let tmp: RenderableMatch;
let tmp: RenderableMatch | null;
while (tmp = navigator.next()) {
prev = tmp;
}
......@@ -967,7 +967,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
}
}
private getSearchTextFromEditor(allowUnselectedWord: boolean): string {
private getSearchTextFromEditor(allowUnselectedWord: boolean): string | null {
if (!this.editorService.activeEditor) {
return null;
}
......@@ -985,7 +985,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
}
}
if (!isCodeEditor(activeTextEditorWidget)) {
if (!isCodeEditor(activeTextEditorWidget) || !activeTextEditorWidget.hasModel()) {
return null;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册