MCPcopy Create free account
hub / github.com/chhoumann/quickadd / suggestForFile

Method suggestForFile

src/formatters/completeFormatter.ts:904–1022  ·  view source on GitHub ↗
(parsed: ParsedFileToken)

Source from the content-addressed store, hash-verified

902 }
903
904 protected async suggestForFile(parsed: ParsedFileToken): Promise<string | string[]> {
905 this.assertInteractivePrompt(
906 `{{FILE}} (pick a file from ${parsed.folderPath})`,
907 );
908 // Route the final picker to a remote interactive session (Raycast) when one
909 // is driving; the vault-side file filtering below still runs unchanged.
910 const provider = this.choiceExecutor?.promptProvider;
911 try {
912 const files = EnhancedFieldSuggestionFileFilter.filterFiles(
913 this.app.vault.getMarkdownFiles(),
914 parsed.filter,
915 (file) => this.app.metadataCache.getFileCache(file),
916 );
917
918 const placeholder =
919 parsed.label ?? `Select a file from ${parsed.folderPath}`;
920
921 // Empty folder (or no match): fall back to free-text so a capture never
922 // dead-ends, mirroring suggestForField. A typed value is stored as custom
923 // (never resolved to a real file); an empty/skip stays "".
924 if (files.length === 0) {
925 const description = `No markdown files found in "${parsed.folderPath}". Type a value or leave empty.`;
926 const typed = provider
927 ? await provider.inputPrompt(placeholder, description)
928 : await GenericInputPrompt.Prompt(
929 this.app,
930 placeholder,
931 description,
932 undefined,
933 undefined,
934 parsed.optional ? { optional: true } : undefined,
935 );
936 if (parsed.multiSelect) {
937 return typed ? [`${FILE_CUSTOM_PREFIX}${typed}`] : [];
938 }
939 return typed ? `${FILE_CUSTOM_PREFIX}${typed}` : "";
940 }
941
942 const displayItems = buildFileDisplayLabels(
943 files,
944 (file) => this.app.metadataCache.getFileCache(file),
945 );
946 const items = files.map((file) => `${FILE_PICK_PREFIX}${file.path}`);
947
948 if (parsed.multiSelect) {
949 const result = provider
950 ? await provider.suggesterMulti(displayItems, items, {
951 placeholder,
952 allowCustomInput: parsed.allowCustomInput,
953 })
954 : await MultiSuggester.Suggest(this.app, displayItems, items, {
955 placeholder,
956 allowCustomValue: parsed.allowCustomInput,
957 ...(parsed.optional ? { skippable: true } : {}),
958 });
959 return result.map((item) =>
960 items.includes(item) ? item : `${FILE_CUSTOM_PREFIX}${item}`,
961 );

Callers

nothing calls this directly

Calls 9

buildFileDisplayLabelsFunction · 0.90
isCancellationErrorFunction · 0.90
inputPromptMethod · 0.65
suggesterMultiMethod · 0.65
suggesterMethod · 0.65
filterFilesMethod · 0.45
PromptMethod · 0.45
SuggestMethod · 0.45

Tested by

no test coverage detected