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

Strict null work

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