Change Runnable.bin -> Runnable.kind

As per matklad, we now pass the responsibility for finding the binary to the frontend.
Also, added caching for finding the binary path to reduce
the amount of filesystem interactions.
This commit is contained in:
veetaha 2020-05-31 05:13:08 +03:00
parent a419cedb1c
commit d605ec9c32
13 changed files with 133 additions and 93 deletions

View file

@ -99,3 +99,21 @@ export function isValidExecutable(path: string): boolean {
export function setContextValue(key: string, value: any): Thenable<void> {
return vscode.commands.executeCommand('setContext', key, value);
}
/**
* Returns a higher-order function that caches the results of invoking the
* underlying function.
*/
export function memoize<Ret, TThis, Param extends string>(func: (this: TThis, arg: Param) => Ret) {
const cache = new Map<string, Ret>();
return function(this: TThis, arg: Param) {
const cached = cache.get(arg);
if (cached) return cached;
const result = func.call(this, arg);
cache.set(arg, result);
return result;
};
}