Skip to content

Commit 58f5ae3

Browse files
committed
Fix linter errors.
1 parent f487c9b commit 58f5ae3

File tree

3 files changed

+49
-33
lines changed

3 files changed

+49
-33
lines changed

Extension/src/Debugger/lldb-dap-worker.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,16 @@ export async function findLldbDapImpl() {
226226

227227
// Only run one search at a time, so if we are already searching, return that.
228228
searching = new ManualPromise<string | undefined>();
229-
searchForLldbDap().then(result => {
230-
searching!.resolve(result);
231-
searching = undefined;
229+
searchForLldbDap().then((result: string | undefined): void => {
230+
if (searching) {
231+
searching.resolve(result);
232+
searching = undefined;
233+
}
234+
}).catch(error => {
235+
if (searching) {
236+
searching.reject(error);
237+
searching = undefined;
238+
}
232239
});
233240
return searching;
234241
}

Extension/src/Utility/Remoting/snare.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,25 +178,29 @@ export function startRemoting(connection: Worker | MessagePort, endpoint: Endpoi
178178
let result: ManualPromise<any> | undefined;
179179
let payload: Payload | undefined;
180180
try {
181-
182-
ready ? ready = await ready : undefined;
183-
181+
if (ready) {
182+
await ready;
183+
}
184184
result = new ManualPromise<any>();
185185
payload = { operation, parameters: sanitizeParameters(parameters), sequence: ++next };
186186
results.set(payload.sequence, result);
187187

188188
connection.postMessage(payload);
189189
} catch (err) {
190190
// If we can't post the message, then we need to reject the promise.
191-
results.delete(payload!.sequence);
192-
result!.reject(err);
191+
if (payload) {
192+
results.delete(payload.sequence);
193+
}
194+
if (result) {
195+
result.reject(err);
196+
}
193197
}
194198
return result;
195199
},
196200
notify: (operation: string, ...parameters: any[]) => {
197201
try {
198202
if (ready) {
199-
ready.then(() => {
203+
void ready.then(() => {
200204
ready = undefined;
201205
connection.postMessage({ operation, parameters: sanitizeParameters(parameters), sequence: 0 });
202206
});
@@ -295,15 +299,15 @@ function sanitizeParameters(parameters: any[]) {
295299
* @param p The value to check.
296300
* @returns True if the value is a reference object.
297301
*/
298-
function isReference(p: any): p is reference {
302+
function isReference(p: any): p is Reference {
299303
return is.object(p) && 'identity' in p && 'kind' in p;
300304
}
301305

302306
/**
303307
* Interface representing a reference to an object or function in another thread.
304308
* References are used to represent values that cannot be cloned.
305309
*/
306-
interface reference {
310+
interface Reference {
307311
/** Unique identifier for the referenced object. */
308312
identity: number;
309313

@@ -334,23 +338,23 @@ export function getByRef<T = any>(identity: number): T {
334338
* @param instance A Promise resolving to the object to reference.
335339
* @returns A Promise resolving to a reference object, or undefined if the value can't be referenced.
336340
*/
337-
export function ref(instance: Promise<any>): Promise<reference | undefined>;
341+
export function ref(instance: Promise<any>): Promise<Reference | undefined>;
338342

339343
/**
340344
* Creates a reference to an object or function that can be sent to another thread.
341345
*
342346
* @param instance The object to reference.
343347
* @returns A reference object, or undefined if the value can't be referenced.
344348
*/
345-
export function ref(instance: any): reference | undefined;
349+
export function ref(instance: any): Reference | undefined;
346350

347351
/**
348352
* Implementation of the ref function handling both synchronous and asynchronous cases.
349353
*
350354
* @param instance The object or Promise to reference.
351355
* @returns A reference object, a Promise to a reference object, or undefined.
352356
*/
353-
export function ref(instance: any | Promise<any>): reference | undefined | Promise<reference | undefined> {
357+
export function ref(instance: any | Promise<any>): Reference | undefined | Promise<Reference | undefined> {
354358
if (is.promise(instance)) {
355359
return instance.then(ref);
356360
}

Extension/src/common-remote-safe.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ import { is } from './Utility/System/guards';
2727
let remoteConnection: RemoteConnection | undefined;
2828

2929
// In the main thread, grab the logger and localize functions directly.
30-
const logFn = isMainThread ? require('./logger').log : () => { };
31-
const noteFn = isMainThread ? require('./logger').note : () => { };
32-
const localizeFn = isMainThread ? require('./localization').localize : (info: { key: string; comment: string[] } | string, message: string, ...args: (string | number | boolean | undefined | null)[]) => message.replace(/\{(\d+)\}/g, (_, index) => String(args[Number(index)] ?? 'undefined'));
33-
const getOutputChannelLoggerFn = isMainThread ? require('./logger').getOutputChannelLogger : () => undefined;
30+
import { localize as localizationLocalize } from './localization';
31+
import * as logger from './logger';
32+
import { getOutputChannelLogger, note as loggerNote } from './logger';
33+
34+
const logFn = isMainThread ? logger.log : () => { };
35+
const noteFn = isMainThread ? loggerNote : () => { };
36+
const localizeFn = isMainThread ? localizationLocalize : (info: { key: string; comment: string[] } | string, message: string, ...args: (string | number | boolean | undefined | null)[]) => message.replace(/\{(\d+)\}/g, (_, index) => String(args[Number(index)] ?? 'undefined'));
37+
const getOutputChannelLoggerFn = isMainThread ? getOutputChannelLogger : () => undefined;
3438

3539
/**
3640
* Used when this is imported in a module running in a worker thread.
@@ -79,17 +83,17 @@ export function note(message: string | Promise<string>) {
7983
* @param message The message to localize.
8084
* @param args The arguments for the message.
8185
*/
82-
export function localize(info: { key: string; comment: string[] } | string, message: string, ...args: (string | number | boolean | undefined | null)[]): Promise<string> | string {
83-
return isMainThread ?
84-
// main thread uses localize directly
85-
localizeFn(info, message, ...args) :
86-
87-
// worker (non-main) thread requests localization via remote connection
88-
remoteConnection?.request('localize', info, message, ...args) ||
89-
90-
// fallback to simple replacement if no remote connection is available
86+
export const localize: AsyncLocalizeFunc = (infoOrKey, message, ...args) => {
87+
if (isMainThread) {
88+
if (typeof infoOrKey === 'string') {
89+
return localizeFn(infoOrKey, message, ...args);
90+
} else {
91+
return localizeFn(infoOrKey as LocalizeInfo, message, ...args);
92+
}
93+
}
94+
return remoteConnection?.request('localize', infoOrKey, message, ...args) ??
9195
message.replace(/\{(\d+)\}/g, (_, index) => String(args[Number(index)] ?? 'undefined'));
92-
}
96+
};
9397

9498
export function appendLineAtLevel(level: number, message: string | Promise<string>): void {
9599
if (is.promise(message)) {
@@ -168,10 +172,11 @@ export interface LocalizeInfo {
168172
}
169173

170174
/** The type for the localize function for string localization, but can work asynchronously (can be called via remoting). */
171-
export interface AsyncLocalizeFunc {
172-
(info: LocalizeInfo, message: string, ...args: (string | number | boolean | undefined | null)[]): string | Promise<string>;
173-
(key: string, message: string, ...args: (string | number | boolean | undefined | null)[]): string | Promise<string>;
174-
}
175+
export type AsyncLocalizeFunc = (
176+
infoOrKey: LocalizeInfo | string,
177+
message: string,
178+
...args: (string | number | boolean | undefined | null)[]
179+
) => string | Promise<string>;
175180

176181
/**
177182
* A cancellation token is passed to an asynchronous or long running
@@ -436,7 +441,7 @@ export async function searchFolders(folders: string[], filename: string | RegExp
436441

437442
// If it is a file, check for a match.
438443
case stats.isFile():
439-
if (nameMatches(item) && (predicate ? await predicate!(fullPath) : true)) {
444+
if (nameMatches(item) && (predicate ? await predicate(fullPath) : true)) {
440445
return options.result ??= fullPath;
441446
}
442447
break;

0 commit comments

Comments
 (0)