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

LSP features don't work when rust source file is opened from more than one level outside of the project directory #2970

Closed
SaphiraKai opened this issue Jul 5, 2022 · 7 comments
Labels
A-helix-term Area: Helix term improvements A-language-server Area: Language server client C-bug Category: This is a bug

Comments

@SaphiraKai
Copy link

SaphiraKai commented Jul 5, 2022

Summary

When opening a Rust source file with a file path either one level outside of the project directory or anywhere inside the directory, these features work perfectly. However, using a path more than one layer outside of the project directory, either on the commandline or in the editor, the 'goto definition' and 'show documentation' features and likely others do not work. Most simply do nothing, but 'goto definition' returns the error 'No definition found.'.

Reproduction Steps

Assume the following directory layout:

/
└─home/
  └─saphira/
    └─src/
      └─SaphiraKai/
        └─libaether/ # cargo created project dir
          └─src/
            └─lib.rs

This works:
~/src/SaphiraKai$ hx libaether/src/lib.rs

I am fully able to use features such as <space>k.
However, moving up a single directory layer breaks.

This does not work:
~/src$ hx SaphiraKai/libaether/src/lib.rs

Attempting to use <space>k and other LSP features simply do nothing, or yield an error.

I've also tried various other directory structure layouts, including this:

/
└─home/
  └─saphira/
    └─rd/ # ramdisk
      └─libaether/ # same directory copied
        └─src/
          └─lib.rs

This works:
~/rd$ hx libaether/src/lib.rs

This does not work:
~$ hx rd/libaether/src/lib.rs

Helix log

I managed to get the output from opening a broken session, attempting to use <space>k, and then closing the session:

~/.cache/helix/helix.log
2022-07-05T01:24:31.912 helix_lsp::transport [ERROR] err <- "[ERROR rust_analyzer] failed to find any projects in [AbsPathBuf(\"/home/saphira\")]\n"
2022-07-05T01:24:31.913 helix_lsp::transport [ERROR] err <- "[ERROR rust_analyzer::lsp_utils] rust-analyzer failed to discover workspace\n"
2022-07-05T01:24:31.913 helix_term::application [WARN] unhandled window/showMessage: ShowMessageParams { typ: Error, message: "rust-analyzer failed to discover workspace" }
2022-07-05T01:24:37.087 helix_lsp::transport [ERROR] err: <- StreamClosed
2022-07-05T01:24:37.087 helix_lsp::transport [ERROR] err: <- StreamClosed

Platform

Linux

Terminal Emulator

st-instantos (the instantOS fork of suckless terminal)

Helix Version

helix 22.05

@SaphiraKai SaphiraKai added the C-bug Category: This is a bug label Jul 5, 2022
@SaphiraKai SaphiraKai changed the title LSP features don't work when file is opened via absolute path LSP features don't work when rust source file is opened from more than one level outside of the project directory Jul 5, 2022
@SaphiraKai
Copy link
Author

I've updated this issue several times, after discovering new information. After reading the log output I eventually managed to catch, I believe the error is caused by passing the current directory to the language server, instead of the path to the file. I will attempt to fix this error, and if I'm successful I'll make a PR.

@SaphiraKai
Copy link
Author

Update on the attempted PR, it's now past 2am my time and I was completely unfamiliar with the codebase to start with, lol. I'll continue tomorrow, but so far I have confirmed that the issue occurs when send_payload_to_server() is used to initialize the server with the current directory, instead of the path to the opened file. I have yet to find the exact call that's responsible though.

@uncomfyhalomacro
Copy link
Contributor

I've updated this issue several times, after discovering new information. After reading the log output I eventually managed to catch, I believe the error is caused by passing the current directory to the language server, instead of the path to the file. I will attempt to fix this error, and if I'm successful I'll make a PR.

It actually happens not just in rust-analyzer. I was thinking that roots in languages.toml recursively goes above the path of the file to search for the file that implies the root directory of the project e.g. Cargo.toml, Cargo.lock. I was thinking of opening an issue about this as well but I don't have a lot of time in my hands.

@uncomfyhalomacro
Copy link
Contributor

uncomfyhalomacro commented Jul 5, 2022

Parts of the code base that I think passes the current_directory should be in
https://github.com/helix-editor/helix/blob/f10b6f6ee2bbf4d6d9356e27be25b25bdb85b9cd/helix-term/src/args.rs
or more likely here

fn location_to_file_location(location: &lsp::Location) -> FileLocation {
let path = location.uri.to_file_path().unwrap();
let line = Some((
location.range.start.line as usize,
location.range.end.line as usize,
));
(path, line)
}
- just a guess since I am not familiar with helix too

@kirawi kirawi added A-language-server Area: Language server client A-helix-term Area: Helix term improvements labels Jul 5, 2022
@SaphiraKai
Copy link
Author

Alright I never got around to working on it today unfortunately. I've discovered the the LSP features seem to be extremely picky and will break unless I open my projects a very specific way...

It also completely breaks if I try and use a helper script for reasons I can't begin to comprehend given that the situation should be exactly the same.. I'll get around to figuring it out eventually, I'm tired

@ath3
Copy link
Contributor

ath3 commented Oct 1, 2022

#3553

@the-mikedavis
Copy link
Member

Fixed in #3553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements A-language-server Area: Language server client C-bug Category: This is a bug
Projects
None yet
Development

No branches or pull requests

5 participants