Skip to content

Commit

Permalink
feat(lsp): support python lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
loctvl842 committed Jun 7, 2023
1 parent 399252e commit 4a64025
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 29 deletions.
15 changes: 8 additions & 7 deletions lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" },
"compile-nvim": { "branch": "main", "commit": "f7ad312ec5d0ae4a0554a7e52349ee371b868a5d" },
"dashboard-nvim": { "branch": "master", "commit": "0af0ad181db271ef8d5a332f4cfcec9118340497" },
"dressing.nvim": { "branch": "master", "commit": "f19cbd56f7f8cad212c58a7285d09c5d9c273896" },
"dressing.nvim": { "branch": "master", "commit": "f16d7586fcdd8b2e3850d0abb7e46f944125cc25" },
"emmet-vim": { "branch": "master", "commit": "def5d57a1ae5afb1b96ebe83c4652d1c03640f4d" },
"friendly-snippets": { "branch": "main", "commit": "7006e69b60a559837ff6cdb7fe610af4f6ca823c" },
"ethHvr": { "branch": "main", "commit": "e6b0ab6004abcd6a1397d303124adcb5f196fe99" },
"friendly-snippets": { "branch": "main", "commit": "9025d37189f26b6ca0b965a9e5eec3e69c37d2e9" },
"gitsigns.nvim": { "branch": "main", "commit": "bb808fc7376ed7bac0fbe8f47b83d4bf01738167" },
"indent-blankline.nvim": { "branch": "master", "commit": "ceaf730b13e332cd76600d9795722413c236c684" },
"lazy.nvim": { "branch": "main", "commit": "ebdd0499551765e6a7aba220cc8ae4e0cdb6be69" },
"lazy.nvim": { "branch": "main", "commit": "f145e6f42a56306c5536e9efbfe41f7efbec285d" },
"lsp_signature.nvim": { "branch": "master", "commit": "4665921ff8e30601c7c1328625b3abc1427a6143" },
"lspsaga.nvim": { "branch": "main", "commit": "e39c210c5f19a01a627e1d25544e5aca52efb522" },
"lualine.nvim": { "branch": "master", "commit": "05d78e9fd0cdfb4545974a5aa14b1be95a86e9c9" },
Expand All @@ -27,7 +28,7 @@
"mini.comment": { "branch": "main", "commit": "9ead47cef4266efa5145808b838762c658b74f74" },
"mini.indentscope": { "branch": "main", "commit": "f60e9b51a6214c73a170ffc5445ce91560981031" },
"mini.pairs": { "branch": "main", "commit": "771c08bd313614c7e9a1904d277ac76eb226f674" },
"monokai-pro.nvim": { "branch": "master", "commit": "1fee9d151787c6a0bdbaceeee63e3c8f7f557385" },
"monokai-pro.nvim": { "branch": "master", "commit": "9f9d9d253983a9360e16bc1dd2b8d6cea5842006" },
"neo-tree-diagnostics.nvim": { "branch": "main", "commit": "e1149cc68264739dce7d4f02df483bbb8c0f6a8f" },
"neo-tree.nvim": { "branch": "v2.x", "commit": "8c89efb93b8383666a6f989762c2f610f5f2c930" },
"noice.nvim": { "branch": "main", "commit": "ed7bbe09e8516040836c194ad17b3f2b3162cade" },
Expand All @@ -38,12 +39,11 @@
"nvim-colorizer.lua": { "branch": "master", "commit": "dde3084106a70b9a79d48f426f6d6fec6fd203f7" },
"nvim-jdtls": { "branch": "master", "commit": "a5c6f38f8151d7b4f5b32c005a95022fa66f4c9d" },
"nvim-lightbulb": { "branch": "master", "commit": "ca5b44a8efffb5fec1963ccd21f25ec04cc778b7" },
"nvim-lspconfig": { "branch": "master", "commit": "9166622781a39a829878d1fd24c174529d996838" },
"nvim-lspconfig": { "branch": "master", "commit": "664de12a7816dfa348bb475607edfa4fe0122025" },
"nvim-navic": { "branch": "master", "commit": "15704c607569d6c5cfeab486d3ef9459645a70ce" },
"nvim-notify": { "branch": "master", "commit": "bdd647f61a05c9b8a57c83b78341a0690e9c29d7" },
"nvim-scrollbar": { "branch": "main", "commit": "35f99d559041c7c0eff3a41f9093581ceea534e8" },
"nvim-tree.lua": { "branch": "master", "commit": "e2a4c9d09d205ebe5f071264f43f73a0077c43a3" },
"nvim-treesitter": { "branch": "master", "commit": "62146fe415193879290c523b54cb5072e1f5dbbc" },
"nvim-treesitter": { "branch": "master", "commit": "9ec2a6bbdae426fc093b71805e7929158ac09411" },
"nvim-ts-autotag": { "branch": "main", "commit": "40615e96075c743ef47aaf9de966dc348bec6459" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "0bf8fbc2ca8f8cdb6efbd0a9e32740d7a991e4c3" },
"nvim-ts-rainbow2": { "branch": "master", "commit": "c00d61ab7517530c49457ba49186776e6611a3e1" },
Expand All @@ -55,6 +55,7 @@
"promise-async": { "branch": "main", "commit": "38a4575da9497326badd3995e768b4ccf0bb153e" },
"rnvimr": { "branch": "main", "commit": "4f4fbd29e2e0869bea9a8376e06fca4331de60c9" },
"statuscol.nvim": { "branch": "main", "commit": "f13a5dbe83ed500e6022e8e96d3c404aa11ebfba" },
"swenv.nvim": { "branch": "main", "commit": "08aea3e8809ab00dfcab3cebb466dcb8001ad162" },
"telescope.nvim": { "branch": "master", "commit": "6d3fbffe426794296a77bb0b37b6ae0f4f14f807" },
"toggleterm.nvim": { "branch": "main", "commit": "95204ece0f2a54c89c4395295432f9aeedca7b5f" },
"tokyonight.nvim": { "branch": "main", "commit": "cd5156f4b4a6c4c337a46deb0c0bd37319920833" },
Expand Down
5 changes: 5 additions & 0 deletions lua/tvl/config/lsp/navic.lua
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ M.attach = function(client, buffer)
if not status_ok then
return
end

