提交 57b3fc8a 编写于 作者: M Matt Bierner

Explicitly convert undefined and null to false if they are used in place of boolean value

part of strict null work
上级 48db68b4
......@@ -796,7 +796,7 @@ export class EditorStatus implements IStatusbarItem {
private isActiveEditor(control: IBaseEditor): boolean {
const activeControl = this.editorService.activeControl;
return activeControl && activeControl === control;
return !!activeControl && activeControl === control;
}
}
......
......@@ -582,7 +582,7 @@ class TreeDataSource implements IDataSource {
}
hasChildren(tree: ITree, node: ITreeItem): boolean {
return this.treeView.dataProvider && node.collapsibleState !== TreeItemCollapsibleState.None;
return !!this.treeView.dataProvider && node.collapsibleState !== TreeItemCollapsibleState.None;
}
getChildren(tree: ITree, node: ITreeItem): Promise<any[]> {
......
......@@ -97,7 +97,7 @@ export class CodeInsetWidget {
return this._decorationIds.some((id, i) => {
const range = this._editor.getModel().getDecorationRange(id);
const symbol = this._data[i].symbol;
return range && Range.isEmpty(symbol.range) === range.isEmpty();
return !!range && Range.isEmpty(symbol.range) === range.isEmpty();
});
}
......
......@@ -594,7 +594,7 @@ export class SetValueAction extends AbstractDebugAction {
protected isEnabled(state: State): boolean {
const session = this.debugService.getViewModel().focusedSession;
return super.isEnabled(state) && state === State.Stopped && session && session.capabilities.supportsSetVariable;
return !!(super.isEnabled(state) && state === State.Stopped && session && session.capabilities.supportsSetVariable);
}
}
......@@ -774,8 +774,8 @@ export class StepBackAction extends AbstractDebugAction {
protected isEnabled(state: State): boolean {
const session = this.debugService.getViewModel().focusedSession;
return super.isEnabled(state) && state === State.Stopped &&
session && session.capabilities.supportsStepBack;
return !!(super.isEnabled(state) && state === State.Stopped &&
session && session.capabilities.supportsStepBack);
}
}
......@@ -797,8 +797,8 @@ export class ReverseContinueAction extends AbstractDebugAction {
protected isEnabled(state: State): boolean {
const session = this.debugService.getViewModel().focusedSession;
return super.isEnabled(state) && state === State.Stopped &&
session && session.capabilities.supportsStepBack;
return !!(super.isEnabled(state) && state === State.Stopped &&
session && session.capabilities.supportsStepBack);
}
}
......
......@@ -879,7 +879,7 @@ export class DebugModel implements IDebugModel {
this.exceptionBreakpoints = data.map(d => {
const ebp = this.exceptionBreakpoints.filter(ebp => ebp.filter === d.filter).pop();
return new ExceptionBreakpoint(d.filter, d.label, ebp ? ebp.enabled : d.default);
return new ExceptionBreakpoint(d.filter, d.label, ebp ? ebp.enabled : !!d.default);
});
this._onDidChangeBreakpoints.fire(undefined);
}
......
......@@ -540,7 +540,7 @@ class ShowMoreRenderer implements ITreeRenderer<IStackFrame[], FuzzyScore, ILabe
renderElement(element: ITreeNode<IStackFrame[], FuzzyScore>, index: number, data: ILabelTemplateData): void {
const stackFrames = element.element;
if (stackFrames.every(sf => sf.source && sf.source.origin && sf.source.origin === stackFrames[0].source.origin)) {
if (stackFrames.every(sf => !!(sf.source && sf.source.origin && sf.source.origin === stackFrames[0].source.origin))) {
data.label.textContent = nls.localize('showMoreAndOrigin', "Show {0} More: {1}", stackFrames.length, stackFrames[0].source.origin);
} else {
data.label.textContent = nls.localize('showMoreStackFrames', "Show {0} More Stack Frames", stackFrames.length);
......
......@@ -146,9 +146,9 @@ export class Debugger implements IDebugger {
private inExtHost(): boolean {
const debugConfigs = this.configurationService.getValue<IDebugConfiguration>('debug');
return debugConfigs.extensionHostDebugAdapter
return !!debugConfigs.extensionHostDebugAdapter
|| this.configurationManager.needsToRunInExtHost(this.type)
|| (this.mainExtensionDescription && this.mainExtensionDescription.extensionLocation.scheme !== 'file');
|| (!!this.mainExtensionDescription && this.mainExtensionDescription.extensionLocation.scheme !== 'file');
}
get label(): string {
......
......@@ -126,7 +126,7 @@ class NavBar {
_update(id: string | null = this.currentId, focus?: boolean): Promise<void> {
this.currentId = id;
this._onChange.fire({ id, focus });
this._onChange.fire({ id, focus: !!focus });
this.actions.forEach(a => a.enabled = a.id !== id);
return Promise.resolve(undefined);
}
......
......@@ -308,8 +308,8 @@ export class ExplorerView extends ViewletPanel {
const isSingleFolder = this.contextService.getWorkbenchState() === WorkbenchState.FOLDER;
const resource = stat ? stat.resource : isSingleFolder ? this.contextService.getWorkspace().folders[0].uri : undefined;
this.resourceContext.set(resource);
this.folderContext.set((isSingleFolder && !stat) || stat && stat.isDirectory);
this.readonlyContext.set(stat && stat.isReadonly);
this.folderContext.set((isSingleFolder && !stat) || !!stat && stat.isDirectory);
this.readonlyContext.set(!!stat && stat.isReadonly);
this.rootContext.set(!stat || (stat && stat.isRoot));
}));
......
......@@ -472,7 +472,7 @@ export class FileDragAndDrop implements ITreeDragAndDrop<ExplorerItem> {
if (!target) {
// Droping onto the empty area. Do not accept if items dragged are already
// children of the root unless we are copying the file
if (!isCopy && items.every(i => i.parent && i.parent.isRoot)) {
if (!isCopy && items.every(i => !!i.parent && i.parent.isRoot)) {
return false;
}
......
......@@ -358,7 +358,7 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
const markersNavigator = this._register(new TreeResourceNavigator2(this.tree, { openOnFocus: true }));
this._register(Event.debounce(markersNavigator.onDidOpenResource, (last, event) => event, 75, true)(options => {
this.openFileAtElement(options.element, options.editorOptions.preserveFocus, options.sideBySide, options.editorOptions.pinned);
this.openFileAtElement(options.element, !!options.editorOptions.preserveFocus, options.sideBySide, !!options.editorOptions.pinned);
}));
this._register(this.tree.onDidChangeCollapseState(({ node }) => {
const { element } = node;
......
......@@ -303,7 +303,7 @@ class MarkerWidget extends Disposable {
const viewModel = this.markersViewModel.getViewModel(marker);
const multiline = viewModel && viewModel.multiline;
const action = new Action('problems.action.toggleMultiline');
action.enabled = viewModel && marker.lines.length > 1;
action.enabled = !!viewModel && marker.lines.length > 1;
action.tooltip = multiline ? localize('single line', "Show message in single line") : localize('multi line', "Show message in multiple lines");
action.class = multiline ? 'octicon octicon-chevron-up' : 'octicon octicon-chevron-down';
action.run = () => { if (viewModel) { viewModel.multiline = !viewModel.multiline; } return Promise.resolve(); };
......
......@@ -193,7 +193,7 @@ export class OpenLogOutputFile extends Action {
private update(): void {
const outputChannelDescriptor = this.getOutputChannelDescriptor();
this.enabled = outputChannelDescriptor && outputChannelDescriptor.file && outputChannelDescriptor.log;
this.enabled = !!(outputChannelDescriptor && outputChannelDescriptor.file && outputChannelDescriptor.log);
}
public run(): Promise<any> {
......
......@@ -493,10 +493,10 @@ export class OutputService extends Disposable implements IOutputService, ITextMo
this.activeChannel = channel;
let promise: Promise<void>;
if (this.isPanelShown()) {
promise = this.doShowChannel(channel, preserveFocus);
promise = this.doShowChannel(channel, !!preserveFocus);
} else {
this.panelService.openPanel(OUTPUT_PANEL_ID);
promise = this.doShowChannel(this.activeChannel, preserveFocus);
promise = this.doShowChannel(this.activeChannel, !!preserveFocus);
}
return promise.then(() => this._onActiveOutputChannel.fire(id));
}
......@@ -613,7 +613,7 @@ export class OutputService extends Disposable implements IOutputService, ITextMo
private isPanelShown(): boolean {
const panel = this.panelService.getActivePanel();
return panel && panel.getId() === OUTPUT_PANEL_ID;
return !!panel && panel.getId() === OUTPUT_PANEL_ID;
}
private createInput(channel: IOutputChannel): ResourceEditorInput {
......
......@@ -129,7 +129,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
setInput(input: KeybindingsEditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
this.keybindingsEditorContextKey.set(true);
return super.setInput(input, options, token)
.then(() => this.render(options && options.preserveFocus, token));
.then(() => this.render(!!(options && options.preserveFocus), token));
}
clearInput(): void {
......
......@@ -499,7 +499,7 @@ class PreferencesRenderersController extends Disposable {
this.consolidateAndUpdate(defaultFilterResult, editableFilterResult);
this._lastFilterResult = defaultFilterResult;
return defaultFilterResult && defaultFilterResult.exactMatch;
return !!(defaultFilterResult && defaultFilterResult.exactMatch);
});
}
......
......@@ -755,7 +755,7 @@ export class SettingsEditor2 extends BaseEditor {
query: this.searchWidget.getValue(),
searchResults: this.searchResultModel && this.searchResultModel.getUniqueResults(),
rawResults: this.searchResultModel && this.searchResultModel.getRawResults(),
showConfiguredOnly: this.viewState.tagFilters && this.viewState.tagFilters.has(MODIFIED_SETTING_TAG),
showConfiguredOnly: !!this.viewState.tagFilters && this.viewState.tagFilters.has(MODIFIED_SETTING_TAG),
isReset: typeof value === 'undefined',
settingsTarget: this.settingsTargetsWidget.settingsTarget as SettingsTarget
};
......
......@@ -34,7 +34,7 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
export function isSearchViewFocused(viewletService: IViewletService, panelService: IPanelService): boolean {
const searchView = getSearchView(viewletService, panelService);
const activeElement = document.activeElement;
return searchView && activeElement && DOM.isAncestor(activeElement, searchView.getContainer());
return !!(searchView && activeElement && DOM.isAncestor(activeElement, searchView.getContainer()));
}
export function appendKeyBindingLabel(label: string, keyBinding: number | ResolvedKeybinding, keyBindingService2: IKeybindingService): string {
......@@ -262,7 +262,7 @@ export class CollapseDeepestExpandedLevelAction extends Action {
update(): void {
const searchView = getSearchView(this.viewletService, this.panelService);
this.enabled = searchView && searchView.hasSearchResults();
this.enabled = !!searchView && searchView.hasSearchResults();
}
run(): Promise<void> {
......@@ -319,7 +319,7 @@ export class ClearSearchResultsAction extends Action {
update(): void {
const searchView = getSearchView(this.viewletService, this.panelService);
this.enabled = searchView && (!searchView.allSearchFieldsClear() || searchView.hasSearchResults());
this.enabled = !!searchView && (!searchView.allSearchFieldsClear() || searchView.hasSearchResults());
}
run(): Promise<void> {
......@@ -327,7 +327,7 @@ export class ClearSearchResultsAction extends Action {
if (searchView) {
searchView.clearSearchResults();
}
return Promise.resolve(null);
return Promise.resolve();
}
}
......@@ -346,7 +346,7 @@ export class CancelSearchAction extends Action {
update(): void {
const searchView = getSearchView(this.viewletService, this.panelService);
this.enabled = searchView && searchView.isSearching();
this.enabled = !!searchView && searchView.isSearching();
}
run(): Promise<void> {
......
......@@ -185,7 +185,7 @@ export class SearchWidget extends Widget {
}
isReplaceActive(): boolean {
return this.replaceActive.get();
return !!this.replaceActive.get();
}
getReplaceValue(): string {
......
......@@ -161,7 +161,7 @@ export class TerminalPanel extends Panel {
});
}
const activeInstance = this._terminalService.getActiveInstance();
this._copyContextMenuAction.enabled = activeInstance && activeInstance.hasSelection();
this._copyContextMenuAction.enabled = !!activeInstance && activeInstance.hasSelection();
return this._contextMenuActions;
}
......
......@@ -352,10 +352,10 @@ export class Workbench extends Disposable implements IPartService {
this.workbenchParams = { configuration, serviceCollection };
this.hasInitialFilesToOpen =
this.hasInitialFilesToOpen = !!(
(configuration.filesToCreate && configuration.filesToCreate.length > 0) ||
(configuration.filesToOpen && configuration.filesToOpen.length > 0) ||
(configuration.filesToDiff && configuration.filesToDiff.length > 0);
(configuration.filesToDiff && configuration.filesToDiff.length > 0));
this.registerErrorHandler();
}
......@@ -944,7 +944,7 @@ export class Workbench extends Disposable implements IPartService {
}
const newMenubarVisibility = this.configurationService.getValue<MenuBarVisibility>(Workbench.menubarVisibilityConfigurationKey);
this.setMenubarVisibility(newMenubarVisibility, skipLayout);
this.setMenubarVisibility(newMenubarVisibility, !!skipLayout);
}
//#endregion
......@@ -976,7 +976,7 @@ export class Workbench extends Disposable implements IPartService {
const activeControl = this.editorService.activeControl;
const visibleEditors = this.editorService.visibleControls;
textCompareEditorActive.set(activeControl && activeControl.getId() === TEXT_DIFF_EDITOR_ID);
textCompareEditorActive.set(!!activeControl && activeControl.getId() === TEXT_DIFF_EDITOR_ID);
textCompareEditorVisible.set(visibleEditors.some(control => control.getId() === TEXT_DIFF_EDITOR_ID));
if (visibleEditors.length > 0) {
......@@ -1013,7 +1013,7 @@ export class Workbench extends Disposable implements IPartService {
const inputFocused = InputFocusedContext.bindTo(this.contextKeyService);
function activeElementIsInput(): boolean {
return document.activeElement && (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA');
return !!document.activeElement && (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA');
}
function trackInputFocus(): void {
......
......@@ -474,7 +474,7 @@ export class ConfigurationEditingService {
private isWorkspaceConfigurationResource(resource: URI): boolean {
const workspace = this.contextService.getWorkspace();
return workspace.configuration && resource && workspace.configuration.fsPath === resource.fsPath;
return !!(workspace.configuration && resource && workspace.configuration.fsPath === resource.fsPath);
}
private getConfigurationFileResource(target: ConfigurationTarget, relativePath: string, resource: URI): URI {
......
......@@ -839,11 +839,11 @@ export class FileService extends Disposable implements IFileService {
}
moveFile(source: uri, target: uri, overwrite?: boolean): Promise<IFileStat> {
return this.moveOrCopyFile(source, target, false, overwrite);
return this.moveOrCopyFile(source, target, false, !!overwrite);
}
copyFile(source: uri, target: uri, overwrite?: boolean): Promise<IFileStat> {
return this.moveOrCopyFile(source, target, true, overwrite);
return this.moveOrCopyFile(source, target, true, !!overwrite);
}
private moveOrCopyFile(source: uri, target: uri, keepCopy: boolean, overwrite: boolean): Promise<IFileStat> {
......@@ -915,7 +915,7 @@ export class FileService extends Disposable implements IFileService {
return this.doMoveItemToTrash(resource);
}
return this.doDelete(resource, options && options.recursive);
return this.doDelete(resource, !!(options && options.recursive));
}
private doMoveItemToTrash(resource: uri): Promise<void> {
......
......@@ -505,7 +505,7 @@ export class RemoteFileService extends FileService {
return super.del(resource, options);
} else {
return this._withProvider(resource).then(RemoteFileService._throwIfFileSystemIsReadonly).then(provider => {
return provider.delete(resource, { recursive: options && options.recursive }).then(() => {
return provider.delete(resource, { recursive: !!(options && options.recursive) }).then(() => {
this._onAfterOperation.fire(new FileOperationEvent(resource, FileOperation.DELETE));
});
});
......@@ -593,7 +593,7 @@ export class RemoteFileService extends FileService {
if (source.scheme === target.scheme && (provider.capabilities & FileSystemProviderCapabilities.FileFolderCopy)) {
// good: provider supports copy withing scheme
return provider.copy(source, target, { overwrite }).then(() => {
return provider.copy(source, target, { overwrite: !!overwrite }).then(() => {
return this.resolveFile(target);
}).then(fileStat => {
this._onAfterOperation.fire(new FileOperationEvent(source, FileOperation.COPY, fileStat));
......@@ -620,7 +620,7 @@ export class RemoteFileService extends FileService {
provider, target,
new StringSnapshot(content.value),
content.encoding,
{ create: true, overwrite }
{ create: true, overwrite: !!overwrite }
).then(fileStat => {
this._onAfterOperation.fire(new FileOperationEvent(source, FileOperation.COPY, fileStat));
return fileStat;
......
......@@ -1004,7 +1004,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
}
isReadonly(): boolean {
return this.lastResolvedDiskStat && this.lastResolvedDiskStat.isReadonly;
return !!(this.lastResolvedDiskStat && this.lastResolvedDiskStat.isReadonly);
}
isDisposed(): boolean {
......
......@@ -515,7 +515,7 @@ export class TextFileService extends Disposable implements ITextFileService {
}
}
return this.saveAll([resource], options).then(result => result.results.length === 1 && result.results[0].success);
return this.saveAll([resource], options).then(result => result.results.length === 1 && !!result.results[0].success);
}
saveAll(includeUntitled?: boolean, options?: ISaveOptions): Promise<ITextFileOperationResult>;
......@@ -794,7 +794,7 @@ export class TextFileService extends Disposable implements ITextFileService {
}
revert(resource: URI, options?: IRevertOptions): Promise<boolean> {
return this.revertAll([resource], options).then(result => result.results.length === 1 && result.results[0].success);
return this.revertAll([resource], options).then(result => result.results.length === 1 && !!result.results[0].success);
}
revertAll(resources?: URI[], options?: IRevertOptions): Promise<ITextFileOperationResult> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册