Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions server/src/find-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,14 @@ async function findRuntimePath(project: string): Promise<string[]> {
return rescriptRuntimeDirs.map((runtime) => resolve(runtime));
}

function findRuntimeCached(): (project: string) => Promise<string[]> {
const cache = new Map<string, string[]>();
return async (project: string) => {
if (cache.has(project)) {
return cache.get(project)!;
}
const runtimes = await findRuntimePath(project);
cache.set(project, runtimes);
return runtimes;
};
}

/**
* Find all installed @rescript/runtime directories in the given project path.
* In a perfect world, there should be exactly one.
* This function is cached per project path.
* Note: This function is not cached here. Caching is handled by the caller
* (see getRuntimePathFromWorkspaceRoot in utils.ts).
*/
export const findRescriptRuntimesInProject = findRuntimeCached();
export async function findRescriptRuntimesInProject(
project: string,
): Promise<string[]> {
return await findRuntimePath(project);
}
1 change: 1 addition & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,7 @@ async function onMessage(msg: p.Message) {
config: config.extensionConfiguration,
projects,
workspaceFolders: Array.from(workspaceFolders),
runtimePathCache: utils.getRuntimePathCacheSnapshot(),
};

let response: p.ResponseMessage = {
Expand Down
8 changes: 8 additions & 0 deletions server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,14 @@ export async function getRuntimePathFromProjectRoot(
return result;
}

/**
* Returns a snapshot of the runtime path cache as a plain object.
* Useful for debugging and state dumps.
*/
export function getRuntimePathCacheSnapshot(): Record<string, string | null> {
return Object.fromEntries(runtimePathCache);
}

export const getNamespaceNameFromConfigFile = (
projDir: p.DocumentUri,
): execResult => {
Expand Down