if client.name == "pylsp" then
return
end

if client.server_capabilities.documentSymbolProvider then
navic.attach(client, buffer)
end
Expand Down
22 changes: 22 additions & 0 deletions lua/tvl/config/lsp/python.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local M = {}

M.attach = function(client, buffer)
local sc = client.server_capabilities
if client.name == "pylsp" then
sc.documentFormattingProvider = false
sc.documentRangeFormattingProvider = false
end
if client.name == "pyright" then
client.server_capabilities.renameProvider = false -- rope is ok
client.server_capabilities.hoverProvider = false -- pylsp includes also docstrings
client.server_capabilities.signatureHelpProvider = false -- pyright typing of signature is weird
client.server_capabilities.definitionProvider = false -- pyright does not follow imports correctly
client.server_capabilities.referencesProvider = false -- pylsp does it
client.server_capabilities.completionProvider = {
resolveProvider = true,
triggerCharacters = { "." },
}
end
end

return M
57 changes: 54 additions & 3 deletions lua/tvl/config/lsp/servers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,72 @@ local servers = {
},
},
},

-- python language server
pyright = {
settings = {
python = {
analysis = {
indexing = true,
typeCheckingMode = "basic",
diagnosticMode = "workspace",
diagnosticMode = "openFilesOnly",
autoImportCompletions = false,
-- autoSearchPaths = false,
inlayHints = {
variableTypes = true,
functionReturnTypes = true,
},
useLibraryCodeForTypes = true,
diagnosticSeverityOverrides = {
reportGeneralTypeIssues = "none",
reportOptionalMemberAccess = "none",
reportOptionalSubscript = "none",
reportPrivateImportUsage = "none",
},
},
},
},
},
pylsp = {
capabilities = {
documentFormattingProvider = false,
documentRangeFormattingProvider = false,
},
settings = {
pylsp = {
plugins = {
jedi_definition = {
enabled = true,
follow_imports = true,
follow_builtin_imports = true,
follow_builtin_definitions = true,
},
jedi_rename = { enabled = true },
jedi_completion = { enabled = false },
jedi_hover = { enabled = true },
pylsp_mypy = {
enabled = true,
live_mode = false,
dmypy = false,
report_progress = false,
},
-- Disabled ones:
flake8 = { enabled = false },
mccabe = { enabled = false },
preload = { enabled = false },
pycodestyle = { enabled = false },
pyflakes = { enabled = false },
pylint = { enabled = false },
rope = { enabled = true },
rope_completion = { enabled = true },
rope_rename = { enabled = false },
yapf = { enabled = false },
pylsp_black = { enabled = false },
pyls_isort = { enabled = false },
autopep8 = { enabled = false },
},
},
},
},
bashls = {},
}

