Skip to content
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

Add user-defined prefixes to custom label reference and definition commands #1138

Open
DasNaCl opened this issue Jun 5, 2024 · 1 comment

Comments

@DasNaCl
Copy link
Contributor

DasNaCl commented Jun 5, 2024

Thanks for texlab, I've been enjoying it a lot!

At the moment, there exist experimental options for custom label commands.
In my work, the diagnostics for these extended labels are basically useless, since I have macros that wrap the actual label and prepend a certain prefix to it.
For example:

\newcommand{\asm}[2]{\item\label[asm]{asm:#1} {#2}}
\newcommand{\goal}[2]{\item\label[goal]{goal:#1} {#2}}
\newcommand{\asmref}[1]{\Cref{asm:#1}}
\newcommand{\goalref}[1]{\Cref{goal:#1}}

I propose to add another option to the server that allows a mapping from custom label commands to a prefix, which would be considered when checking for duplicate or unused references.

To this end, I've started to work on this by extending crates/parser/src/config.rs appropriately. But, it appears that the planned change is a little more fundamental than anticipated, because base_db::semantics::tex::Label or ...::LabelKind do not appear to carry information about the actual command. If I'm not mistaken, that information is dropped in the lexer, replacing the read token (e.g., \asm) with just CommandName::LabelDefinition (see here).
Since the changes do not appear to be as easy as I thought, I'd like to discuss with you if (1) this is a reasonable (experimental) feature to add, (2) the plan on how to support this aligns with the general style and structure of the project, and (3) my analysis of the code base regarding the difficulty to implement this is on point or not.

@DasNaCl
Copy link
Contributor Author

DasNaCl commented Jun 10, 2024

It'd be incredible if there is a somewhat less ad-hoc solution to custom prefixes, i.e., texlab identifying custom label commands automatically and adding them automagically, simply because one of the documents contains e.g. \newcommand{\asm}[1]{\label{asm:#1}}.
Of course, something like this would be dramatically more complicated and the question is if such complication justifies this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant