feat(flutter-tools.lua): add configuration for flutter-tools statusline decorations

feat(lsp-config.lua): update key bindings for code actions and references, remove pycodestyle config
feat(lualine.lua): add functions to display Flutter Tools statusline and check if Flutter Tools is active
feat(mason.lua): add kotlin_language_server to the list of supported language servers
feat(molten.lua): improve configuration for Molten plugin based on file type
feat(none-ls.lua): improve configuration for null-ls sources, resolve virtual environment for mypy diagnostics

fix(telescope.lua): update trouble import path to sources instead of providers
feat(telescope.lua): add vimgrep_arguments to improve search functionality
feat(telescope.lua): add mappings for trouble.open in insert and normal mode
feat(telescope.lua): load extensions flutter and dap
feat(telescope.lua): define custom find_files function with specific find_command
feat(trouble.lua): update trouble import path to sources instead of providers
feat(trouble.lua): update mappings to use trouble_sources.open instead of trouble_telescope.open_with_trouble
feat(core/init.lua): add ignorecase and smartcase options for case-insensitive searching
feat(core/init.lua): add backspace option for more flexible backspacing behavior
feat(core/init.lua): set cursor color based on mode in InsertEnter and InsertLeave autocmds
feat(dap.lua): add nvim-nio dependency and load telescope-dap.nvim extension
feat(flutter-tools.lua): add flutter-tools.nvim plugin configuration
feat(molten.lua): add lazy loading and ft option for Python files
feat(none-ls.lua.disabled): add none-ls.nvim plugin configuration
feat(poet-v.lua): add lazy loading and ft option for Python files
feat(vim-tmux-navigator.lua): update cmd and keys for vim-tmux-navigator plugin

chore(remap.lua): reorganize keymap descriptions for better clarity and readability
feat(remap.lua): add key mappings for jumping up, down, to next, and to previous locations with center screen
feat(remap.lua): add key mappings for resizing windows right, left, up, and down by 10 lines
feat(safe-invoke.lua): add utility function SafeInvoke to safely invoke functions and handle errors
This commit is contained in:
David Ibia
2024-06-14 02:03:40 +01:00
parent a96a4f719e
commit 2b7ce8f520
19 changed files with 314 additions and 205 deletions

View File

@@ -0,0 +1,12 @@
local flutter_tools = require('flutter-tools')
flutter_tools.setup({
decorations = {
statusline = {
app_version = true,
device = true,
project_config = true,
}
},
fvm = true,
})

View File

@@ -37,10 +37,10 @@ local on_attach = function(client, bufnr)
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
opts.desc = "See available code actions"
vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, opts)
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
opts.desc = "Show LSP references"
vim.keymap.set("n", "<leader>vrr", "<cmd>Telescope lsp_references<CR>", opts)
vim.keymap.set("n", "<leader>cr", "<cmd>Telescope lsp_references<CR>", opts)
opts.desc = "Format File"
vim.keymap.set("n", "<leader>f", function()
@@ -123,10 +123,6 @@ lspconfig["pylsp"].setup({
jedi_completion = {
include_params = true,
},
pycodestyle = {
ignore = { "E231" },
maxLineLength = 150,
},
},
},
},

View File

