latex-lsp / texlab

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

Undefined reference #923

Open yashamon opened 1 year ago

yashamon commented 1 year ago

This issue appeared recently. Probably last release. All citations are now marked undefined reference. The location of bib is standard: ~/texmf/bibtex/bib The document compiles without issues with all references intact.

Platform: Win11 release, neovim 9.1

pfoerster commented 12 months ago

@yashamon Thanks for the report! Does kpsewhich find the bibliography and does texlab (check if texlab reports a document link for the \bibliography/\addbibresource command)? As a test, can you try adding the directory to the BIBINPUTS environment variable, please?

firubat commented 11 months ago

@pfoerster This bug happens to me too. Neovim 0.9.2 on linux mint. kpsewhich finds the bibliography. Can you explain how to do the check in texlab?

yashamon commented 11 months ago

I thought I also replied. In my case kpsewhich also finds the bib file. We are only using the LSP server so I am not sure how to troubleshoot further.

pfoerster commented 11 months ago

@yashamon @firubat Can you try triggering a "goto definition" on the \addbibresource or \bibliography command? If it does not open the file, then the server does not find the file.

Can you also try the BIBINPUTS test, please (note that you cannot use ~ inside the variable)?

As a test, can you try adding the directory to the BIBINPUTS environment variable, please?

firubat commented 11 months ago

