提交 93ebd409 编写于 作者: M Matt Bierner

Continue Strict null check for Map.get may return undefined

上级 f89f4902
......@@ -3,11 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ISpliceable } from 'vs/base/common/sequence';
import { Iterator, ISequence } from 'vs/base/common/iterator';
import { Emitter, Event, EventBufferer } from 'vs/base/common/event';
import { ICollapseStateChangeEvent, ITreeElement, ITreeFilter, ITreeFilterDataResult, ITreeModel, ITreeNode, TreeVisibility } from 'vs/base/browser/ui/tree/tree';
import { tail2 } from 'vs/base/common/arrays';
import { ITreeFilterDataResult, TreeVisibility, ITreeFilter, ITreeModel, ITreeNode, ITreeElement, ICollapseStateChangeEvent } from 'vs/base/browser/ui/tree/tree';
import { Emitter, Event, EventBufferer } from 'vs/base/common/event';
import { ISequence, Iterator } from 'vs/base/common/iterator';
import { ISpliceable } from 'vs/base/common/sequence';
interface IMutableTreeNode<T, TFilterData> extends ITreeNode<T, TFilterData> {
readonly parent: IMutableTreeNode<T, TFilterData> | undefined;
......
......@@ -218,7 +218,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
} else {
const cpuUsage = stdout.toString().split('\n');
for (let i = 0; i < pids.length; i++) {
const processInfo = map.get(pids[i]);
const processInfo = map.get(pids[i])!;
processInfo.load = parseFloat(cpuUsage[i]);
}
......
......@@ -242,7 +242,7 @@ export class ColorDetector implements IEditorContribution {
return null;
}
return this._colorDatas.get(decorations[0].id);
return this._colorDatas.get(decorations[0].id)!;
}
}
......
......@@ -626,10 +626,11 @@ export class SnippetParser {
return true;
});
for (const placeholder of incompletePlaceholders) {
if (placeholderDefaultValues.has(placeholder.index)) {
const defaultValues = placeholderDefaultValues.get(placeholder.index);
if (defaultValues) {
const clone = new Placeholder(placeholder.index);
clone.transform = placeholder.transform;
for (const child of placeholderDefaultValues.get(placeholder.index)) {
for (const child of defaultValues) {
clone.appendChild(child.clone());
}
snippet.replace(placeholder, [clone]);
......
......@@ -145,7 +145,7 @@ export class OneSnippet {
// Special case #2: placeholders enclosing active placeholders
const selections: Selection[] = [];
for (const placeholder of this._placeholderGroups[this._placeholderGroupsIdx]) {
const id = this._placeholderDecorations.get(placeholder);
const id = this._placeholderDecorations.get(placeholder)!;
const range = this._editor.getModel().getDecorationRange(id)!;
selections.push(new Selection(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn));
......
......@@ -212,9 +212,9 @@ export class StandaloneThemeServiceImpl implements IStandaloneThemeService {
public setTheme(themeName: string): string {
let theme: StandaloneTheme;
if (this._knownThemes.has(themeName)) {
theme = this._knownThemes.get(themeName);
theme = this._knownThemes.get(themeName)!;
} else {
theme = this._knownThemes.get(VS_THEME_NAME);
theme = this._knownThemes.get(VS_THEME_NAME)!;
}
if (this._theme === theme) {
// Nothing to do
......
......@@ -231,7 +231,7 @@ export class MenuItemActionItem extends ActionItem {
const iconPathMapKey = item.iconLocation.dark.toString();
if (MenuItemActionItem.ICON_PATH_TO_CSS_RULES.has(iconPathMapKey)) {
iconClass = MenuItemActionItem.ICON_PATH_TO_CSS_RULES.get(iconPathMapKey);
iconClass = MenuItemActionItem.ICON_PATH_TO_CSS_RULES.get(iconPathMapKey)!;
} else {
iconClass = ids.nextId();
createCSSRule(`.icon.${iconClass}`, `background-image: url("${(item.iconLocation.light || item.iconLocation.dark).toString()}")`);
......
......@@ -96,7 +96,8 @@ export const CommandsRegistry: ICommandRegistry = new class implements ICommandR
let ret = toDisposable(() => {
removeFn();
if (this._commands.get(id).isEmpty()) {
const command = this._commands.get(id);
if (command && command.isEmpty()) {
this._commands.delete(id);
}
});
......
......@@ -54,8 +54,9 @@ export class MockContextKeyService implements IContextKeyService {
return Event.None;
}
public getContextKeyValue(key: string) {
if (this._keys.has(key)) {
return this._keys.get(key).get();
const value = this._keys.get(key);
if (value) {
return value.get();
}
}
public getContext(domNode: HTMLElement): any {
......
......@@ -163,8 +163,9 @@ export class LifecycleService extends Disposable implements ILifecycleService {
this._phase = value;
mark(`LifecyclePhase/${LifecyclePhaseToString(value)}`);
if (this.phaseWhen.has(this._phase)) {
this.phaseWhen.get(this._phase).open();
const barrier = this.phaseWhen.get(this._phase);
if (barrier) {
barrier.open();
this.phaseWhen.delete(this._phase);
}
}
......
......@@ -347,7 +347,7 @@ export class FileIndexSearchManager {
this.folderCacheKeys.set(config.cacheKey!, new Set());
}
this.folderCacheKeys.get(config.cacheKey!).add(folderCacheKey!);
this.folderCacheKeys.get(config.cacheKey!)!.add(folderCacheKey!);
return folderCacheKey!;
}
......@@ -553,11 +553,11 @@ export class FileIndexSearchManager {
}
public clearCache(cacheKey: string): void {
if (!this.folderCacheKeys.has(cacheKey)) {
const expandedKeys = this.folderCacheKeys.get(cacheKey);
if (!expandedKeys) {
return undefined;
}
const expandedKeys = this.folderCacheKeys.get(cacheKey);
expandedKeys.forEach(key => delete this.caches[key]);
this.folderCacheKeys.delete(cacheKey);
......
......@@ -4,17 +4,17 @@
*--------------------------------------------------------------------------------------------*/
import * as crypto from 'crypto';
import { URI } from 'vs/base/common/uri';
import { relative } from 'path';
import { coalesce, equals } from 'vs/base/common/arrays';
import { illegalArgument } from 'vs/base/common/errors';
import * as vscode from 'vscode';
import { isMarkdownString } from 'vs/base/common/htmlContent';
import { IRelativePattern } from 'vs/base/common/glob';
import { relative } from 'path';
import { startsWith } from 'vs/base/common/strings';
import { isMarkdownString } from 'vs/base/common/htmlContent';
import { values } from 'vs/base/common/map';
import { coalesce, equals } from 'vs/base/common/arrays';
import { startsWith } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import { generateUuid } from 'vs/base/common/uuid';
import * as vscode from 'vscode';
export class Disposable {
......
......@@ -52,7 +52,7 @@ export interface IViewContainersRegistry {
*
* @returns the view container with given id.
*/
get(id: string): ViewContainer;
get(id: string): ViewContainer | undefined;
}
export class ViewContainer {
......@@ -71,19 +71,22 @@ class ViewContainersRegistryImpl implements IViewContainersRegistry {
}
registerViewContainer(id: string, extensionId: ExtensionIdentifier): ViewContainer {
if (!this.viewContainers.has(id)) {
const viewContainer = new class extends ViewContainer {
constructor() {
super(id, extensionId);
}
};
this.viewContainers.set(id, viewContainer);
this._onDidRegister.fire(viewContainer);
const existing = this.viewContainers.get(id);
if (existing) {
return existing;
}
return this.get(id);
const viewContainer = new class extends ViewContainer {
constructor() {
super(id, extensionId);
}
};
this.viewContainers.set(id, viewContainer);
this._onDidRegister.fire(viewContainer);
return viewContainer;
}
get(id: string): ViewContainer {
get(id: string): ViewContainer | undefined {
return this.viewContainers.get(id);
}
}
......
......@@ -96,9 +96,9 @@ export class ResourceGlobMatcher extends Disposable {
let expressionForRoot: ParsedExpression;
if (folder && this.mapRootToParsedExpression.has(folder.uri.toString())) {
expressionForRoot = this.mapRootToParsedExpression.get(folder.uri.toString());
expressionForRoot = this.mapRootToParsedExpression.get(folder.uri.toString())!;
} else {
expressionForRoot = this.mapRootToParsedExpression.get(ResourceGlobMatcher.NO_ROOT);
expressionForRoot = this.mapRootToParsedExpression.get(ResourceGlobMatcher.NO_ROOT)!;
}
// If the resource if from a workspace, convert its absolute path to a relative
......
......@@ -286,9 +286,9 @@ export class QueryBuilder {
const searchPathPatternMap = new Map<string, ISearchPathPattern>();
expandedSearchPaths.forEach(oneSearchPathPattern => {
const key = oneSearchPathPattern.searchPath.toString();
if (searchPathPatternMap.has(key)) {
const existing = searchPathPatternMap.get(key);
if (existing) {
if (oneSearchPathPattern.pattern) {
const existing = searchPathPatternMap.get(key);
existing.pattern = existing.pattern || {};
existing.pattern[oneSearchPathPattern.pattern] = true;
}
......
......@@ -94,7 +94,7 @@ export class Snippet {
// a 'variable' without a default value and not being one of our supported
// variables is automatically turned into a placeholder. This is to restore
// a bug we had before. So `${foo}` becomes `${N:foo}`
const index = placeholders.has(marker.name) ? placeholders.get(marker.name) : ++placeholderMax;
const index = placeholders.has(marker.name) ? placeholders.get(marker.name)! : ++placeholderMax;
placeholders.set(marker.name, index);
const synthetic = new Placeholder(index).appendChild(new Text(marker.name));
......
......@@ -69,23 +69,26 @@ export class CachedExtensionScanner {
let result = new Map<string, IExtensionDescription>();
system.forEach((systemExtension) => {
const extensionKey = ExtensionIdentifier.toKey(systemExtension.identifier);
if (result.has(extensionKey)) {
log.warn(systemExtension.extensionLocation.fsPath, nls.localize('overwritingExtension', "Overwriting extension {0} with {1}.", result.get(extensionKey).extensionLocation.fsPath, systemExtension.extensionLocation.fsPath));
const extension = result.get(extensionKey);
if (extension) {
log.warn(systemExtension.extensionLocation.fsPath, nls.localize('overwritingExtension', "Overwriting extension {0} with {1}.", extension.extensionLocation.fsPath, systemExtension.extensionLocation.fsPath));
}
result.set(extensionKey, systemExtension);
});
user.forEach((userExtension) => {
const extensionKey = ExtensionIdentifier.toKey(userExtension.identifier);
if (result.has(extensionKey)) {
log.warn(userExtension.extensionLocation.fsPath, nls.localize('overwritingExtension', "Overwriting extension {0} with {1}.", result.get(extensionKey).extensionLocation.fsPath, userExtension.extensionLocation.fsPath));
const extension = result.get(extensionKey);
if (extension) {
log.warn(userExtension.extensionLocation.fsPath, nls.localize('overwritingExtension', "Overwriting extension {0} with {1}.", extension.extensionLocation.fsPath, userExtension.extensionLocation.fsPath));
}
result.set(extensionKey, userExtension);
});
development.forEach(developedExtension => {
log.info('', nls.localize('extensionUnderDevelopment', "Loading development extension at {0}", developedExtension.extensionLocation.fsPath));
const extensionKey = ExtensionIdentifier.toKey(developedExtension.identifier);
if (result.has(extensionKey)) {
log.warn(developedExtension.extensionLocation.fsPath, nls.localize('overwritingExtension', "Overwriting extension {0} with {1}.", result.get(extensionKey).extensionLocation.fsPath, developedExtension.extensionLocation.fsPath));
const extension = result.get(extensionKey);
if (extension) {
log.warn(developedExtension.extensionLocation.fsPath, nls.localize('overwritingExtension', "Overwriting extension {0} with {1}.", extension.extensionLocation.fsPath, developedExtension.extensionLocation.fsPath));
}
result.set(extensionKey, developedExtension);
});
......
......@@ -62,8 +62,11 @@ export class ExtensionHostProfiler {
idsToSegmentId.set(node.id, segmentId);
if (node.children) {
for (let child of node.children) {
visit(idsToNodes.get(child), segmentId);
for (const child of node.children) {
const childNode = idsToNodes.get(child);
if (childNode) {
visit(childNode, segmentId);
}
}
}
}
......
......@@ -29,13 +29,14 @@ export class CachedKeyboardMapper implements IKeyboardMapper {
}
public resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[] {
let hashCode = keybinding.getHashCode();
if (!this._cache.has(hashCode)) {
let r = this._actual.resolveKeybinding(keybinding);
const hashCode = keybinding.getHashCode();
const resolved = this._cache.get(hashCode);
if (!resolved) {
const r = this._actual.resolveKeybinding(keybinding);
this._cache.set(hashCode, r);
return r;
}
return this._cache.get(hashCode);
return resolved;
}
public resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册