Modify example for submenu type context provider in tutorial

This commit is contained in:
Ko Seokyoung 2024-10-19 22:44:12 +09:00
parent 770bc90d54
commit 5dbe56b57b

View file

@ -104,12 +104,21 @@ const ReadMeContextProvider: CustomContextProvider = {
loadSubmenuItems: async (
args: LoadSubmenuItemsArgs,
): Promise<ContextSubmenuItem[]> => {
const { ide } = args;
// Filter all workspace files for READMEs
const allFiles = await args.ide.listWorkspaceContents();
const readmes = allFiles.filter((filepath) =>
filepath.endsWith("README.md"),
const workspaceDirs = await ide.getWorkspaceDirs()
const allFiles = await Promise.all(
workspaceDirs.map(dir => ide.subprocess(`find ${dir} -name "README.md"`)),
);
// 'readmes' now contains an array of file paths for each README.md file found in the workspace,
// excluding those in 'node_modules'
const readmes = allFiles
.flatMap(mds => mds[0].split("\n"))
.filter(file => file.trim() !== '' && !file.includes("/node_modules/"))
// Return the items that will be shown in the dropdown
return readmes.map((filepath) => {
return {