GNOME Bugzilla – Bug 748069
Completion: labels in \ref commands
Last modified: 2018-02-23 16:24:09 UTC
Created attachment 301864 [details] [review] git patch This is an proof of concept for the dynamic completion of the \ref command using labels, for technical review only. FEATURES - Parse documents at load and at save, looking for labels. - When a document is opened, look for other documents inside the same folder, open them in background and parse them. - When editing a file, the completion provider use only labels parsed from files from the same directory. KNOW BUG - When writing after a \ref, the completion provider keep a message saying he can not provide completion IMPROVEMENTS - Don't only parse the same folder in background, but the entire file tree
Please follow the code conventions from the start, instead of writing a commit at the end that fixes the code. Also, all the conventions are not followed, from a quick glance at the patches. Conditions are written like this: if (blah) { } else { } Comments are written like this (note the spaces): // foo /* bar */ Not: //blah Please avoid trailing spaces (at the end of a line). Also, one blank line is enough to separate sections, no need to have several contiguous blank lines.
The feature should be implemented in several (small) steps. Here is a rough plan: 1. Support the completion of placeholders, with a hard-coded list of labels to complete labels. 2. Have a list of labels for an opened .tex file. The structure in the side panel already has the needed information, but there is a problem: the structure must be updated manually by the user with the refresh button, so the list of labels may be outdated. So it's needed to write a class that extracts labels, and that listen to the insert-text and delete-range GtkTextBuffer signals to keep the list updated. So each Document object would contain a DocumentLabels object. Ideally the structure in the side panel should be automatically updated, and would contain the AST, but it's more difficult. Extracting just labels is easier. The code for extracting labels should be in common between the structure and DocumentLabels. This needs several commits to do that incrementally. 3. From the completion provider, retrieve the DocumentLabels. 4. Refactor the code related to projects. I think a Project class would be better. 5. In the Project class, be able to retrieve the list of opened files belonging to the project. 6. From the completion provider, retrieve the current project, and from that retrieve the complete list of labels belonging to the project (but only for files already opened in latexila). 7. In the Project class, scan other files to retrieve the labels of .tex files that are not opened in latexila. This probably needs some refactoring commits to accommodate that. Maybe after doing the first steps you'll see that the next steps are not the best ideas.
For DocumentLabels, this should be done similarly to: https://git.gnome.org/browse/gtksourceview/tree/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c With a GtkTextRegion (private utility class in GtkSourceView). Maybe it's a bit too difficult. Taking the labels from the structure is much simpler.
This would be an incredibly useful feature, especially for large documents with not only a large number of sections and figures, but also equations (in some cases, with labels for each line thereof). I'm afraid I can't offer my own assistance for development (predictably enough due to paper and thesis writing), but I most certainly hope that this feature come back into consideration at some point.
There was a beginning of a solution in bug #722858.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gnome-latex/issues/31.