@@ -2,6 +2,7 @@ local lualine = require("lualine")
local lazy_status = require("lazy.status") -- to configure lazy pending updates count
local molten_status = require("molten.status") -- to configure molten statusline
local colors = {
blue = "#65D1FF",
green = "#3EFFDC",
@@ -46,6 +47,21 @@ local my_lualine_theme = {
},
}
function GetFlutterToolsStatusLine()
local application_version = vim.g.flutter_tools_decorations.app_version
local device = vim.g.flutter_tools_decorations.device
local result = "Flutter: " .. application_version .. " " .. device
end
function IsFlutterToolsActive()
if vim.g.flutter_tools_decorations ~= nil then
return true
else
return false
end
end
function GetPoetvStatusLine()
-- Get the poetv statusline
-- If poetv is not active, return empty string
@@ -80,6 +96,11 @@ lualine.setup({
},
sections = {
lualine_x = {
{
GetFlutterToolsStatusLine,
cond = IsFlutterToolsActive,
color = { fg = "#ff9e64" },
},
{
molten_status.initialized,
},

View File

@@ -11,6 +11,7 @@ require("mason-lspconfig").setup({
"svelte",
"cssls",
"jedi_language_server",
"kotlin_language_server"
},
automatic_installation = true,
})

View File

@@ -1,84 +1,84 @@
-- change the configuration when editing a python file
vim.api.nvim_create_autocmd("BufEnter", {
pattern = "*.py",
callback = function(e)
if string.match(e.file, ".otter.") then
return
end
if require("molten.status").initialized() == "Molten" then -- this is kinda a hack...
vim.fn.MoltenUpdateOption("virt_lines_off_by_1", false)
vim.fn.MoltenUpdateOption("virt_text_output", false)
else
vim.g.molten_virt_lines_off_by_1 = false
vim.g.molten_virt_text_output = false
end
end,
pattern = "*.py",
callback = function(e)
if string.match(e.file, ".otter.") then
return
end
if require("molten.status").initialized() == "Molten" then -- this is kinda a hack...
vim.fn.MoltenUpdateOption("virt_lines_off_by_1", false)
vim.fn.MoltenUpdateOption("virt_text_output", false)
else
vim.g.molten_virt_lines_off_by_1 = false
vim.g.molten_virt_text_output = false
end
end,
})
-- Undo those config changes when we go back to a markdown or quarto file
vim.api.nvim_create_autocmd("BufEnter", {
pattern = { "*.qmd", "*.md", "*.ipynb" },
callback = function(e)
if string.match(e.file, ".otter.") then
return
end
if require("molten.status").initialized() == "Molten" then
vim.fn.MoltenUpdateOption("virt_lines_off_by_1", true)
vim.fn.MoltenUpdateOption("virt_text_output", true)
else
vim.g.molten_virt_lines_off_by_1 = true
vim.g.molten_virt_text_output = true
end
end,
pattern = { "*.qmd", "*.md", "*.ipynb" },
callback = function(e)
if string.match(e.file, ".otter.") then
return
end
if require("molten.status").initialized() == "Molten" then
vim.fn.MoltenUpdateOption("virt_lines_off_by_1", true)
vim.fn.MoltenUpdateOption("virt_text_output", true)
else
vim.g.molten_virt_lines_off_by_1 = true
vim.g.molten_virt_text_output = true
end
end,
})
-- automatically export output chunks to a jupyter notebook on write
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = { "*.ipynb" },
callback = function()
if require("molten.status").initialized() == "Molten" then
vim.cmd("MoltenExportOutput!")
end
end,
pattern = { "*.ipynb" },
callback = function()
if require("molten.status").initialized() == "Molten" then
vim.cmd("MoltenExportOutput!")
end
end,
})
-- automatically import output chunks from a jupyter notebook
-- tries to find a kernel that matches the kernel in the jupyter notebook
-- falls back to a kernel that matches the name of the active venv (if any)
local imb = function(e) -- init molten buffer
vim.schedule(function()
local kernels = vim.fn.MoltenAvailableKernels()
local try_kernel_name = function()
local metadata = vim.json.decode(io.open(e.file, "r"):read("a"))["metadata"]
return metadata.kernelspec.name
end
local ok, kernel_name = pcall(try_kernel_name)
if not ok or not vim.tbl_contains(kernels, kernel_name) then
kernel_name = nil
local venv = os.getenv("VIRTUAL_ENV")
if venv ~= nil then
kernel_name = string.match(venv, "/.+/(.+)")
end
end
if kernel_name ~= nil and vim.tbl_contains(kernels, kernel_name) then
vim.cmd(("MoltenInit %s"):format(kernel_name))
end
vim.cmd("MoltenImportOutput")
end)
vim.schedule(function()
local kernels = vim.fn.MoltenAvailableKernels()
local try_kernel_name = function()
local metadata = vim.json.decode(io.open(e.file, "r"):read("a"))["metadata"]
return metadata.kernelspec.name
end
local ok, kernel_name = pcall(try_kernel_name)
if not ok or not vim.tbl_contains(kernels, kernel_name) then
kernel_name = nil
local venv = os.getenv("VIRTUAL_ENV")
if venv ~= nil then
kernel_name = string.match(venv, "/.+/(.+)")
end
end
if kernel_name ~= nil and vim.tbl_contains(kernels, kernel_name) then
vim.cmd(("MoltenInit %s"):format(kernel_name))
end
vim.cmd("MoltenImportOutput")
end)
end
-- automatically import output chunks from a jupyter notebook
vim.api.nvim_create_autocmd("BufAdd", {
pattern = { "*.ipynb" },
callback = imb,
pattern = { "*.ipynb" },
callback = imb,
})
-- we have to do this as well so that we catch files opened like nvim ./hi.ipynb
vim.api.nvim_create_autocmd("BufEnter", {
pattern = { "*.ipynb" },
callback = function(e)
if vim.api.nvim_get_vvar("vim_did_enter") ~= 1 then
imb(e)
end
end,
pattern = { "*.ipynb" },
callback = function(e)
if vim.api.nvim_get_vvar("vim_did_enter") ~= 1 then
imb(e)
end
end,
})