return servers
2 changes: 1 addition & 1 deletion lua/tvl/config/lualine/highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ end
M.custom = function(config)
local statusline_hl = util.get_highlight_value("StatusLine")
local palette = {
float_background = util.get_highlight_value("CursorLine").background,
float_background = util.get_highlight_value("Pmenu").background,
editor_bg = util.get_highlight_value("Normal").background or "NONE",
statusbar_bg = statusline_hl.background or "#000000",
statusbar_fg = statusline_hl.foreground or "#505050",
Expand Down
3 changes: 2 additions & 1 deletion lua/tvl/config/neo-tree/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local config = {
{ source = "filesystem", display_name = "󰉓" },
{ source = "buffers", display_name = "󰈙" },
{ source = "git_status", display_name = "" },
-- { source = "document_symbols", display_name = "o" },
{ source = "diagnostics", display_name = "󰒡" },
},
},
Expand All @@ -46,7 +47,7 @@ local config = {
-- then these will never be used.
default = "",
},
modified = { symbol = "[+]" },
modified = { symbol = "" },
git_status = { symbols = Icons.git },
diagnostics = { symbols = Icons.diagnostics },
},
Expand Down
5 changes: 3 additions & 2 deletions lua/tvl/core/resources/colorscheme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ return {
monokai.setup({
transparent_background = false,
devicons = true,
filter = "spectrum", -- classic | octagon | pro | machine | ristretto | spectrum
filter = "pro", -- classic | octagon | pro | machine | ristretto | spectrum
day_night = {
enable = false,
day_filter = "classic",
night_filter = "octagon",
},
inc_search = "background", -- underline | background
background_clear = { "nvim-tree" },
background_clear = { "nvim-tree", "neo-tree", "bufferline" },
plugins = {
bufferline = {
underline_selected = true,
underline_visible = false,
underline_fill = true,
bold = false,
},
indent_blankline = {
Expand Down
4 changes: 1 addition & 3 deletions lua/tvl/core/resources/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ local Util = require("tvl.util")
local Icons = require("tvl.core.icons")

return {
{ "nvim-tree/nvim-tree.lua", lazy = true, opts = {} },

{
"nvim-neo-tree/neo-tree.nvim",
cmd = "Neotree",
dependencies = { "mrbjarksen/neo-tree-diagnostics.nvim" },
dependencies = "mrbjarksen/neo-tree-diagnostics.nvim",
keys = {
{
"<leader>e",
Expand Down
4 changes: 3 additions & 1 deletion lua/tvl/core/resources/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ return {
config = function()
-- special attach lsp
require("tvl.util").on_attach(function(client, buffer)
require("tvl.config.lsp.navic").attach(client, buffer)
require("tvl.config.lsp.keymaps").attach(client, buffer)
require("tvl.config.lsp.inlayhints").attach(client, buffer)
require("tvl.config.lsp.gitsigns").attach(client, buffer)
require("tvl.config.lsp.python").attach(client, buffer)
end)

-- diagnostics
Expand Down Expand Up @@ -112,7 +114,7 @@ return {
formatting.black,
formatting.markdownlint,
formatting.beautysh.with({ extra_args = { "--indent-size", "2" } }),
diagnostics.flake8.with({ extra_args = { "--ignore=E203,E501" }, filetypes = { "python" } }),
diagnostics.flake8.with({ extra_args = { "--ignore=E203,E501,E402,F401" }, filetypes = { "python" } }),
},
})
end,
Expand Down
12 changes: 12 additions & 0 deletions lua/tvl/core/resources/tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,16 @@ return {
},
},
},

-- Easily switch virtual environment in python
{
"AckslD/swenv.nvim",
config = function()
require("swenv").setup({
post_set_venv = function()
vim.cmd([[LspRestart]])
end,
})
end,
},
}
1 change: 1 addition & 0 deletions lua/tvl/core/resources/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ return {
"scss",
"cpp",
"java",
"graphql",
},
highlight = { enable = true },
indent = { enable = true, disable = { "yaml", "python", "html" } },
Expand Down
23 changes: 12 additions & 11 deletions lua/tvl/core/resources/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ return {
filetype = "neo-tree",
text = "EXPLORER",
text_align = "center",
-- separator = true,
separator = true, -- set to `true` if clear background of neo-tree
},
{
filetype = "NvimTree",
Expand All @@ -83,15 +83,15 @@ return {
{
"nvim-lualine/lualine.nvim",
event = "VeryLazy",
opts = {},
config = function()
opts = {
float = true,
separator = "bubble", -- bubble | triangle
---@type any
colorful = true,
},
config = function(_, opts)
local lualine_config = require("tvl.config.lualine")
lualine_config.setup({
float = false,
separator = "bubble", -- bubble | triangle
---@type any
colorful = true,
})
lualine_config.setup(opts)
lualine_config.load()
end,
},
Expand Down Expand Up @@ -171,6 +171,7 @@ return {
"nvim-tree/nvim-web-devicons",
},
opts = {
attach_navic = false,
theme = "auto",
include_buftypes = { "" },
exclude_filetypes = { "gitcommit", "Trouble", "toggleterm" },
Expand Down Expand Up @@ -199,7 +200,7 @@ return {
winbar = {
enabled = true,
name_formatter = function(term)
return string.format("%d:%s", term.id, term:_display_name())
return term.name
end,
},
},
Expand Down Expand Up @@ -347,7 +348,7 @@ return {
cmdline = { icon = "" },
search_down = { icon = "  󰄼" },
search_up = { icon = "  " },
lua = { icon = "" },
lua = { icon = " " },
},
},
lsp = {
Expand Down

0 comments on commit 4a64025

Please sign in to comment.