mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-23 19:59:37 +00:00
Use more optional chaining in TS extension (#152271)
Use optional chaining in TS extension Also removes `prefer-const` since this is now enabled globally
This commit is contained in:
@@ -88,7 +88,7 @@ export function getSymbolRange(
|
||||
}
|
||||
|
||||
// In older versions, we have to calculate this manually. See #23924
|
||||
const span = item.spans && item.spans[0];
|
||||
const span = item.spans?.[0];
|
||||
if (!span) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class TypeScriptSignatureHelpProvider implements vscode.SignatureHelpProvider {
|
||||
|
||||
private getActiveParameter(info: Proto.SignatureHelpItems): number {
|
||||
const activeSignature = info.items[info.selectedItemIndex];
|
||||
if (activeSignature && activeSignature.isVariadic) {
|
||||
if (activeSignature?.isVariadic) {
|
||||
return Math.min(info.argumentIndex, activeSignature.parameters.length - 1);
|
||||
}
|
||||
return info.argumentIndex;
|
||||
|
||||
@@ -53,7 +53,7 @@ class TagClosing extends Disposable {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeDocument = vscode.window.activeTextEditor && vscode.window.activeTextEditor.document;
|
||||
const activeDocument = vscode.window.activeTextEditor?.document;
|
||||
if (document !== activeDocument) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export class DiskTypeScriptVersionProvider implements ITypeScriptVersionProvider
|
||||
public get globalVersion(): TypeScriptVersion | undefined {
|
||||
if (this.configuration?.globalTsdk) {
|
||||
const globals = this.loadVersionsFromSetting(TypeScriptVersionSource.UserSetting, this.configuration.globalTsdk);
|
||||
if (globals && globals.length) {
|
||||
if (globals?.length) {
|
||||
return globals[0];
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ export class DiskTypeScriptVersionProvider implements ITypeScriptVersionProvider
|
||||
|
||||
public get localVersion(): TypeScriptVersion | undefined {
|
||||
const tsdkVersions = this.localTsdkVersions;
|
||||
if (tsdkVersions && tsdkVersions.length) {
|
||||
if (tsdkVersions?.length) {
|
||||
return tsdkVersions[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -883,7 +883,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
|
||||
this.loadingIndicator.reset();
|
||||
|
||||
const diagnosticEvent = event as Proto.DiagnosticEvent;
|
||||
if (diagnosticEvent.body && diagnosticEvent.body.diagnostics) {
|
||||
if (diagnosticEvent.body?.diagnostics) {
|
||||
this._onDiagnosticsReceived.fire({
|
||||
kind: getDignosticsKind(event),
|
||||
resource: this.toResource(diagnosticEvent.body.file),
|
||||
|
||||
@@ -13,7 +13,7 @@ export class Delayer<T> {
|
||||
|
||||
public defaultDelay: number;
|
||||
private timeout: any; // Timer
|
||||
private completionPromise: Promise<T | null> | null;
|
||||
private completionPromise: Promise<T | undefined> | null;
|
||||
private onSuccess: ((value: T | PromiseLike<T> | undefined) => void) | null;
|
||||
private task: ITask<T> | null;
|
||||
|
||||
@@ -25,7 +25,7 @@ export class Delayer<T> {
|
||||
this.task = null;
|
||||
}
|
||||
|
||||
public trigger(task: ITask<T>, delay: number = this.defaultDelay): Promise<T | null> {
|
||||
public trigger(task: ITask<T>, delay: number = this.defaultDelay): Promise<T | undefined> {
|
||||
this.task = task;
|
||||
if (delay >= 0) {
|
||||
this.cancelTimeout();
|
||||
@@ -37,7 +37,7 @@ export class Delayer<T> {
|
||||
}).then(() => {
|
||||
this.completionPromise = null;
|
||||
this.onSuccess = null;
|
||||
const result = this.task && this.task();
|
||||
const result = this.task?.();
|
||||
this.task = null;
|
||||
return result;
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ export function getEditForCodeAction(
|
||||
client: ITypeScriptServiceClient,
|
||||
action: Proto.CodeAction
|
||||
): vscode.WorkspaceEdit | undefined {
|
||||
return action.changes && action.changes.length
|
||||
return action.changes?.length
|
||||
? typeConverters.WorkspaceEdit.fromFileCodeEdits(client, action.changes)
|
||||
: undefined;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ export async function applyCodeActionCommands(
|
||||
commands: ReadonlyArray<{}> | undefined,
|
||||
token: vscode.CancellationToken,
|
||||
): Promise<boolean> {
|
||||
if (commands && commands.length) {
|
||||
if (commands?.length) {
|
||||
for (const command of commands) {
|
||||
await client.execute('applyCodeActionCommand', { command }, token);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export enum TsServerLogLevel {
|
||||
|
||||
export namespace TsServerLogLevel {
|
||||
export function fromString(value: string): TsServerLogLevel {
|
||||
switch (value && value.toLowerCase()) {
|
||||
switch (value?.toLowerCase()) {
|
||||
case 'normal':
|
||||
return TsServerLogLevel.Normal;
|
||||
case 'terse':
|
||||
|
||||
@@ -55,7 +55,7 @@ export class VSCodeTelemetryReporter implements TelemetryReporter {
|
||||
|
||||
@memoize
|
||||
private get reporter(): VsCodeTelemetryReporter | null {
|
||||
if (this.packageInfo && this.packageInfo.aiKey) {
|
||||
if (this.packageInfo?.aiKey) {
|
||||
this._reporter = new VsCodeTelemetryReporter(
|
||||
this.packageInfo.name,
|
||||
this.packageInfo.version,
|
||||
|
||||
Reference in New Issue
Block a user