View File

@@ -1,16 +1,17 @@
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.prettierd,
null_ls.builtins.formatting.shfmt,
null_ls.builtins.formatting.black,
null_ls.builtins.diagnostics.mypy.with({
extra_args = function()
local virtual = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") or "/usr"
return { "--python-executable", virtual .. "/bin/python3" }
end,
}),
},
sources = {
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.prettierd,
null_ls.builtins.formatting.shfmt,
null_ls.builtins.formatting.black,
null_ls.builtins.diagnostics.mypy.with({
extra_args = function()
-- Let's resolve the virtual environment or conda environment
local virtual = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") or "/usr"
return { "--python-executable", virtual .. "/bin/python3" }
end,
}),
},
})

View File

@@ -1,23 +1,43 @@
local telescope = require("telescope")
local builtin = require("telescope.builtin")
local trouble = require("trouble.providers.telescope")
local trouble = require("trouble.sources.telescope")
telescope.setup({
defaults = {
mappings = {
i = {
["<C-q>"] = trouble.open_with_trouble,
},
n = {
["<C-q>"] = trouble.open_with_trouble,
},
},
},
defaults = {
vimgrep_arguments = {
"rg",
"--color=never",
"--no-heading",
"--with-filename",
"--line-number",
"--column",
"--smart-case",
},
mappings = {
i = {
["<C-q>"] = trouble.open,
},
n = {
["<C-q>"] = trouble.open,
},
},
},
})
vim.keymap.set("n", "<leader>pf", builtin.find_files, { desc = "Fuzzy find files in cwd" })
telescope.load_extension("flutter")
telescope.load_extension("dap")
local find_files = function()
builtin.find_files({
find_command = { "rg", "--files", "--hidden", "--glob", "!.git" },
})
end
vim.keymap.set("n", "<leader>pf", find_files, { desc = "Fuzzy find files in cwd" })
vim.keymap.set("n", "<leader>pr", builtin.oldfiles, { desc = "Fuzzy find recent files" })
vim.keymap.set("n", "<C-p>", builtin.git_files, { desc = "Fuzzy find files in git in cwd" })
vim.keymap.set("n", "<leader>ps", function()
builtin.grep_string({ search = vim.fn.input("Grep > ") })
builtin.grep_string({ search = vim.fn.input("Grep > ") })
end, { desc = "Find string under cursor in cwd" })

View File

@@ -1,8 +1,8 @@
local tsj = require("treesj")
tsj.setup({
use_default_keymaps = false,
max_join_length = 400,
use_default_keymaps = false,
max_join_length = 1000,
})
local opts = { silent = true, noremap = true }

View File

@@ -1,20 +1,20 @@
local telescope = require("telescope")
local actions = require("telescope.actions")
local trouble_telescope = require("trouble.providers.telescope")
local trouble_sources = require("trouble.sources.telescope")
telescope.setup({
defaults = {
mappings = {
i = {
["<C-t>"] = trouble_telescope.open_with_trouble,
["<C-q>"] = actions.send_to_qflist,
},
n = {
["<C-t>"] = trouble_telescope.open_with_trouble,
["<C-q>"] = actions.send_to_qflist,
},
},
},
defaults = {
mappings = {
i = {
["<C-t>"] = trouble_sources.open,
["<C-q>"] = actions.send_to_qflist,
},
n = {
["<C-t>"] = trouble_sources.open,
["<C-q>"] = actions.send_to_qflist,
},
},
},
})
-- Keybindings

View File

@@ -18,6 +18,11 @@ vim.opt.backup = false
vim.opt.hlsearch = false
vim.opt.incsearch = true
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.backspace = "indent,eol,start"
vim.opt.termguicolors = true
vim.opt.scrolloff = 8
@@ -32,27 +37,27 @@ vim.g.mapleader = " "
vim.g.maplocalleader = ";"
vim.opt.guicursor = "n-v-c:block,i-ci-ve:block,r-cr:hor20,o:hor50,"
.. "a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor,"
.. "sm:block-blinkwait175-blinkoff150-blinkon175"
.. "a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor,"
.. "sm:block-blinkwait175-blinkoff150-blinkon175"
-- Function to change cursor color
local function set_cursor_color(color)
vim.api.nvim_set_hl(0, "Cursor", { fg = color, bg = color })
vim.api.nvim_set_hl(0, "Cursor", { fg = color, bg = color })
end
-- Autocommands to change cursor color based on mode
vim.api.nvim_create_autocmd("InsertEnter", {
pattern = "*",
callback = function()
set_cursor_color("#ffffff") -- Red in insert mode
end,
pattern = "*",
callback = function()
set_cursor_color("#ffffff") -- Red in insert mode
end,
})
vim.api.nvim_create_autocmd("InsertLeave", {
pattern = "*",
callback = function()
set_cursor_color("#7DF9FF") -- Blue in visual mode
end,
pattern = "*",
callback = function()
set_cursor_color("#7DF9FF") -- Blue in visual mode
end,
})
-- Add similar autocommands for other modes as needed

View File

@@ -3,11 +3,12 @@ return {
dependencies = {
-- "theHamsta/nvim-dap-virtual-text",
"rcarriga/nvim-dap-ui",
-- "nvim-telescope/telescope-dap.nvim",
"nvim-neotest/nvim-nio",
"nvim-telescope/telescope-dap.nvim",
{ "mfussenegger/nvim-dap-python", ft = "python", dependencies = { "mfussenegger/nvim-dap" } },
-- "Pocco81/DAPInstall.nvim"
},
config = function()
require("absolute.after.dap")
end
end,
}

View File

@@ -0,0 +1,11 @@
return {
'akinsho/flutter-tools.nvim',
lazy = false,
dependencies = {
'nvim-lua/plenary.nvim',
'stevearc/dressing.nvim', -- optional for vim.ui.select
},
config = function()
require("absolute.after.flutter-tools")
end,
}

View File

@@ -3,6 +3,8 @@ return {
version = "^1.0.0", -- use version <2.0.0 to avoid breaking changes
dependencies = { "3rd/image.nvim" },
build = ":UpdateRemotePlugins",
lazy = true,
ft = "py",
init = function()
vim.g.molten_auto_open_output = false
vim.g.molten_wrap_output = true

View File

@@ -1,5 +1,7 @@
return {
"petobens/poet-v",
lazy = true,
ft = "py",
config = function()
require("absolute.after.poet-v")
end,

View File

@@ -1,17 +1,17 @@
return {
"christoomey/vim-tmux-navigator",
cmd = {
"TmuxNavigateLeft",
"TmuxNavigateDown",
"TmuxNavigateUp",
"TmuxNavigateRight",
-- "TmuxNavigatePrevious",
},
keys = {
{ "<C-h>", "<cmd><C-U>TmuxNavigateLeft<CR>" },
{ "<C-j>", "<cmd><C-U>TmuxNavigateDown<CR>" },
{ "<C-k>", "<cmd><C-U>TmuxNavigateUp<CR>" },
{ "<C-l>", "<cmd><C-U>TmuxNavigateRight<CR>" },
-- { "<C-\\>", "<cmd><C-U>TmuxNavigatePrevious<CR>" },
},
"christoomey/vim-tmux-navigator",
cmd = {
"TmuxNavigateLeft",
"TmuxNavigateDown",
"TmuxNavigateUp",
"TmuxNavigateRight",
"TmuxNavigatePrevious",
},
keys = {
{ "<C-h>", "<cmd><C-U>TmuxNavigateLeft<CR>" },
{ "<C-j>", "<cmd><C-U>TmuxNavigateDown<CR>" },
{ "<C-k>", "<cmd><C-U>TmuxNavigateUp<CR>" },
{ "<C-l>", "<cmd><C-U>TmuxNavigateRight<CR>" },
{ "<C-\\>", "<cmd><C-U>TmuxNavigatePrevious<CR>" },
},
}

View File

@@ -62,18 +62,20 @@ vim.keymap.set("i", "<C-c>", "<Esc>", opts)
opts.desc = "Disable Q - Nothing Good Ever Happens"
vim.keymap.set("n", "Q", "<nop>", opts)
-- Format document with LSP Formatter
opts.desc = "Format document with LSP Formatter"
vim.keymap.set("n", "<leader>f", vim.lsp.buf.format, opts)
-- Navigation Quick Fixes
--
-- vim.keymap.set("n", "<C-k>", "<cmd>cnext<CR>zz", opts)
-- vim.keymap.set("n", "<C-j>", "<cmd>cprev<CR>zz", opts)
-- vim.keymap.set("n", "<leader>k", "<cmd>lnext<CR>zz", opts)
-- vim.keymap.set("n", "<leader>j", "<cmd>lprev<CR>zz", opts)
--
opts.desc = "Jump up and center screen"
vim.keymap.set("n", "<C-k>", "<cmd>cnext<CR>zz", opts)
opts.desc = "Jump down and center screen"
vim.keymap.set("n", "<C-j>", "<cmd>cprev<CR>zz", opts)
opts.desc = "Jump to next location and center screen"
vim.keymap.set("n", "<leader>k", "<cmd>lnext<CR>zz", opts)
opts.desc = "Jump to previous location and center screen"
vim.keymap.set("n", "<leader>j", "<cmd>lprev<CR>zz", opts)
-- Search Regex Keymap
opts.desc = "Regex Replace"
@@ -85,20 +87,39 @@ vim.keymap.set("v", "<leader>ss", [[:s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><
-- Source File Keymap
opts.desc = "Source File"
vim.keymap.set("n", "<leader><leader>", function()
-- Only source these file extensions
local allowed_extensions = [[".vim", ".lua", ".vimrc", ".gvimrc", ".nvim", ".nvimrc", ".sh"]]
-- Only source these file extensions
local allowed_extensions = [[".vim", ".lua", ".vimrc", ".gvimrc", ".nvim", ".nvimrc", ".sh"]]
-- Get the file extension
local file_extension = vim.fn.expand("%:e")
-- Get the file extension
local file_extension = vim.fn.expand("%:e")
-- Check if the file extension is allowed
if string.find(allowed_extensions, file_extension) then
vim.cmd("so %")
else
print("Filetype not supported")
end
-- Check if the file extension is allowed
if string.find(allowed_extensions, file_extension) then
vim.cmd("so %")
else
print("Filetype not supported")
end
end, opts)
-- Manage VIM Maximizer
opts.desc = "Toggle TMUX Pane"
vim.keymap.set("n", "<leader>`", "<cmd>NvimTreeToggle<CR>", opts)
-- Optimize Window Resize
-- Resize Window Right
opts.desc = "Resize Window Right"
vim.keymap.set("n", "<leader>l", "<C-w>10>", opts)
-- Resize Window Left
opts.desc = "Resize Window Left"
vim.keymap.set("n", "<leader>h", "<C-w>10<", opts)
-- Resize Window Up
opts.desc = "Resize Window Up"
vim.keymap.set("n", "<leader>k", "<C-w>10-", opts)
-- Resize Window Down
opts.desc = "Resize Window Down"
vim.keymap.set("n", "<leader>j", "<C-w>10+", opts)

View File

@@ -0,0 +1,15 @@
function SafeInvoke(func)
-- safely invoke a functions
-- if the function returns an error, return an empty string
-- otherwise return the result of the function
local ok, result = pcall(func)
if ok then
return result
else
return ""
end
end
return SafeInvoke