simrat39 / rust-tools.nvim

Tools for better development in rust using neovim's builtin lsp
MIT License
2.17k stars 158 forks source link

Question & Request : Has anyone tried implementing lsp_status plugin with rust-tools? #271

Closed letter-p closed 1 year ago

letter-p commented 1 year ago

What I am using

Neovim : NVIM v0.8.0-1210-gd367ed9b2 https://github.com/nvim-lua/lsp-status.nvim https://github.com/neovim/nvim-lspconfig I Followed this guide : https://sharksforarms.dev/posts/neovim-rust/

vscode rust analyzer indexing progress status

rust-analyzer

INIT.VIM file

call plug#begin('~/AppData/Local/nvim/plugged')

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

" Completion framework Plug 'hrsh7th/nvim-cmp'

" LSP completion source for nvim-cmp Plug 'hrsh7th/cmp-nvim-lsp'

" Snippet completion source for nvim-cmp Plug 'hrsh7th/cmp-vsnip'

" Other usefull completion sources Plug 'hrsh7th/cmp-path' Plug 'hrsh7th/cmp-buffer'

" See hrsh7th's other plugins for more completion sources!

" Rust-analyzer, such as inlay hints and more! Plug 'simrat39/rust-tools.nvim'

" Rust analyzer indexing status Plug 'nvim-lua/lsp-status.nvim'

" Stable version of coc Plug 'neoclide/coc.nvim', {'branch': 'release'}

" Snippet engine Plug 'hrsh7th/vim-vsnip'

" Fuzzy finder " Optional Plug 'nvim-lua/popup.nvim' Plug 'nvim-lua/plenary.nvim' Plug 'nvim-telescope/telescope.nvim'

" Color scheme Plug 'EdenEast/nightfox.nvim'

" Statusline / winbar Plug 'nvim-lualine/lualine.nvim' " StatusLine with Icons Plug 'kyazdani42/nvim-web-devicons'

call plug#end()

" STATUSLINE ---------------------------------------------------

lua << END

require('lualine').setup { options = { icons_enabled = false,

component_separators = "|",
section_separators = { left = ' ', right = ' '},
disabled_filetypes = {
  statusline = {},
  winbar = {},
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = {
  statusline = 1000,
  tabline = 1000,
  winbar = 1000,
}

}, sections = { lualine_a = {'mode'}, lualine_b = {'branch', 'diff', 'diagnostics'}, lualine_c = {'filename'}, lualine_x = {'encoding', 'fileformat', 'filetype'}, lualine_y = {'progress'}, lualine_z = {'location'} }, inactive_sections = { lualine_a = {}, lualine_b = {}, lualine_c = {'filename'}, lualine_x = {'location'}, lualine_y = {}, lualine_z = {} }, tabline = {}, winbar = {}, inactive_winbar = {}, extensions = {} }

END

" COLOR SCHEMES --------------------------------------------

lua << END

require('nightfox').override.palettes({ carbonfox = { bg1 = "#000000", }, })

require('nightfox').setup({ options = { -- Compiled file's destination location compile_path = vim.fn.stdpath("cache") .. "/nightfox", compile_file_suffix = "_compiled", -- Compiled file suffix transparent = false, -- Disable setting background terminal_colors = true, -- Set terminal colors (vim.g.terminalcolor*) used in :terminal dim_inactive = false, -- Non focused panes set to alternative background styles = { -- Style to be applied to different syntax groups comments = "NONE", -- Value is any valid attr-list value :help attr-list conditionals = "NONE", constants = "NONE", functions = "NONE", keywords = "NONE", numbers = "NONE", operators = "NONE", strings = "NONE", types = "NONE", variables = "NONE", }, inverse = { -- Inverse highlight for different types match_paren = false, visual = false, search = false, }, modules = { -- List of various plugins and additional options -- ... }, }, palettes = {override}, specs = {}, groups = {}, })

vim.cmd("colorscheme carbonfox") END

" LSP RUST ANALYZER & LSP STATUS--------------------------------------------

set completeopt=menuone,noinsert,noselect

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

lua <<EOF -- config_options -- local opts = { tools = { -- rust-tools options autoSetHints = true, inlay_hints = { auto = true, parameter_hints_prefix = "<- ", other_hints_prefix = "=> ", right_align = true, show_parameter_hints = true, }, },

-- all the opts to send to nvim-lspconfig
-- these override the defaults set by rust-tools.nvim
-- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer
server = {

-- ||| LSP STATUS ||| --
on_attach = lsp_status.on_attach,
capabilities = lsp_status.capabilities,

    -- on_attach is a callback called when the language server attachs to the buffer
    settings = {
   -- to enable rust-analyzer settings visit:
        -- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
        ["rust-analyzer"] = {

    -- enable clippy on save
            checkOnSave = {
                command = "clippy"
            },
        }
    }
},

}

local lspconfig = require('lspconfig') local lsp_status = require('lsp-status') local rust_tools = require('rust-tools')

-- || LSP STATUS || --

lsp_status.register_progress() lspconfig.rust_analyzer.setup({ on_attach = lsp_status.on_attach, capabilities = lsp_status.capabilities })

-- SETTING IT UP -- rust_tools.setup(opts)

EOF

" Setup Completion " See https://github.com/hrsh7th/nvim-cmp#basic-configuration lua <<EOF local cmp = require'cmp' cmp.setup({ -- Enable LSP snippets snippet = { expand = function(args) vim.fn"vsnip#anonymous" end, }, mapping = { [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.select_next_item(), -- Add tab support [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.close(), [''] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true, }) },

-- Installed sources sources = { { name = 'lspconfig' }, { name = 'vsnip' }, { name = 'path' }, { name = 'buffer' },

}, }) EOF

RESULT

image

polyzen commented 1 year ago

Don't remember if I used it with lsp-status.nvim, but it definitely works with https://github.com/j-hui/fidget.nvim.

letter-p commented 1 year ago

@polyzen Thanks :) It works.