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