Skip to content

Lsp not working in cargo check -r #14315

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

Closed
ayush-india opened this issue Mar 10, 2023 · 20 comments · Fixed by #14328
Closed

Lsp not working in cargo check -r #14315

ayush-india opened this issue Mar 10, 2023 · 20 comments · Fixed by #14328
Labels
C-support Category: support questions

Comments

@ayush-india
Copy link

ayush-india commented Mar 10, 2023

I recently updated my ra's config to run ** cargo check -r ** insted of cargo check (debug mode)
Because i usually run my projects in release mode.

I use nvim-lspconfig and i keymapped "K" to show the hover (Just like in vscode). But it show this error
**edit: I just got to know that lol the lsp is only working. Idk what is this But i think that for ra to get compleition , code action and hover working it needs to get a debug build**
man.lua: "no manual entry for PathBuf"
when i try to get hover for PathBuf.

Is this a bug or a release issue idk. Btw thanks for help and also for build such a great software

minimal config

local on_windows = vim.loop.os_uname().version:match 'Windows'

local function join_paths(...)
  local path_sep = on_windows and '\\' or '/'
  local result = table.concat({ ... }, path_sep)
  return result
end

vim.cmd [[set runtimepath=$VIMRUNTIME]]

local temp_dir = vim.loop.os_getenv 'TEMP' or '/tmp'

vim.cmd('set packpath=' .. join_paths(temp_dir, 'nvim', 'site'))

local package_root = join_paths(temp_dir, 'nvim', 'site', 'pack')
local lspconfig_path = join_paths(package_root, 'test', 'start', 'nvim-lspconfig')

if vim.fn.isdirectory(lspconfig_path) ~= 1 then
  vim.fn.system { 'git', 'clone', 'https://github.com/neovim/nvim-lspconfig', lspconfig_path }
end

vim.lsp.set_log_level 'trace'
require('vim.lsp.log').set_format_func(vim.inspect)
local nvim_lsp = require 'lspconfig'
local on_attach = function(_, bufnr)
  local function buf_set_option(...)
    vim.api.nvim_buf_set_option(bufnr, ...)
  end

  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  -- Mappings.
  local opts = { buffer = bufnr, noremap = true, silent = true }
  vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
  vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
  vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
  vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
  vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
  vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
  vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
  vim.keymap.set('n', '<space>wl', function()
    print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
  end, opts)
  vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
  vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
  vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
  vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
  vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
  vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
  vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
end

-- Add the server that troubles you here
local name = 'rust_analyzer'
local cmd = {
	["rust-analyzer"] = {
          check = {
            extraArgs = {"-r"},
          },
        },
      },
 -- needed for elixirls, lua_ls, omnisharp
if not name then
  print 'You have not defined a server name, please edit minimal_init.lua'
end
if not nvim_lsp[name].document_config.default_config.cmd and not cmd then
  print [[You have not defined a server default cmd for a server
    that requires it please edit minimal_init.lua]]
end

nvim_lsp[name].setup {
  cmd = cmd,
  on_attach = on_attach,
}

print [[You can find your log at $HOME/.cache/nvim/lsp.log. Please paste in a github issue under a details tag as described in the issue template.]]
@ayush-india ayush-india added the C-support Category: support questions label Mar 10, 2023
@lnicola
Copy link
Member

lnicola commented Mar 10, 2023

What did you change and does it work if you change it back? Do the other features like completion work?

@ayush-india
Copy link
Author

@lnicola Wait its compliling the project

@ayush-india
Copy link
Author

@lnicola Yes it working fine in debug mode , but nothing works in release mode not hover not code actions or completiong also

@lnicola
Copy link
Member

lnicola commented Mar 10, 2023

Ref. neovim/nvim-lspconfig#2502

@ayush-india
Copy link
Author

Bro its my issue only

@ayush-india
Copy link
Author

ayush-india commented Mar 10, 2023

Lol i only have opened that issue

@lnicola
Copy link
Member

lnicola commented Mar 10, 2023

I know, but you didn't say how you configured it, so I linked to the place where you did.

@ayush-india
Copy link
Author

OoO sorry i though that ...

@lnicola
Copy link
Member

lnicola commented Mar 10, 2023

What does rust-analyzer --version say?

@ayush-india
Copy link
Author

rust-analyzer 0.3.1369-standalone

@lnicola
Copy link
Member

lnicola commented Mar 10, 2023

Try:

local settings = {
	["rust-analyzer"] = {
          check = {
            extraArgs = {"-r"},
          },
        },
}
-- ...
nvim_lsp[name].setup {
  on_attach = on_attach,
  settings = settings
}

See https://github.com/neovim/nvim-lspconfig#suggested-configuration or https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer.

@ayush-india
Copy link
Author

Fixed it idk how but yeah
lspconfig.lua

local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities

local lspconfig = require "lspconfig"
local servers = { "rust_analyzer", "pyright" }

for _, lsp in ipairs(servers) do
  lspconfig[lsp].setup {
    on_attach = on_attach,
    capabilities = capabilities,
  }
end

lspconfig.rust_analyzer.setup {
  on_attach = on_attach,
  settings = {
    ["rust-analyzer"] = {
      check = {
        extraArgs = {"-r"},
      },
    },
  },
}

@lnicola
Copy link
Member

lnicola commented Mar 10, 2023

You're registering it twice, I'm not sure that's a good idea.

@ayush-india ayush-india reopened this Mar 11, 2023
@ayush-india
Copy link
Author

ayush-india commented Mar 11, 2023

@lnicola Yes but can this work

for _, lsp in ipairs(servers) do
  lspconfig[lsp].setup {
    on_attach = on_attach,
    capabilities = capabilities,
  }
   if lsp == "rust_analyzer" then
      on_attach = on_attach,
  settings = {
    ["rust-analyzer"] = {
      check = {
        extraArgs = {"-r"},
      },
    },
  },
   end
end

Sorry if the syntax is wrng, Currently i am not on my pc right on and i don't know lua lol 🇹🇩

@lnicola
Copy link
Member

lnicola commented Mar 11, 2023

Why not this?

local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities
local lspconfig = require "lspconfig"

lspconfig.pyright.setup {on_attach = on_attach, capabilities = capabilities}
lspconfig.rust_analyzer.setup {
    on_attach = on_attach,
    settings = {["rust-analyzer"] = {check = {extraArgs = {"-r"}}}}
}

Anyway, I noticed you've reopened both issues. Are you still having trouble with this?

@ayush-india
Copy link
Author

@lnicola Nope not working it makes both a debug and a relase dir
Btw does it work in your config

I think that the hover, completion and code actions both need the debug build to work
Coz when using your config , it makes both a debug and release dir.

But if i delete the debug dir from neovim itself the every thing works fine but if i quit neovim and the start it again it seems to build the debug dir again.

Idk what is happning.

And yes i opened the issue again coz it could be that their is a bug in nvim lsp.
Btw does this work on your machine

@ayush-india
Copy link
Author

@lnicola Idk what is happening
69 pnh

Its a screen shot of rust-analyzer extraArgs by mason (the lsp installer)

Btw can i set cargo check to cargo check -r by default so that if any where cargo check run's
it is transfed to cargo check -r

@lnicola
Copy link
Member

lnicola commented Mar 11, 2023

Nope not working it makes both a debug and a relase dir

Coz when using your config , it makes both a debug and release dir.

Btw does it work in your config

Yes, it works, with { "rust-analyzer.check.extraArgs": ["-r"] } (in VS Code).

Even in release mode, some dependencies like build scripts and proc macros are not optimized.

On a test project with a single dependency, rand, I get a libc build script under debug/build and many libraries under release/deps. That doesn't mean that something is compiled once, or that they take up twice as much space, because they don't.

Btw can i set cargo check to cargo check -r by default so that if any where cargo check run's it is transfed to cargo check -r

I don't know if that's possible. You can probably make an alias like shown in https://doc.rust-lang.org/cargo/reference/config.html.

@ayush-india ayush-india changed the title Hover not working in cargo check -r Lsp not working in cargo check -r Mar 11, 2023
@ayush-india
Copy link
Author

ayush-india commented Mar 11, 2023

@lnicola

On a test project with a single dependency, rand, I get a libc build script under debug/build and many libraries under release/deps. That doesn't mean that something is compiled once, or that they take up twice as much space, because they don't.

True for a small project like with rand,
But not for a medium project https://github.com/ayush-india/music.rs its a very very small music player with is also very incomplete

23
As you can see the debug dir is 500mb and release dir is 300mb and also that i had deleted the the target dir and both we a fresh build
the debug was made by **cargo check** and the release was made by **cargo run --release**
Note: cargo check -r does not have any effect on the release dir

I get a libc build script under debug/build.

I have nothing inside that

@ayush-india
Copy link
Author

@lnicola it would be a great great favour if you could test this project in your computer
Which will probally make sure that there is some problem with my laptop only.

Btw thanks for trying to help me for so long

https://github.com/ayush-india/music.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-support Category: support questions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants