MCPcopy
hub / github.com/callumalpass/tasknotes / getFileSuggestions

Function getFileSuggestions

src/editor/NLPCodeMirrorAutocomplete.ts:305–401  ·  view source on GitHub ↗

* Get file-based suggestions (projects or user fields with autosuggest)

(
	propertyId: string,
	query: string,
	plugin: TaskNotesPlugin,
	triggerConfig: TriggerConfigService
)

Source from the content-addressed store, hash-verified

303 * Get file-based suggestions (projects or user fields with autosuggest)
304 */
305async function getFileSuggestions(
306 propertyId: string,
307 query: string,
308 plugin: TaskNotesPlugin,
309 triggerConfig: TriggerConfigService
310): Promise<Completion[]> {
311 try {
312 // Get autosuggest config - use projectAutosuggest for projects,
313 // or user field's autosuggestFilter for user fields
314 let autosuggestConfig;
315 if (propertyId === "projects") {
316 autosuggestConfig = plugin.settings.projectAutosuggest;
317 } else {
318 const userField = triggerConfig.getUserField(propertyId);
319 autosuggestConfig = userField?.autosuggestFilter;
320 }
321
322 const list = await FileSuggestHelper.suggest(plugin, query, 20, autosuggestConfig);
323
324 // For projects, add rich metadata rendering
325 if (propertyId === "projects") {
326 const resolver = new ProjectMetadataResolver({
327 getFrontmatter: (entry) => entry.frontmatter,
328 });
329 const rowConfigs = (plugin.settings?.projectAutosuggest?.rows ?? []).slice(0, 3);
330
331 return list.map((item) => {
332 const displayText = item.displayText || item.insertText;
333 const insertText = item.insertText;
334
335 // Get file metadata for rendering
336 const file = plugin.app.vault
337 .getMarkdownFiles()
338 .find((f) => f.path === item.path);
339
340 // Build metadata rows using shared utility
341 let metadataRows: ProjectCompletionMetadata = [];
342 if (file && rowConfigs.length > 0) {
343 const cache = plugin.app.metadataCache.getFileCache(file);
344 const frontmatter: Record<string, unknown> = cache?.frontmatter || {};
345 const mapped = plugin.fieldMapper.mapFromFrontmatter(
346 frontmatter,
347 file.path,
348 plugin.settings.storeTitleInFilename
349 );
350
351 const title = typeof mapped.title === "string" ? mapped.title : "";
352 const aliases = Array.isArray(frontmatter["aliases"])
353 ? frontmatter["aliases"].filter((a: unknown) => typeof a === "string")
354 : [];
355
356 const fileData: ProjectEntry = {
357 basename: file.basename,
358 name: file.name,
359 path: file.path,
360 parent: file.parent?.path || "",
361 title,
362 aliases,

Callers 1

Calls 6

buildProjectMetadataRowsFunction · 0.85
getUserFieldMethod · 0.80
getMarkdownFilesMethod · 0.80
getFileCacheMethod · 0.80
mapFromFrontmatterMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected