-
Notifications
You must be signed in to change notification settings - Fork 68
Rust_Analyzer doesn't provide LSP completion #86
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
Comments
It's a lsp related issue. You might have to add some root markers like rust-project.json |
ok, but what should i add in this file?
|
I think you can't use '*' in your rust-project.json, that's why it wont work for you but take a look at this issue. I yoinked the sh script. Put it in the leetcode folder. Run it after your problem file has been created and it will generate the rust-project.json for you. #!/bin/sh
for f in *.rs; do
crates="${crates}${next}{\"root_module\": \"$f\",\"edition\": \"2021\",\"deps\": []}"
next=","
done
sysroot_src="$(rustc --print sysroot)/lib/rustlib/src/rust/library"
echo "{\"sysroot_src\": \"$sysroot_src\", \"crates\": [$crates]}" | jq '.' >rust-project.json Maybe you can create a job in neovim that does that for you automatically after a problem is loaded + restart the lsp ? (I'll try and look into that later maybe?) |
thanks, it works fine, i just restarted the lsp and work perfectly |
i added this to the kooks part in my config of leetcode:
|
Sorry to necro bump but if you want to do this in pure ["question_enter"] = {
function()
local file_extension = vim.fn.expand("%:e")
if file_extension == "rs" then
local target_dir = vim.fn.stdpath("data") .. "/leetcode"
local output_file = target_dir .. "/rust-project.json"
if vim.fn.isdirectory(target_dir) == 1 then
local crates = ""
local next = ""
local rs_files = vim.fn.globpath(target_dir, "*.rs", false, true)
for _, f in ipairs(rs_files) do
local file_path = f
crates = crates ..
next ..
"{\"root_module\": \"" .. file_path .. "\",\"edition\": \"2021\",\"deps\": []}"
next = ","
end
if crates == "" then
print("No .rs files found in directory: " .. target_dir)
return
end
local sysroot_src = vim.fn.system("rustc --print sysroot"):gsub("\n", "") ..
"/lib/rustlib/src/rust/library"
local json_content = "{\"sysroot_src\": \"" ..
sysroot_src .. "\", \"crates\": [" .. crates .. "]}"
local file = io.open(output_file, "w")
if file then
file:write(json_content)
file:close()
local clients = vim.lsp.get_clients()
local rust_analyzer_attached = false
for _, client in ipairs(clients) do
if client.name == "rust_analyzer" then
rust_analyzer_attached = true
break
end
end
if rust_analyzer_attached then
vim.cmd("LspRestart rust_analyzer")
end
else
print("Failed to open file: " .. output_file)
end
else
print("Directory " .. target_dir .. " does not exist.")
end
end
end,
}, |
You absolute legend. I came across this about 45 mins after searching for a solution and this is exactly what I needed. |
Hi, when I try to solve any problem using Rust the lsp completion doesn't work, there a capture of another project of rust:

but in leetcode.nvim it didn't work:
there the LspInfo of this problem, it seems the standalone mode is running and the formatting also works, but the issue is just with completion

this is my config of leetcode.nvim
I tried with other languages like c/c++ and java, in this languages it works fine:

The text was updated successfully, but these errors were encountered: