latex-lsp / texlab

An implementation of the Language Server Protocol for LaTeX
GNU General Public License v3.0
1.49k stars 51 forks source link

Bib reference error for subimports #1145

Closed brunotvs closed 1 month ago

brunotvs commented 2 months ago

The LSP displays an ‘undefined reference’ error in files imported with the import package.

brunotvs commented 2 months ago

Actually, I found two behaviors that I consider undesirable:

  1. When I define a new command using import or subimport, TexLab appears to be unable to build the document tree.
\newcommand{\structure}[1]{
    \subimport{#1/}{document.tex}
}
  1. If I subimport file1.tex and, in file1.tex, I input file2.tex, TexLab does not seem to consider file2.tex as part of the same project as file1.tex.
brunotvs commented 2 months ago

Created this repo showing the errors: https://github.com/brunotvs/texlab_issue

pfoerster commented 1 month ago

@brunotvs Currently, this is to be expected because the server does not implement the same logic as the TeX engine so in this case, it does not know that \structure{foo} resolves to \subimport{foo}{document.tex}. There two ways to solve this issue:

  1. Hard-code this case similar to texlab.experimental.labelDefinitionCommands (difficult to draw the line here on what is useful enough to be hard-coded into the server)
  2. Implement a (rudimentary) macro expansion engine in the server (very hard)
brunotvs commented 1 month ago

@pfoerster Okay, but what about nested subimports?

brunotvs commented 1 month ago

@pfoerster, in addition, can the .fls file be utilized?

pfoerster commented 1 month ago

@pfoerster Okay, but what about nested subimports?

If they just use the plain \subimport command, they should work.

@pfoerster, in addition, can the .fls file be utilized?

Sure, #1160 adds a the .fls as an additional source for the project detection. With this changeset, your example will work now after compiling the document once.

brunotvs commented 1 month ago

Sure, https://github.com/latex-lsp/texlab/pull/1160 adds a the .fls as an additional source for the project detection.

Awesome, sounds great.

If they just use the plain \subimport command, they should work.

@pfoerster I found that if I add a latexmkrc file, citation and refs from nested submimports stop working as per this repo

pfoerster commented 1 month ago

@pfoerster I found that if I add a latexmkrc file, citation and refs from nested submimports stop working as per this repo

Thanks for the example. With #1161, your example should work as intended.