texlab icon indicating copy to clipboard operation
texlab copied to clipboard

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

Open DasNaCl opened this issue 8 months ago • 1 comments

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 avatar Jun 05 '24 15:06 DasNaCl