1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

Compare commits

...

11 Commits

Author SHA1 Message Date
WombleWoo7547
f0794e7f58
Merge 994b0d4c84dcf9e780d5887c7527a9ab04ef2d8b into 8dfae271d020e198e385382c4f31b15ad4d10405 2024-11-07 21:48:13 -03:00
jdhao
8dfae271d0 use plaintext for pyright hover request
see my comment here for the details: https://www.reddit.com/r/neovim/comments/1gdv1rc/comment/lvt9nlm/
2024-11-07 21:53:32 +01:00
jdhao
1141a18c5f update config for pyright 2024-11-06 23:19:55 +01:00
jdhao
fe3d5e5922 remove plugin committia.vim 2024-11-05 22:16:54 +01:00
jdhao
9769c24633 Switch Python LSP for completion and add ruff
pyright servers type checking, completion, and ruff servers linting and
diagnostics (ruff can also format Python files, but it is slightly
different from black)
2024-11-05 22:09:33 +01:00
jdhao
97f72936ac Enable LSP format also for visual selection 2024-11-05 22:04:49 +01:00
jdhao
94cade03be enable inlayhint for lua_ls server
The client side inlayhint can be enabled by uncommentting the code in
this PR.
2024-11-05 22:01:23 +01:00
jdhao
590bd6c7e6 use stylua to format lua files 2024-11-05 21:56:18 +01:00
jdhao
4171f190f2 Add plugin nvim-lightbulb to hint code actions 2024-11-05 21:47:34 +01:00
jdhao
5426c88a90 update Leaderf setting
Only search file content and not file name when using Leaderf rg
2024-11-05 21:44:34 +01:00
WombleWoo7547
994b0d4c84
Update documentation to mention WSL2 2024-10-06 09:21:22 +01:00
5 changed files with 98 additions and 52 deletions

View File

@ -3,3 +3,5 @@ set formatoptions-=o
set formatoptions-=r
nnoremap <buffer><silent> <F9> :luafile %<CR>
nnoremap <buffer><silent> <space>f <cmd>!stylua %<CR>

View File

