Changed flake8 to ruff

This commit is contained in:
Kristofers Solo 2023-04-23 19:32:32 +03:00
parent ab213ef300
commit a7e28fe683
17 changed files with 214 additions and 44 deletions

View File

@ -6,6 +6,7 @@ require("user.autocommands")
require("user.cmp") require("user.cmp")
require("user.cmp_gh_source") require("user.cmp_gh_source")
require("user.telescope") require("user.telescope")
require("user.todo")
require("user.treesitter") require("user.treesitter")
require("user.autopairs") require("user.autopairs")
require("user.comment") require("user.comment")
@ -27,3 +28,4 @@ require("user.crates")
require("user.colorizer") require("user.colorizer")
require("user.luasnip") require("user.luasnip")
require("user.autosave") require("user.autosave")
require("user.persistence")

View File

@ -4,8 +4,9 @@ if not status_ok then
end end
local dashboard = require("alpha.themes.dashboard") local dashboard = require("alpha.themes.dashboard")
dashboard.section.header.val = {
local function header()
return {
[[ ___ ]], [[ ___ ]],
[[ /\_ \ __ ]], [[ /\_ \ __ ]],
[[ ____ ___\//\ \ ___ __ __ /\_\ ___ ___ ]], [[ ____ ___\//\ \ ___ __ __ /\_\ ___ ___ ]],
@ -14,20 +15,28 @@ dashboard.section.header.val = {
[[\/\____/\ \____//\____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]], [[\/\____/\ \____//\____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]],
[[ \/___/ \/___/ \/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]], [[ \/___/ \/___/ \/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]],
} }
end
dashboard.section.buttons.val = {
dashboard.button("f", "" .. " Find file", ":Telescope find_files <cr>"),
dashboard.button("e", "" .. " New file", ":ene <BAR> startinsert <cr>"),
dashboard.button("p", "" .. " Find project", ":lua require('telescope').extensions.projects.projects()<cr>"),
dashboard.button("r", "" .. " Recent files", ":Telescope oldfiles <cr>"),
dashboard.button("t", "" .. " Find text", ":Telescope live_grep <cr>"),
dashboard.button("c", "" .. " Config", ":e ~/.config/nvim/init.lua <cr>"),
dashboard.button("q", "" .. " Quit", ":qa<cr>"),
}
local function footer() local function footer()
return "kristofers.xyz" return "kristofers.xyz"
end end
dashboard.section.header.val = header()
dashboard.section.buttons.val = {
dashboard.button("f", "" .. " Find file", "<cmd>Telescope find_files <cr>"),
dashboard.button("e", "" .. " New file", "<cmd>ene <BAR> startinsert <cr>"),
dashboard.button("p", "" .. " Persistence", "<cmd>lua require('persistence').load()<cr>"),
dashboard.button("r", "" .. " Recent files", "<cmd>Telescope oldfiles <cr>"),
dashboard.button("t", "" .. " Find text", "<cmd>Telescope live_grep <cr>"),
dashboard.button(
"P",
"" .. " Find project",
"<cmd>lua require('telescope').extensions.projects.projects()<cr>"
),
dashboard.button("g", "" .. " Git", "<cmd>lua _LAZYGIT_TOGGLE()<cr>"),
dashboard.button("c", "" .. " Config", "<cmd>e ~/.config/nvim/init.lua <cr>"),
dashboard.button("q", "" .. " Quit", "<cmd>qa<cr>"),
}
dashboard.section.footer.val = footer() dashboard.section.footer.val = footer()
dashboard.section.footer.opts.hl = "Type" dashboard.section.footer.opts.hl = "Type"

View File

@ -48,7 +48,6 @@ vim.api.nvim_create_autocmd({ "TextYankPost" }, {
vim.api.nvim_create_autocmd({ "BufWritePre" }, { vim.api.nvim_create_autocmd({ "BufWritePre" }, {
callback = function() callback = function()
vim.lsp.buf.format() vim.lsp.buf.format()
-- vim.lsp.buf.format({ async = true })
end, end,
}) })
@ -59,6 +58,15 @@ vim.api.nvim_create_autocmd({ "InsertEnter" }, {
end, end,
}) })
-- Disable `expandtab` (don't replace tab with spaces) for lua files
vim.api.nvim_create_autocmd({ "FileType" }, {
pattern = { "lua" },
callback = function()
vim.opt_local.expandtab = false
end,
})
-- Set tab size for the following file types to 2
vim.api.nvim_create_autocmd({ "FileType" }, { vim.api.nvim_create_autocmd({ "FileType" }, {
pattern = { "vimwiki", "java", "sql" }, pattern = { "vimwiki", "java", "sql" },
callback = function() callback = function()

View File

@ -4,7 +4,7 @@ if not status_ok then
end end
colorizer.setup({ colorizer.setup({
filetypes = { "html", "css", "js" }, filetypes = { "html", "css", "js", "lua", "yaml", "conf", "toml" },
user_default_options = { user_default_options = {
RGB = true, -- #RGB hex codes RGB = true, -- #RGB hex codes
RRGGBB = true, -- #RRGGBB hex codes RRGGBB = true, -- #RRGGBB hex codes
@ -29,6 +29,6 @@ colorizer.setup({
}, },
-- all the sub-options of filetypes apply to buftypes -- all the sub-options of filetypes apply to buftypes
buftypes = {}, buftypes = {},
-- html = { names = true }, html = { names = true },
-- css = { names = true }, css = { names = true },
}) })

View File

@ -33,8 +33,8 @@ keymap("n", "<C-Left>", ":vertical resize -2<cr>", opts)
keymap("n", "<C-Right>", ":vertical resize +2<cr>", opts) keymap("n", "<C-Right>", ":vertical resize +2<cr>", opts)
-- -- Navigate buffers -- -- Navigate buffers
-- keymap("n", "<S-l>", ":bnext<cr>", opts) keymap("n", "<S-l>", ":bnext<cr>", opts)
-- keymap("n", "<S-h>", ":bprevious<cr>", opts) keymap("n", "<S-h>", ":bprevious<cr>", opts)
-- Better paste -- Better paste
keymap("v", "p", '"_dP', opts) keymap("v", "p", '"_dP', opts)

View File

@ -89,8 +89,41 @@ end
ls.add_snippets(nil, { ls.add_snippets(nil, {
all = {}, all = {},
lua = {}, lua = {
rust = {}, s(
"status",
fmt(
[[
local status_ok, {} = pcall(require, "{}")
if not status_ok then
return
end
]],
{
i(1),
same(1),
}
)
),
},
rust = {
s(
"modtest",
fmt(
[[
#[cfg(test)]
mod test {{
{}
{}
}}
]],
{
c(1, { t(" use super::*"), t("") }),
i(0),
}
)
),
},
python = {}, python = {},
cpp = { cpp = {
s( s(

View File

@ -23,7 +23,7 @@ M.setup = function()
end end
local config = { local config = {
virtual_text = false, -- disable virtual text virtual_text = true, -- virtual text
signs = { signs = {
active = signs, -- show signs active = signs, -- show signs
}, },
@ -55,12 +55,11 @@ local function lsp_keymaps(bufnr)
local opts = { noremap = true, silent = true } local opts = { noremap = true, silent = true }
local keymap = vim.api.nvim_buf_set_keymap local keymap = vim.api.nvim_buf_set_keymap
keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<cr>", opts) keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<cr>", opts)
keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<cr>", opts) keymap(bufnr, "n", "gd", "<cmd>lua require('telescope.builtin').lsp_definitions()<cr>", opts)
keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<cr>", opts) keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<cr>", opts)
keymap(bufnr, "n", "gI", "<cmd>lua vim.lsp.buf.implementation()<cr>", opts) keymap(bufnr, "n", "gI", "<cmd>lua vim.lsp.buf.implementation()<cr>", opts)
keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<cr>", opts) keymap(bufnr, "n", "gr", "<cmd>lua require('telescope.builtin').lsp_references()<cr>", opts)
keymap(bufnr, "n", "gl", "<cmd>lua vim.diagnostic.open_float()<cr>", opts) keymap(bufnr, "n", "gl", "<cmd>lua vim.diagnostic.open_float()<cr>", opts)
vim.cmd([[command! Format execute "lua vim.lsp.buf.format()"]])
end end
M.on_attach = function(client, bufnr) M.on_attach = function(client, bufnr)

View File

@ -23,11 +23,11 @@ local servers = {
"jsonls", "jsonls",
"lua_ls", "lua_ls",
"phpactor", "phpactor",
"ruff_lsp",
"rust_analyzer", "rust_analyzer",
"taplo", "taplo",
"texlab", "texlab",
"tsserver", "tsserver",
"yamlls",
} }
mason.setup() mason.setup()

View File

@ -16,7 +16,6 @@ mason_null_ls.setup({
"codespell", "codespell",
"cpplint", "cpplint",
"djlint", "djlint",
"flake8",
"gitlint", "gitlint",
"html_lint", "html_lint",
"isort", "isort",
@ -45,7 +44,6 @@ null_ls.setup({
sources = { sources = {
diagnostics.codespell, diagnostics.codespell,
diagnostics.cpplint, diagnostics.cpplint,
diagnostics.flake8,
diagnostics.luacheck.with({ diagnostics.luacheck.with({
extra_args = { extra_args = {
"--globals", "--globals",
@ -54,7 +52,6 @@ null_ls.setup({
}), }),
diagnostics.misspell, diagnostics.misspell,
diagnostics.mypy, diagnostics.mypy,
-- diagnostics.phpcs,
formatting.autopep8, formatting.autopep8,
formatting.beautysh, formatting.beautysh,
formatting.clang_format, formatting.clang_format,

View File

@ -31,7 +31,7 @@ local options = {
laststatus = 3, laststatus = 3,
showcmd = false, showcmd = false,
ruler = false, ruler = false,
numberwidth = 4, -- set number column width to 2 {default 4} numberwidth = 4, -- set number column width to 4 {default 4}
signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time
wrap = false, -- display lines as one long line wrap = false, -- display lines as one long line
scrolloff = 8, -- is one of my fav scrolloff = 8, -- is one of my fav

10
lua/user/persistence.lua Normal file
View File

@ -0,0 +1,10 @@
local status_ok, persistence = pcall(require, "persistence")
if not status_ok then
return
end
persistence.setup({
dir = vim.fn.expand(vim.fn.stdpath("state") .. "/sessions/"), -- directory where session files are saved
options = { "buffers", "curdir", "tabpages", "winsize" }, -- sessionoptions used for saving
pre_save = nil, -- a function to call before saving the session
})

View File

@ -40,7 +40,6 @@ packer.init({
-- Install your plugins here -- Install your plugins here
return packer.startup(function(use) return packer.startup(function(use)
-- My plugins here
use("wbthomason/packer.nvim") -- Have packer manage itself use("wbthomason/packer.nvim") -- Have packer manage itself
use("nvim-lua/plenary.nvim") -- Useful lua functions used by lots of plugins use("nvim-lua/plenary.nvim") -- Useful lua functions used by lots of plugins
use("windwp/nvim-autopairs") -- Autopairs, integrates with both cmp and treesitter use("windwp/nvim-autopairs") -- Autopairs, integrates with both cmp and treesitter
@ -56,12 +55,19 @@ return packer.startup(function(use)
use("lewis6991/impatient.nvim") use("lewis6991/impatient.nvim")
use("lukas-reineke/indent-blankline.nvim") use("lukas-reineke/indent-blankline.nvim")
use("goolord/alpha-nvim") use("goolord/alpha-nvim")
use("folke/which-key.nvim")
use("andweeb/presence.nvim") use("andweeb/presence.nvim")
use("NvChad/nvim-colorizer.lua") use("NvChad/nvim-colorizer.lua")
use("alvan/vim-closetag") use("alvan/vim-closetag")
use("tpope/vim-surround") use("tpope/vim-surround")
use("folke/which-key.nvim")
use("folke/todo-comments.nvim")
use({
"folke/persistence.nvim",
event = "BufReadPre", -- this will only start session saving when an actual file was opened
module = "persistence",
})
-- Colorschemes -- Colorschemes
use("lunarvim/darkplus.nvim") use("lunarvim/darkplus.nvim")
use("Mofiqul/dracula.nvim") use("Mofiqul/dracula.nvim")
@ -107,6 +113,8 @@ return packer.startup(function(use)
use({ "nvim-telescope/telescope.nvim", run = ":TSUpdate" }) use({ "nvim-telescope/telescope.nvim", run = ":TSUpdate" })
use({ "nvim-telescope/telescope-fzf-native.nvim", run = "make" }) use({ "nvim-telescope/telescope-fzf-native.nvim", run = "make" })
use("nvim-telescope/telescope-media-files.nvim") use("nvim-telescope/telescope-media-files.nvim")
use("xiyaowong/telescope-emoji.nvim")
use("nvim-telescope/telescope-frecency.nvim")
-- Treesitter -- Treesitter
use("nvim-treesitter/nvim-treesitter") use("nvim-treesitter/nvim-treesitter")

View File

@ -6,7 +6,7 @@ project.setup({
-- detection_methods = { "lsp", "pattern" }, -- NOTE: lsp detection will get annoying with multiple langs in one project -- detection_methods = { "lsp", "pattern" }, -- NOTE: lsp detection will get annoying with multiple langs in one project
detection_methods = { "pattern" }, detection_methods = { "pattern" },
-- patterns used to detect root dir, when **"pattern"** is in detection_methods -- patterns used to detect root dir, when **"pattern"** is in detection_methods
patterns = { ".git", "Makefile", "package.json", ".venv" }, patterns = { ".git", "Makefile", "package.json", ".venv", "Cargo.toml", "requirements.txt" },
}) })
local tele_status_ok, telescope = pcall(require, "telescope") local tele_status_ok, telescope = pcall(require, "telescope")

View File

@ -7,12 +7,10 @@ local actions = require("telescope.actions")
telescope.setup({ telescope.setup({
defaults = { defaults = {
prompt_prefix = "", prompt_prefix = "",
selection_caret = "", selection_caret = "",
path_display = { "smart" }, path_display = { "smart" },
file_ignore_patterns = { ".git/", "node_modules" }, file_ignore_patterns = { ".git/", "node_modules" },
mappings = { mappings = {
i = { i = {
["<Down>"] = actions.cycle_history_next, ["<Down>"] = actions.cycle_history_next,
@ -22,4 +20,33 @@ telescope.setup({
}, },
}, },
}, },
extensions = {
fzf = {
fuzzy = true, -- false will only do exact matching
override_generic_sorter = true, -- override the generic sorter
override_file_sorter = true, -- override the file sorter
case_mode = "smart_case", -- or "ignore_case" or "respect_case"
},
media_files = {
-- filetypes whitelist
filetypes = { "png", "webp", "jpg", "jpeg", "mp4", "webm" },
find_cmd = "rg",
},
emoji = {
action = function(emoji)
-- argument emoji is a table.
-- {name="", value="", cagegory="", description=""}
vim.fn.setreg("*", emoji.value)
print([[Press p or "*p to paste this emoji]] .. emoji.value)
-- insert emoji when picked
-- vim.api.nvim_put({ emoji.value }, 'c', false, true)
end,
},
},
}) })
telescope.load_extension("fzf")
telescope.load_extension("media_files")
telescope.load_extension("emoji")

69
lua/user/todo.lua Normal file
View File

@ -0,0 +1,69 @@
local status_ok, todo = pcall(require, "todo-comments")
if not status_ok then
return
end
todo.setup({
signs = true, -- show icons in the signs column
sign_priority = 8, -- sign priority
-- keywords recognized as todo comments
keywords = {
FIX = {
icon = "", -- icon used for the sign, and in search results
color = "error", -- can be a hex color, or a named color (see below)
alt = { "FIXME", "BUG", "FIXIT", "ISSUE" }, -- a set of other keywords that all map to this FIX keywords
-- signs = false, -- configure signs for some keywords individually
},
TODO = { icon = "", color = "info" },
HACK = { icon = "", color = "warning" },
WARN = { icon = "", color = "warning", alt = { "WARNING", "XXX" } },
PERF = { icon = "", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } },
NOTE = { icon = "", color = "hint", alt = { "INFO" } },
TEST = { icon = "", color = "test", alt = { "TESTING", "PASSED", "FAILED" } },
},
gui_style = {
fg = "NONE", -- The gui style to use for the fg highlight group.
bg = "BOLD", -- The gui style to use for the bg highlight group.
},
merge_keywords = true, -- when true, custom keywords will be merged with the defaults
-- highlighting of the line containing the todo comment
-- * before: highlights before the keyword (typically comment characters)
-- * keyword: highlights of the keyword
-- * after: highlights after the keyword (todo text)
highlight = {
multiline = true, -- enable multine todo comments
multiline_pattern = "^.", -- lua pattern to match the next multiline from the start of the matched keyword
multiline_context = 10, -- extra lines that will be re-evaluated when changing a line
before = "", -- "fg" or "bg" or empty
keyword = "wide", -- "fg", "bg", "wide", "wide_bg", "wide_fg" or empty. (wide and wide_bg is the same as bg, but will also highlight surrounding characters, wide_fg acts accordingly but with fg)
after = "fg", -- "fg" or "bg" or empty
pattern = [[.*<(KEYWORDS)\s*:]], -- pattern or table of patterns, used for highlighting (vim regex)
comments_only = true, -- uses treesitter to match keywords in comments only
max_line_len = 400, -- ignore lines longer than this
exclude = {}, -- list of file types to exclude highlighting
},
-- list of named colors where we try to extract the guifg from the
-- list of highlight groups or use the hex color if hl not found as a fallback
colors = {
error = { "DiagnosticError", "ErrorMsg", "#DC2626" },
warning = { "DiagnosticWarn", "WarningMsg", "#FBBF24" },
info = { "DiagnosticInfo", "#2563EB" },
hint = { "DiagnosticHint", "#10B981" },
default = { "Identifier", "#7C3AD" },
test = { "Identifier", "#FF00FF" },
},
search = {
command = "rg",
args = {
"--color=never",
"--no-heading",
"--with-filename",
"--line-number",
"--column",
},
-- regex that will be used to match keywords.
-- don't replace the (KEYWORDS) placeholder
pattern = [[\b(KEYWORDS):]], -- ripgrep regex
-- pattern = [[\b(KEYWORDS)\b]], -- match without the extra colon. You'll likely get false positives
},
})

View File

@ -209,6 +209,8 @@ local mappings = {
t = { "<cmd>Telescope live_grep<cr>", "Text" }, t = { "<cmd>Telescope live_grep<cr>", "Text" },
k = { "<cmd>Telescope keymaps<cr>", "Keymaps" }, k = { "<cmd>Telescope keymaps<cr>", "Keymaps" },
C = { "<cmd>Telescope commands<cr>", "Commands" }, C = { "<cmd>Telescope commands<cr>", "Commands" },
T = { "<cmd>TodoTelescope<cr>", "Todo" },
m = { "<cmd>lua require('telescope').extensions.media_files.media_files()<cr>", "Media" },
p = { p = {
"<cmd>lua require('telescope.builtin').colorscheme({enable_preview = true})<cr>", "<cmd>lua require('telescope.builtin').colorscheme({enable_preview = true})<cr>",
"Colorscheme with Preview", "Colorscheme with Preview",
@ -259,6 +261,12 @@ local mappings = {
T = { "<cmd>lua require('dap').terminate()<cr>", "Terminate" }, T = { "<cmd>lua require('dap').terminate()<cr>", "Terminate" },
l = { "<cmd>lua require('dap').run_last()<cr>", "Run last" }, l = { "<cmd>lua require('dap').run_last()<cr>", "Run last" },
}, },
q = {
name = "Persistence",
s = { "<cmd>lua require('persistence').load()<cr>", "Current directory" },
l = { "<cmd>lua require('persistence').load({ last = true })<cr>", "Last session" },
d = { "<cmd>lua require('persistence').stop()<cr>", "Stop" },
},
} }
which_key.setup(setup) which_key.setup(setup)