Add autocompletion for wiki links

This commit is contained in:
2025-11-11 21:56:18 +01:00
parent 0579b8d0e5
commit 2e7bd88a57
13 changed files with 538 additions and 107 deletions

View File

@@ -240,17 +240,13 @@ export function remarkWikiLinks(workspaceName: string) {
continue;
}
const lookupFileName: string = match.isImage
? match.fileName
: addMarkdownExtension(match.fileName);
// If the filename contains a path separator, treat it as a full path
// This handles wikilinks with paths like [[folder/subfolder/file]]
let filePath: string;
if (match.fileName.includes('/')) {
// It's already a full path - use it directly
filePath = match.isImage ? match.fileName : addMarkdownExtension(match.fileName);
const paths: string[] = await lookupFileByName(
workspaceName,
lookupFileName
);
if (paths && paths.length > 0 && paths[0]) {
const filePath: string = paths[0];
if (match.isImage) {
newNodes.push(
createImageNode(workspaceName, filePath, match.displayText)
@@ -266,9 +262,37 @@ export function remarkWikiLinks(workspaceName: string) {
);
}
} else {
newNodes.push(
createNotFoundLink(match.fileName, match.displayText, baseUrl)
// It's just a filename - look it up to find the full path
const lookupFileName: string = match.isImage
? match.fileName
: addMarkdownExtension(match.fileName);
const paths: string[] = await lookupFileByName(
workspaceName,
lookupFileName
);
if (paths && paths.length > 0 && paths[0]) {
filePath = paths[0];
if (match.isImage) {
newNodes.push(
createImageNode(workspaceName, filePath, match.displayText)
);
} else {
newNodes.push(
createFileLink(
filePath,
match.displayText,
match.heading,
baseUrl
)
);
}
} else {
newNodes.push(
createNotFoundLink(match.fileName, match.displayText, baseUrl)
);
}
}
} catch (error) {
console.debug('File lookup failed:', match.fileName, error);