Use ??= in more places (#163594)

This commit is contained in:
Matt Bierner
2022-10-13 14:59:35 -07:00
committed by GitHub
parent 65a9097aa2
commit 186d3415a3
11 changed files with 16 additions and 44 deletions

View File

@@ -117,13 +117,9 @@ class MyCompletionItem extends vscode.CompletionItem {
if (tsEntry.kindModifiers) {
const kindModifiers = parseKindModifier(tsEntry.kindModifiers);
if (kindModifiers.has(PConst.KindModifiers.optional)) {
if (!this.insertText) {
this.insertText = this.textLabel;
}
this.insertText ??= this.textLabel;
this.filterText ??= this.textLabel;
if (!this.filterText) {
this.filterText = this.textLabel;
}
if (typeof this.label === 'string') {
this.label += '?';
} else {

View File

@@ -30,10 +30,7 @@ class FileReferencesCommand implements Command {
return;
}
if (!resource) {
resource = vscode.window.activeTextEditor?.document.uri;
}
resource ??= vscode.window.activeTextEditor?.document.uri;
if (!resource) {
vscode.window.showErrorMessage(localize('error.noResource', "Find file references failed. No resource provided."));
return;

View File

@@ -54,14 +54,10 @@ class ConditionalRegistration {
private update() {
const enabled = this.conditions.every(condition => condition.value);
if (enabled) {
if (!this.registration) {
this.registration = this.doRegister();
}
this.registration ??= this.doRegister();
} else {
if (this.registration) {
this.registration.dispose();
this.registration = undefined;
}
this.registration?.dispose();
this.registration = undefined;
}
}
}

View File

@@ -28,7 +28,7 @@ namespace TypeScriptServerPlugin {
export class PluginManager extends Disposable {
private readonly _pluginConfigurations = new Map<string, {}>();
private _plugins: Map<string, ReadonlyArray<TypeScriptServerPlugin>> | undefined;
private _plugins?: Map<string, ReadonlyArray<TypeScriptServerPlugin>>;
constructor() {
super();
@@ -37,6 +37,7 @@ export class PluginManager extends Disposable {
if (!this._plugins) {
return;
}
const newPlugins = this.readPlugins();
if (!arrays.equals(Array.from(this._plugins.values()).flat(), Array.from(newPlugins.values()).flat(), TypeScriptServerPlugin.equals)) {
this._plugins = newPlugins;
@@ -46,9 +47,7 @@ export class PluginManager extends Disposable {
}
public get plugins(): ReadonlyArray<TypeScriptServerPlugin> {
if (!this._plugins) {
this._plugins = this.readPlugins();
}
this._plugins ??= this.readPlugins();
return Array.from(this._plugins.values()).flat();
}

View File

@@ -34,9 +34,7 @@ const getRootTempDir = (() => {
export const getInstanceTempDir = (() => {
let dir: string | undefined;
return () => {
if (!dir) {
dir = path.join(getRootTempDir(), makeRandomHexString(20));
}
dir ??= path.join(getRootTempDir(), makeRandomHexString(20));
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}