@pfoerster So seems that if the bib file is in the same folder as the tex file, it is recognized by texlab. But if the bib file is in a different folder in the BIBINPUTS path (which is the way I like to do it), it is not recognized (the goto definition won't open the file in this case).

yashamon commented 11 months ago

Same for me, the issue goes away if the bib file is local.

On Sat, Sep 23, 2023 at 11:25 AM firubat @.***> wrote:

@pfoerster https://github.com/pfoerster So seems that if the bib file is in the same folder as the tex file, it is recognized by texlab. But if the bib file is in a different folder in the BIBINPUTS path (which is the way I like to do it), it is not recognized (the goto definition won't open the file in this case).

— Reply to this email directly, view it on GitHub https://github.com/latex-lsp/texlab/issues/923#issuecomment-1732370010, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQGIZSYUOFMZNBXNA6H44LX34LSBANCNFSM6AAAAAA4KYRURI . You are receiving this because you were mentioned.Message ID: @.***>

pfoerster commented 11 months ago

@yashamon @firubat Can you try b2a49d0bfc5bde1d56c26fa8afdf55c5fe5c34cb, please? With this changeset, the server should be able to find the bibliography.

naibaf0 commented 11 months ago

I have the same error even if the actual scenario seems different and just tried the new commit. It does find a bibliography file in the tex distribution and uses it now, however even in the case where a local file with the same name is present.

in my case I do have a local file bibliography.bib in my project which should be used and when running with this patch, goto definition (of the bibliography) will now offer to go to /usr/share/doc/texlive/bibtex/newcastle-bst/bibliography.bib in addition to my local file. It also offers autocompletion for citations from both files.

So I am guessing there is still some logic missing to prefer a local file over the one from the tex distribution tree.

firubat commented 11 months ago

Can you try b2a49d0, please?

I must admit that I don't know how to do that, I'm using texlab in neovim via Mason, and I don't know how to tell it to use a specific commit which is outside the releases cycle...

naibaf0 commented 11 months ago

@firubat for me mason saves the binary for texlab in ~/.local/share/nvim/mason/packages/texlab. I think that is the default, but not completely sure. If you build texlab on the the specified commit locally, you can copy the newly built binary into the location where mason saves it and it will be used in neovim.

pfoerster commented 11 months ago

@naibaf0 Thanks for trying out the commit.

So I am guessing there is still some logic missing to prefer a local file over the one from the tex distribution tree.

This should be fixed now. I will publish a new release soon.

firubat commented 10 months ago

Hi @pfoerster , for some reason this is still an issue for me (current version 5.11.0)

yashamon commented 10 months ago

Is it already in the release version?

I have no way to compile commits, well I would prefer not to.

On Wed, Nov 8, 2023 at 2:54 PM firubat @.***> wrote:

Hi @pfoerster https://github.com/pfoerster , for some reason this is still an issue for me (current version 5.11.0)

— Reply to this email directly, view it on GitHub https://github.com/latex-lsp/texlab/issues/923#issuecomment-1802659967, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQGIZRPF7WICVFTJOUWXO3YDPWR5AVCNFSM6AAAAAA4KYRURKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBSGY2TSOJWG4 . You are receiving this because you were mentioned.Message ID: @.***>

pfoerster commented 10 months ago

@yashamon

Is it already in the release version?

Yes, this changeset is included with v5.9.0.

@firubat Is the missing bibliography contained in your home directory?

yashamon commented 10 months ago

In that case I am still experiencing the issue. My bib is in the supposedly standard global directory. If bib file is moved to local directory the issue goes away.

On Sun, Nov 12, 2023 at 6:53 AM Patrick Förster @.***> wrote:

@yashamon https://github.com/yashamon

Is it already in the release version?

Yes, this changeset is included with v5.9.0 https://github.com/latex-lsp/texlab/blob/master/CHANGELOG.md#590---2023-08-06 .

@firubat https://github.com/firubat Is the missing bibliography contained in your home directory?

— Reply to this email directly, view it on GitHub https://github.com/latex-lsp/texlab/issues/923#issuecomment-1807119183, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQGIZXOFDCY5BRKF5UTJZLYEDBGBAVCNFSM6AAAAAA4KYRURKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBXGEYTSMJYGM . You are receiving this because you were mentioned.Message ID: @.***>

firubat commented 10 months ago

@pfoerster It's in ~/Dropbox. Which I manually added to the BIBINPUTS variable

firubat commented 10 months ago

I tried to put it also in /usr/share/texmf and /usr/local/share/texmf but to no avail. Only if it's in the same directory as the tex file.

Zeta611 commented 9 months ago

I have this issue when there are (at least) Korean characters in the path.

I have a .bib file in a local directory where the .tex file lives in. If the directory contains Korean characters, the LSP shows Undefined reference error, but when I move the directory to a path without Korean characters, the error goes away.

This probably means the directory is not properly handled for CJK characters.

andrasbarany commented 6 months ago

I am also having this issue with version 5.12.3 in both nvim and nvim-qt. If I copy or link the bibliography file to the local directory, the error disappears. BIBINPUTS is set to the folder containing the .bib file but is apparently ignored.

I'm using my distribution's texlab binary, but changing to the one installed using :LspInstall in nvim doesn't help either.

Here's the output of :LspInfo

 Press q or <Esc> to close this window. Press <Tab> to view server doc.

 Language client log: /home/ba/.local/state/nvim/lsp.log
 Detected filetype:   tex

 1 client(s) attached to this buffer: 

 Client: texlab (id: 1, bufnr: [1])
    filetypes:       tex, plaintex, bib
    autostart:       true
    root directory:  /home/ba
    cmd:             /usr/bin/texlab

 Configured servers list: texlab, marksman
luavreis commented 4 months ago

Perhaps it's related to the tilde expansion?

\addbibresource{~/Zotero/bibs/all.bib}

wasn't working for me, but

\addbibresource{/home/lucas/Zotero/bibs/all.bib}

does.

yashamon commented 4 months ago

I think we are all using absolute paths.

On Sat, Apr 13, 2024, 03:28 Lucas @.***> wrote:

Perhaps it's related to the tilde expansion?

\addbibresource{~/Zotero/bibs/all.bib}

wasn't working for me, but

\addbibresource{/home/lucas/Zotero/bibs/all.bib}

does.

— Reply to this email directly, view it on GitHub https://github.com/latex-lsp/texlab/issues/923#issuecomment-2053556737, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQGIZUJ4MH7VJVAS477VRTY5DNDDAVCNFSM6AAAAAA4KYRURKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJTGU2TMNZTG4 . You are receiving this because you were mentioned.Message ID: @.***>

juntuu commented 2 months ago

tl;dr Percent encoding in paths may have different casing of hex characters (a-f or A-F), which leads to mismatches later.


I have this issue when there are (at least) Korean characters in the path.

I have a .bib file in a local directory where the .tex file lives in. If the directory contains Korean characters, the LSP shows Undefined reference error, but when I move the directory to a path without Korean characters, the error goes away.

This probably means the directory is not properly handled for CJK characters.

I also noticed this issue with some characters in the path. (using neovim as the LSP client)

I did some investigation and found out that (at least part of) the cause was the percent encoding of URIs.

The LSP messages from the client contain URIs, which were percent encoded with lowercase hex. However, the URI for loaded file is constructed from a Rust Path, see: https://github.com/latex-lsp/texlab/blob/3d70feb03dc7d2cd9e11a80f5a766ec84699dbd7/crates/base-db/src/workspace.rs#L95

That from_file_path method uses uppercase hex for percent encoding, which causes the URIs to not match later.

Another place where the bibliography path is constructed is: https://github.com/latex-lsp/texlab/blob/3d70feb03dc7d2cd9e11a80f5a766ec84699dbd7/crates/base-db/src/deps/graph.rs#L162

This joins the relative path with the directory component, which may come from the LSP client. Thus the joined path may have different casing for the hex in percent encoding, depending on the LSP client.

I think the first is loading the bib file as part of the workspace, and the latter is resolving the path given to addbibresource command. So the two URIs for the same file may end up being different.

(Relative paths seem to work, when the encoded part is within it) After this I also noticed that traversing back the encoded parts of the path "worked" again. (Which kind of makes sense.) Under path `/home/me/ä/`, where `ä` will be encoded. Doesn't work ```tex \addbibresource{references.bib} \cite{test} ``` "Works" ```tex \addbibresource{../ä/references.bib} \cite{test} ```

Solutions?

I'm not familiar with the project or the code, so can't say what would make sense.

Could that be part of normalize_uri? https://github.com/latex-lsp/texlab/blob/3d70feb03dc7d2cd9e11a80f5a766ec84699dbd7/crates/texlab/src/util.rs#L9

pfoerster commented 2 months ago

@juntuu Thanks for digging into this. I have created #1148, which extends normalize_uri.