James-Yu / LaTeX-Workshop

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
MIT License
10.64k stars 532 forks source link

Autocomplete for commands created with \def #4421

Closed jharbig closed 1 week ago

jharbig commented 1 week ago

Please fill the following fields with a star (*) and provide as much related information as possible.

Pre-checks*

Please change the following [ ] to [x] for confirmation.

  • [x] The feature request has not been suggested in this repository.

The Missed*

Is your feature request related to a problem? Please provide a clear and concise description of what the problem is.

When you create commands with \def there are no autocompletion suggestions.

I created the following minimal example to demonstrate this:

\documentclass{article}

\newcommand{\autocompletedCommand}{Autocomplete works for this command}
\def\notAutocompleted{This command will not be auto completed}

\begin{document}

\autocompletedCommand
\notAutocompleted
\notAutocompleted{}
\notAutocompleted{}{}

Autocomplete not even works after a few usages
\notAutocompl

\end{document}

As you can see in the following image, there are no suggestions.

image

The Solution*

Please provide a solution you would like to have.

It would be nice to have autocompletion similar to commands created with newcommand.

image

I also suggest including the non-letter character after the command in the suggestion because LaTeX requires this character in the usage (e.g. \def\myCommand/{something} can only be used `\myCommand/). So, in effect, this character is part of the command (more details below).

If it is complicated to include a command from \def, it would be helpful when the autocompletion suggests commands that were used before.

Anything Else?

Add any other context about the feature request below.

I considered refactoring all my commands from \def to \newcommand. Unfortunately, there is a different behavior, especially with a space after a command. I usually define commands with a slash afterward (e.g., \def\myCommand/{something} such that you do not forget to add a space after a command. See https://tex.stackexchange.com/questions/31091/space-after-latex-commands or page 204 of "The TEXbook" for more info on that behavior/problem.

James-Yu commented 1 week ago

The extension does not parse \def. You may consider report the issue to unified-latex as this extension relies on that package to parse LaTeX.

Generally, \def is anti-pattern.

Further, we won't parse randomly appeared macros in the document, as it can be to convolute to parse its argument signature.