Skip to content

Commit

Permalink
updated for Python work stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
BakerNet committed Dec 19, 2023
1 parent f12f69c commit 4a0ec30
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 32 deletions.
6 changes: 0 additions & 6 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,5 @@ vim.g.loaded_netrwPlugin = 1

require("hans")

-- Diagnostic keymaps
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
vim.keymap.set('n', '<leader>df', vim.diagnostic.open_float, { desc = 'Open [D]iagnostic [F]loating message' })
vim.keymap.set('n', '<leader>dl', vim.diagnostic.setloclist, { desc = 'Open [D]iagnostics [L]ist' })

-- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et
50 changes: 50 additions & 0 deletions lua/hans/diagnostics.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
local M = {}

local serverity_map = {
"DiagnosticError",
"DiagnosticWarn",
"DiagnosticInfo",
"DiagnosticHint",
}
local icon_map = {
"",
"",
"",
"",
}

local function source_string(source)
return string.format(" [%s]", source)
end

M.line_diagnostics = function()
local bufnr, lnum = unpack(vim.fn.getcurpos())
local diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr, lnum - 1, {})
if vim.tbl_isempty(diagnostics) then
return
end

local lines = {}

for _, diagnostic in ipairs(diagnostics) do
table.insert(
lines,
icon_map[diagnostic.severity]
.. " "
.. diagnostic.message:gsub("\n", " ")
.. source_string(diagnostic.source)
)
end

local floating_bufnr, _ = vim.lsp.util.open_floating_preview(lines, "plaintext", {
border = vim.g.floating_window_border_dark,
})

for i, diagnostic in ipairs(diagnostics) do
local message_length = #lines[i] - #source_string(diagnostic.source)
vim.api.nvim_buf_add_highlight(floating_bufnr, -1, serverity_map[diagnostic.severity], i - 1, 0, message_length)
vim.api.nvim_buf_add_highlight(floating_bufnr, -1, "DiagnosticSource", i - 1, message_length, -1)
end
end

return M
8 changes: 8 additions & 0 deletions lua/hans/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ vim.keymap.set('n', '<leader>bn', [[<Cmd>bnext<CR>]])

-- save with C-s
vim.keymap.set({ 'n', 'i' }, '<C-s>', [[<Cmd>wa!<CR>]])

-- Diagnostic keymaps
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
vim.keymap.set('n', '<leader>df', vim.diagnostic.open_float, { desc = 'Open [D]iagnostic [F]loating message' })
vim.keymap.set("n", "<leader>dv", require("hans.diagnostics").line_diagnostics,
{ buffer = bufnr, desc = 'Open [D]iagnostic [S]ource Floating message' })
vim.keymap.set('n', '<leader>dl', vim.diagnostic.setloclist, { desc = 'Open [D]iagnostics [L]ist' })
50 changes: 26 additions & 24 deletions lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ local setup_autoformat = function()
end

vim.lsp.buf.format {
async = false,
async = true, -- black takes forever... we'll see
filter = function(c)
return c.id == client.id
end,
Expand Down Expand Up @@ -94,8 +94,8 @@ local setup_lsp = function()
nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
nmap('<leader>sd', require('telescope.builtin').lsp_document_symbols, '[S]ymbols in [D]ocument')
nmap('<leader>sw', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[S]ymbols in [W]orkspace')

-- See `:help K` for why this keymap
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
Expand Down Expand Up @@ -136,28 +136,30 @@ local setup_lsp = function()

local venv_path = os.getenv('VIRTUAL_ENV')
if venv_path ~= nil then
servers['pylsp'] = {
settings = {
pylsp = {
plugins = {
-- formatter options
black = { enabled = true },
autopep8 = { enabled = false },
yapf = { enabled = false },
-- linter options
runn = { enabled = true },
pylint = { enabled = false, executable = "pylint" },
pyflakes = { enabled = false },
pycodestyle = { enabled = false },
-- type checker
pylsp_mypy = { enabled = true },
-- auto-completion options
jedi_completion = { fuzzy = true },
-- import sorting
pyls_isort = { enabled = true },
},
servers.pylsp = {
pylsp = {
plugins = {
-- formatter options
black = { enabled = true },
autopep8 = { enabled = false },
yapf = { enabled = false },
-- linter options
ruff = { enabled = true },
pylint = { enabled = false, executable = "pylint" },
pyflakes = { enabled = false },
pycodestyle = { enabled = false },
mccabe = { enabled = false },
flake8 = { enabled = false },
-- type checker
pylsp_mypy = { enabled = false },
-- auto-completion options
jedi_completion = { fuzzy = true },
-- import sorting
isort = { enabled = true },
-- code actions
rope_autoimport = { enabled = true },
},
}
},
}
end

Expand Down
18 changes: 16 additions & 2 deletions lua/plugins/ui.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
return {
-- Useful plugin to show you pending keybinds.
{ 'folke/which-key.nvim', opts = {} },
-- Set lualine as statusline
{
-- Set lualine as statusline
'nvim-lualine/lualine.nvim',
-- See `:help lualine.txt`
opts = {
Expand All @@ -14,7 +14,8 @@ return {
},
},
},
{ -- File tree sidebar *chef's kiss
-- File tree sidebar *chef's kiss
{
"nvim-tree/nvim-tree.lua",
version = "*",
dependencies = {
Expand All @@ -34,6 +35,7 @@ return {
vim.keymap.set('n', '<leader>e', ":NvimTreeToggle<cr>", { desc = 'Toggle [E]xplorer' })
end
},
-- Tab bar at the top like GUI editors
{
'akinsho/bufferline.nvim',
version = "*",
Expand Down Expand Up @@ -78,6 +80,7 @@ return {
end)
end
},
-- Pretty commandline, messages, and notifications
{
"folke/noice.nvim",
event = "VeryLazy",
Expand All @@ -102,11 +105,22 @@ return {
["cmp.entry.get_documentation"] = true,
},
},
routes = {
{
filter = { event = "msg_showmode" },
view = "notify",
},
},
-- you can enable a preset for easier configuration
presets = {
command_palette = true, -- position the cmdline and popupmenu together
},
})
end
},
-- Better vim.ui.select and vim.ui.input
{
"stevearc/dressing.nvim",
opts = {},
}
}

0 comments on commit 4a0ec30

Please sign in to comment.