Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cross-ref between different markdown files. #37

Open
pykong opened this issue Apr 2, 2023 · 1 comment
Open

Cross-ref between different markdown files. #37

pykong opened this issue Apr 2, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@pykong
Copy link

pykong commented Apr 2, 2023

I am using pandoc-include to break an otherwise big monolithic file into one root file including a set of smaller files.

This breaks however the autocompletion of cross-ref assets such as figures and listings.
(Citeproc citations still wotk throughout all files though, if PandocCiter.RootFile is set.)

I wished PandocCiter would account for such circumstance and still resolve cross-refs across file boundaries.

EDIT
To be clearer: All references (for tables, figures, listings, sections, etc. ...) as defined via cross-ref syntax in any markdown file should be resolved by PandocCiter in any other markdown file within the same project directory.

@notZaki thanks for this extremely helpful plugin!

@jkittner
Copy link

I think I was able to implement this:

The only requirement is, that the file has to be open in one tab. But that's still a lot more convenient than no auto complete at all. I know and use a similar feature when writing SQL (opening the DB definition in one tab, having autocomplete for tables and columns for all other tabs!)

autocomplete_across_files

I have never written any typescript before, but if you think that's okay, I'm happy to send this as a PR @notZaki.

diff --git a/src/providers/completion.ts b/src/providers/completion.ts
index 56d1375..54e8e01 100644
--- a/src/providers/completion.ts
+++ b/src/providers/completion.ts
@@ -46,9 +46,15 @@ export class Completer implements vscode.CompletionItemProvider {
         // This was used to terminate unecessary autompletion early, but might be causing suggestions to not appear for some users
         // const invoker = document.lineAt(position.line).text[position.character-1];
         // if (invoker !== '@') {return;}
+        const markdownDocuments = vscode.workspace.textDocuments.filter(
+            (document) => ['markdown', 'rmd', 'pweave_md'].includes(document.languageId)
+        );
         const line = document.lineAt(position.line).text.substring(0, position.character).trim().split(" ");
         const trigger = line[line.length-1];
-        const suggestions = this.completion(trigger).concat(this.completionCrossref(trigger, document));
+        let suggestions: vscode.CompletionItem[] = [];
+        markdownDocuments.forEach(doc => {
+            suggestions.push(...this.completion(trigger).concat(this.completionCrossref(trigger, doc)))
+        })
         this.extension.log(`Showing ${suggestions.length} suggestions`);
         if (suggestions.length > 0) {
             const configuration = vscode.workspace.getConfiguration('PandocCiter');

@pykong, just apply this patch and build it yourself for now if you still need it

@notZaki notZaki added the enhancement New feature or request label Jan 10, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants