Giter VIP home page Giter VIP logo

neovim-rust's Introduction

neovim-rust

Collection of Neovim and Vim configurations to kickstart your Rust development experience.

Examples

Each example provides Prerequisites and Steps as comments at the top of each file.

The only maintained file is neovim-init-lsp-cmp-rust-tools.lua, other examples are in ./unmaintained/

Try for yourself!

Each example can be tested with the provided Dockerfile! This allows you to test a configuration without changing your system. The Dockerfile provides all the dependencies required to run each setup.

See the run.sh script for details. This will start a docker instance and run PlugInstall.

For example, ./run.sh ./neovim-init-lsp-cmp-rust-tools.lua to test this configuration.

Once in the container, navigate to ~/test_app to try the configuration on some rust code.

neovim-rust's People

Contributors

balroggg avatar bluk avatar lnicola avatar nilsmartel avatar ruffson avatar sharksforarms avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neovim-rust's Issues

nvim-lsp: inlay hints not working?

image

I'm using your snippet:

autocmd CursorMoved,InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost *
\ lua require'lsp_extensions'.inlay_hints{ prefix = '', highlight = "Comment" }

Tested with nvim 0.5.0+dev+1062+gcc1851c9f-1.

change rust-analyzer `--target-dir`

Trying to switch to nvim.

I usually background nvim and run cargo check from the command line. This however causes problems with rust-analyzer:

✦ ❯ cargo c
    Blocking waiting for file lock on build directory

I tried the following:

nvim_lsp.rust_analyzer.setup({
    on_attach=on_attach;
    settings = {
            ["rust-analyzer"] = {
                checkOnSave = {
                    enable = true,
                    command = "check",
                    extraArgs = { "--target-dir", "/tmp/rust-analyzer-check" },
                },
            },
    }
})

But it doesn't seem to follow those instructions, as I see nothing in the tmp directory, and the issue still persists. Any idea on how to set the --target-dir?

Question about updating LSP output

Hi, I'm using the most recommended setup, and the LSP output (like inline errors and lints) only update when I save my changes to the buffer with :w. Should the output should update in real time or is it only supposed to update when the changes are written with :w? Thanks!

"Command already exist" error

With a config that only has the neovim-init-lsp-cmp-rust-tools.vim file, I'm getting the below incredibly unhelpful error:

Error detected while processing BufNewFile Autocommands for "*":
Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:22: Error executing lua: /usr/share/nvim/runtime/filetype.lua:23: Vim(command):E174: Command already exist
s: add ! to replace it: RustStartStandaloneServerForBuffer :lua require('rust-tools.standalone').start_standalone_client()
stack traceback:
        [C]: in function 'nvim_cmd'
        /usr/share/nvim/runtime/filetype.lua:23: in function </usr/share/nvim/runtime/filetype.lua:22>
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/filetype.lua:22: in function </usr/share/nvim/runtime/filetype.lua:11>
stack traceback:
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/filetype.lua:22: in function </usr/share/nvim/runtime/filetype.lua:11>

This only happens in .rs files.
Not sure what I'm doing wrong or how I can fix it.

Arch Linux
Neovim v0.8.0
rust-analyzer 1 (5c28ad1932 2022-10-01)

Getting some errors/not working as described

I tried this on Docker Desktop on my M1 machine and nvim runs but there does not seem to be any rust format stuff working. I see in the nvim output history:

method rust-analyzer/inlayHints is not supported by any of the servers registered for the current buffer
Client 1 quit with exit code 255 and signal 0

I'm a total rust noob though.

Error executing lua Vim:E474

Error executing lua Vim:E474: Unidentified byte: bash: cannot set terminal process group (-1): Operation not supported on socket

Why not coc

coc has a lot of features.
Compared with coc, what are the pros and cons?

Configuration not working

Hi!
I'm using your configuration but when I open my rust project, nothing happens.

I'm using the nightly appimage for neovim and the lastest version of rust-analyzer.
I'm on ubuntu 20.10.

Here is my init.vim

call plug#begin('~/.vim/plugged')

" Collection of common configurations for the Nvim LSP client
Plug 'neovim/nvim-lspconfig'

" Extentions to built-in LSP, for example, providing type inlay hints
Plug 'tjdevries/lsp_extensions.nvim'

" Autocompletion framework for built-in LSP
Plug 'nvim-lua/completion-nvim'

" Tree plugin
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'

" Fuzzy finder
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

call plug#end()

syntax enable
filetype plugin indent on

set nocompatible
set nobackup
set nowritebackup
set noswapfile

set expandtab
set tabstop=4
set shiftwidth=4

" nerdtree toggle with control n
silent! nmap <C-n> :NERDTreeToggle<CR>

" open fuzzy finder with control p
silent! nmap <C-p> :GFiles<CR>

" Set completeopt to have a better completion experience
set completeopt=menuone,noinsert,noselect

" Avoid showing extra messages when using completion
set shortmess+=c

" Configure lsp
" https://github.com/neovim/nvim-lspconfig#rust_analyzer
lua <<EOF

-- nvim_lsp object
local nvim_lsp = require'lspconfig'

-- function to attach completion when setting up lsp
local on_attach = function(client)
    require'completion'.on_attach(client)
end

-- Enable rust_analyzer
nvim_lsp.rust_analyzer.setup({ on_attach=on_attach })

-- Enable diagnostics
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
  vim.lsp.diagnostic.on_publish_diagnostics, {
    virtual_text = false,
    signs = true,
    update_in_insert = true,
  }
)
EOF

" Code navigation shortcuts
" as found in :help lsp
nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> K     <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gD    <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <c-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> 1gD   <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> gr    <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> g0    <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gW    <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
" rust-analyzer does not yet support goto declaration
" re-mapped `gd` to definition
nnoremap <silent> gd    <cmd>lua vim.lsp.buf.definition()<CR>
"nnoremap <silent> gd    <cmd>lua vim.lsp.buf.declaration()<CR>

" Trigger completion with <tab>
" found in :help completion
function! s:check_back_space() abort
    let col = col('.') - 1
    return !col || getline('.')[col - 1]  =~ '\s'
endfunction

inoremap <silent><expr> <TAB>
  \ pumvisible() ? "\<C-n>" :
  \ <SID>check_back_space() ? "\<TAB>" :
  \ completion#trigger_completion()

" have a fixed column for the diagnostics to appear in
" this removes the jitter when warnings/errors flow in
set signcolumn=yes

" Set updatetime for CursorHold
" 300ms of no cursor movement to trigger CursorHold
set updatetime=300
" Show diagnostic popup on cursor hover
autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics()

" Goto previous/next diagnostic warning/error
nnoremap <silent> g[ <cmd>lua vim.lsp.diagnostic.goto_prev()<CR>
nnoremap <silent> g] <cmd>lua vim.lsp.diagnostic.goto_next()<CR>

" Enable type inlay hints
autocmd CursorMoved,InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost *
\ lua require'lsp_extensions'.inlay_hints{ prefix = '', highlight = "Comment" }

When I do a checkhealth I get the following

health#lspconfig#check
  ========================================================================
  ## Checking language server protocol configuration
    - INFO: rust_analyzer: configuration checked.

  health#completion_nvim#check
  ========================================================================
  ## general
    - OK: neovim version is supported

  ## completion source
    - OK: all completion source are valid

  ## snippet source
    - INFO: You haven't setup any snippet source.

  health#nvim#check
  ========================================================================
  ## Configuration
    - OK: no issues found

  ## Performance
    - OK: Build type: RelWithDebInfo

  ## Remote Plugins
    - OK: Up to date

  ## terminal
    - INFO: key_backspace (kbs) terminfo entry: key_backspace=\177
    - INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~
    - INFO: $SSH_TTY='/dev/pts/0'

The nvim --version result is the following

NVIM v0.5.0-dev+965-gd0668b36a
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compiled by runner@fv-az175-356

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/home/runner/work/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Return does not fill in arguments

Hi there,
I integrated your config to my init.vim. Most things work but when I tab through the suggestions and press enter, it just completes the function name but does not add the function arguments or the brackets. See here:

completion

Any idea why this happens? I also tried to reduce the config, remove the lspsaga stuff, but that did not help either.

Is there a convenient way to change cargo's features or targets?

Sometimes I'm working on a project with feature and/or target-specific code, and I'd like to change my rust-analyzer configuration to get diagnostics for the feature and/or target that I'm currently working on. (i.e I want nvim to give me the same errors I'd get if I were running cargo check --features=foo,bar --target=wasm32-unknown-unknown).

Do you know how to do this? I found this page suggesting that there's a rust-analyzer.cargo.features setting somewhere, but I couldn't figure out where to set it, let alone how to conveniently modify it on the fly...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.