@ -10,7 +10,7 @@ For a list of terminals that support true colors, see [here](https://github.com/
For macOS, we can use [kitty](https://sw.kovidgoyal.net/kitty/), [iterm2](https://www.iterm2.com/), [wezterm](https://wezfurlong.org/wezterm/) or [Alacritty](https://github.com/jwilm/alacritty).
If you ssh to Linux server on Windows, I recommend [wsltty](https://github.com/mintty/wsltty) and [Cygwin](https://www.cygwin.com/),
If you ssh to Linux server on Windows, or use [WSL2 (Windows Subsystem for Linux)](https://learn.microsoft.com/en-us/windows/wsl/about) I recommend [wsltty](https://github.com/mintty/wsltty) and [Cygwin](https://www.cygwin.com/),
both of them use [mintty](https://github.com/mintty/mintty) as the terminal emulator.
For the latest version of Windows 10, you can also try [Windows Terminal](https://github.com/microsoft/terminal).

View File

@ -3,6 +3,7 @@ local api = vim.api
local keymap = vim.keymap
local lsp = vim.lsp
local diagnostic = vim.diagnostic
local lspconfig = require("lspconfig")
local utils = require("utils")
@ -48,9 +49,13 @@ local custom_attach = function(client, bufnr)
-- Set some key bindings conditional on server capabilities
if client.server_capabilities.documentFormattingProvider then
map("n", "<space>f", vim.lsp.buf.format, { desc = "format code" })
map({"n", "x"}, "<space>f", vim.lsp.buf.format, { desc = "format code" })
end
-- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint,
-- but disable this feature by default, so you may need to enable inlay hint in the LSP server config.
-- vim.lsp.inlay_hint.enable(true, {buffer=bufnr})
api.nvim_create_autocmd("CursorHold", {
buffer = bufnr,
callback = function()
@ -110,69 +115,100 @@ local custom_attach = function(client, bufnr)
end
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- required by nvim-ufo
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true
}
local lspconfig = require("lspconfig")
-- For what diagnostic is enabled in which type checking mode, check doc:
-- https://github.com/microsoft/pyright/blob/main/docs/configuration.md#diagnostic-settings-defaults
-- Currently, the pyright also has some issues displaying hover documentation:
-- https://www.reddit.com/r/neovim/comments/1gdv1rc/what_is_causeing_the_lsp_hover_docs_to_looks_like/
if utils.executable("pylsp") then
local venv_path = os.getenv('VIRTUAL_ENV')
local py_path = nil
-- decide which python executable to use for mypy
if venv_path ~= nil then
py_path = venv_path .. "/bin/python3"
else
py_path = vim.g.python3_host_prog
end
if utils.executable('pyright') then
local new_capability = {
-- this will remove some of the diagnostics that duplicates those from ruff, idea taken and adapted from
-- here: https://github.com/astral-sh/ruff-lsp/issues/384#issuecomment-1989619482
textDocument = {
publishDiagnostics = {
tagSupport = {
valueSet = { 2 }
}
},
hover = {
contentFormat = { "plaintext" },
dynamicRegistration = true,
},
}
}
local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability)
lspconfig.pylsp.setup {
lspconfig.pyright.setup {
cmd = { "delance-langserver", "--stdio" },
on_attach = custom_attach,
capabilities = merged_capability,
settings = {
pylsp = {
plugins = {
-- formatter options
black = { enabled = true },
autopep8 = { enabled = false },
yapf = { enabled = false },
-- linter options
pylint = { enabled = true, executable = "pylint" },
ruff = { enabled = false },
pyflakes = { enabled = false },
pycodestyle = { enabled = false },
-- type checker
pylsp_mypy = {
enabled = true,
overrides = { "--python-executable", py_path, true },
report_progress = true,
live_mode = false
pyright = {
-- disable import sorting and use Ruff for this
disableOrganizeImports = true,
disableTaggedHints = false,
},
-- auto-completion options
jedi_completion = { fuzzy = true },
-- import sorting
isort = { enabled = true },
python = {
analysis = {
autoSearchPaths = true,
diagnosticMode = "workspace",
typeCheckingMode = "standard",
useLibraryCodeForTypes = true,
-- we can this setting below to redefine some diagnostics
diagnosticSeverityOverrides = {
deprecateTypingAliases = false,
},
-- inlay hint settings are provided by pylance?
inlayHints = {
callArgumentNames = "partial",
functionReturnTypes = true,
pytestParameters = true,
variableTypes = true,
},
},
},
flags = {
debounce_text_changes = 200,
},
capabilities = capabilities,
}
else
vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Nvim-config" })
vim.notify("pyright not found!", vim.log.levels.WARN, { title = 'Nvim-config' })
end
-- if utils.executable('pyright') then
-- lspconfig.pyright.setup{
-- on_attach = custom_attach,
-- capabilities = capabilities
-- }
-- else
-- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'})
-- end
if utils.executable("ruff") then
require('lspconfig').ruff.setup({
on_attach = custom_attach,
capabilities = capabilities,
init_options = {
-- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/
settings = {
organizeImports = true,
}
}
})
end
-- Disable ruff hover feature in favor of Pyright
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup('lsp_attach_disable_ruff_hover', { clear = true }),
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
-- vim.print(client.name, client.server_capabilities)
if client == nil then
return
end
if client.name == 'ruff' then
client.server_capabilities.hoverProvider = false
end
end,
desc = 'LSP: Disable hover capability from Ruff',
})
if utils.executable("ltex-ls") then
lspconfig.ltex.setup {
@ -220,8 +256,8 @@ if utils.executable("bash-language-server") then
}
end
-- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/
if utils.executable("lua-language-server") then
-- settings for lua-language-server can be found on https://github.com/LuaLS/lua-language-server/wiki/Settings .
lspconfig.lua_ls.setup {
on_attach = custom_attach,
settings = {
@ -230,6 +266,9 @@ if utils.executable("lua-language-server") then
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
hint = {
enable = true
}
},
},
capabilities = capabilities,

View File

@ -357,9 +357,6 @@ local plugin_specs = {
end,
},
-- Better git commit experience
{ "rhysd/committia.vim", lazy = true },
{
"sindrets/diffview.nvim",
},
@ -573,6 +570,14 @@ local plugin_specs = {
end,
event = "VeryLazy",
},
{
-- show hint for code actions, the user can also implement code actions themselves,
-- see discussion here: https://github.com/neovim/neovim/issues/14869
"kosayoda/nvim-lightbulb",
config = function()
require("nvim-lightbulb").setup { autocmd = { enabled = true } }
end,
},
}
require("lazy").setup {

View File

@ -79,7 +79,7 @@ let g:Lf_WorkingDirectoryMode = 'a'
nnoremap <silent> <leader>ff :<C-U>Leaderf file --popup<CR>
" Grep project files in popup window
nnoremap <silent> <leader>fg :<C-U>Leaderf rg --no-messages --popup<CR>
nnoremap <silent> <leader>fg :<C-U>Leaderf rg --no-messages --popup --nameOnly<CR>
" Search vim help files
nnoremap <silent> <leader>fh :<C-U>Leaderf help --popup<CR>