-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial work towards prefixes for custom label commands. #1139
Conversation
This commit mainly extends the configs with a map from label command name to the respective prefix. It does not yet implement any functionality, since it appears that `base-db/semantics/label` needs an extension carrying a span that contains the label command. The plan is to extend the logic in `crates/diagnostics/src/labels.rs`.
Thanks for working on this!
Sure, this sounds reasonable. Adding this would also help supporting the
I think there are 2 ways to implement this:
\newcommand{\asm}[2]{\item\label[asm]{asm:#1} {#2}}
\newcommand{\asmref}[1]{\Cref{asm:#1}}
% semantics module will store a label `asm:foo` internally
\asm{foo}
% Goto definition return `\asm{foo}`
\ref{asm:foo} One notable change would be that Special care would be needed completing commands like |
This commit prepends user-defined prefixes to labels in the semantics pass. Note that this yields to a mismatch between the actual length of a span and its range, but there are no (anticipated) bad side-effects due to this.
Adds two tests that ensure completion for custom labels with custom prefix works as expected. The `\ref` command should list the prefix, while a custom reference command with a configured prefix should not.
I decided to go with the second option, but now that I want to get completion up to speed, it looks like the first option may be necessary. The issue is that, without @pfoerster Maybe you have another idea? :-) |
The suggestions should only contain those that are starting with a prefix, if such a prefix has been defined.
Suggestions for completion can be filtered already by checking the prefixes of known labels and wether they match the custom reference prefix of the respective reference command.
@pfoerster Thank you for the quick look! Indeed, this was one of many other typos I identified in the added tests. I've shrunken the tests a bit down and removed some unnecessary TeX around it. Here is a minimal working example of a document using custom definition and reference commands with custom prefixes: \documentclass{article}
\newcommand{\asm}[2]{\item\label[asm]{asm:#1} {#2}}
\newcommand{\asmref}[1]{\ref{asm:#1}}
\newcommand{\goal}[2]{\item\label[goal]{goal:#1} {#2}}
\newcommand{\goalref}[1]{\ref{goal:#1}}
\begin{document}
\begin{enumerate}\label{baz}
\asm{foo}{what}
\goal{bar}{what}
\end{enumerate}
\asmref{} % suggests "foo"
\goalref{} % suggests "bar"
\ref{} % suggests "baz", "asm:foo", and "goal:bar"
\end{document} To make this work in my editor, I've configured
The pull request seems to be feature complete now, for what I can tell. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @DasNaCl, the completion works nicely!
While testing, I found one issue with the rename
request.
In your example, if you rename \ref{asm:foo}
to asm:bar
. Then, \asmref{foo}
will be renamed to \asmref{asm:bar}
.
Haaa, of course, makes sense that stuff like this breaks. Forgot about that! I just checked other functions, like getting a list of all references or going to a definition, but those appear to work even with just
I looked into this today and saw that this also necessitates an extension of another "includes"-kind, similar to how subfiles work. |
Well, in this case, the list of tuples is better suited so I suggest we stick with tuples even if we just support one prefix for now.
Previously, the rename code used to record a
Probably, there is no way around extending |
This commit implements key functionality for renaming labels with prefixes. A sane assumption it does is that all labels found as candidate for renaming share a common prefix, up to looking it up first and prepending it, e.g., for `\goal{foo}`. Instead of storing a renaming candidate for each entry, it only keeps track of the prefixes and prepends them accordingly, depending on the renaming candidate, by swapping the `TextRange` with `RenameInformation` inside the `RenameResult`. Unfortunately, this pollutes a bit the other renaming ops, such as commands or citations, which don't have prefixes. Nevertheless, changes there have been incremental and `RenameInformation` implements a `From<TextRange>` to easily map an existing `TextRange` into it, simply assuming an empty prefix. In terms of tests, the `prefix` should be ignored.
0d065c9 realizes the desired feature. I've also added some tests for renaming with prefixes. (not sure how valuable they are, though, since it doesn't seem they check for what is actually being replaced, but just matching the text positions) In some hand-made tests on some small and big TeX files in my personal collection, the feature appears to work for any combination of @pfoerster Let me know if you identify additional issues and thank you for your ongoing support.
I rolled back now in 3b4d1d0 to the |
Thank you for the update!
While testing, I found one remaining issue (although this is a rare case): When renaming, The rest works just fine :) |
@pfoerster sorry, I cannot reproduce and from what I can reproduce, I see no issues... See an attempt in action: The way it's implemented is that it 'intelligently' identifies whether a label has an associated prefix and prepends it accordingly when doing the renaming. -> There is no need to write Thank you again for taking time to look at this! |
Yeah, allowing the user to write
Thank you for contributing! |
This commit mainly extends the configs with a map from label command name to the respective prefix, as outlined in #1138.
It does not yet implement any functionality, since it appears that
base-db/semantics/label
needs an extension carrying a span that contains the label command.The plan is to extend the logic in
crates/diagnostics/src/labels.rs
.For discussion on this, as outlined in CONTRIBUTING.md, please refer to the accompanying issue.