From 9b9cd7cd41cb33d66101c366226a38c0cd8cff18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Mendelski?= Date: Tue, 5 Sep 2023 22:05:03 +0200 Subject: [PATCH] hard to say - too much changes --- .../{rust-analyzer => rust-analyzer-bak} | 0 nvim/.nvim/lua/plugin/comments.lua | 1 + nvim/.nvim/lua/plugin/lsp/config.lua | 78 +++++++++---------- nvim/.nvim/lua/plugin/lsp/on-attach.lua | 14 ++-- nvim/.nvim/lua/plugin/null-ls.lua | 2 +- nvim/.nvim/lua/plugin/nvim-cmp.lua | 39 +++++----- nvim/.nvim/lua/plugin/rust-tools.lua | 21 ++++- nvim/.nvim/lua/plugin/telescope.lua | 1 - nvim/.nvim/lua/plugin/tree/on-attach.lua | 5 +- nvim/.nvim/lua/plugins.lua | 27 ++----- nvim/deps/docker.sh | 4 +- nvim/deps/frontend.sh | 3 +- nvim/deps/go.sh | 4 +- nvim/deps/lua.sh | 2 +- nvim/deps/rust.sh | 18 ++++- nvim/deps/toml.sh | 19 +++++ 16 files changed, 139 insertions(+), 99 deletions(-) rename bash/.bash/scripts/{rust-analyzer => rust-analyzer-bak} (100%) create mode 100755 nvim/deps/toml.sh diff --git a/bash/.bash/scripts/rust-analyzer b/bash/.bash/scripts/rust-analyzer-bak similarity index 100% rename from bash/.bash/scripts/rust-analyzer rename to bash/.bash/scripts/rust-analyzer-bak diff --git a/nvim/.nvim/lua/plugin/comments.lua b/nvim/.nvim/lua/plugin/comments.lua index 88d1fcc..f901315 100644 --- a/nvim/.nvim/lua/plugin/comments.lua +++ b/nvim/.nvim/lua/plugin/comments.lua @@ -29,6 +29,7 @@ local htmlComments = vim.tbl_extend("force", baseConfig, { config.configure_language("conf", hashComments) config.configure_language("makefile", hashComments) +config.configure_language("make", hashComments) config.configure_language("dockerfile", hashComments) config.configure_language("yaml", hashComments) config.configure_language("tmux", hashComments) diff --git a/nvim/.nvim/lua/plugin/lsp/config.lua b/nvim/.nvim/lua/plugin/lsp/config.lua index 9f7d9a4..5f3a38d 100644 --- a/nvim/.nvim/lua/plugin/lsp/config.lua +++ b/nvim/.nvim/lua/plugin/lsp/config.lua @@ -63,12 +63,10 @@ for type, icon in pairs(signs) do end -- Bash --- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#bashls -- npm i -g bash-language-server lspconfig.bashls.setup(config()) -- css, scss, less, html, json --- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#cssls -- npm i -g vscode-langservers-extracted lspconfig.cssls.setup(config()) lspconfig.html.setup(config()) @@ -80,36 +78,60 @@ lspconfig.yamlls.setup(config({ }, }, })) +lspconfig.tailwindcss.setup(config({ + filetypes = { + -- "rust", + "aspnetcorerazor", + "django-html", + "htmldjango", + "edge", + "eelixir", + "elixir", + "gohtml", + "handlebars", + "hbs", + "html", + "liquid", + "markdown", + "mdx", + "mustache", + "njk", + "nunjucks", + "php", + "twig", + "css", + "less", + "postcss", + "sass", + "scss", + "stylus", + "javascript", + "javascriptreact", + "typescript", + "typescriptreact", + "vue", + "svelte", + }, +})) -- Eslint --- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.txt#eslint -- go install github.com/mattn/efm-langserver@latest -- npm install -g eslint_d lspconfig.eslint.setup(config()) -- Docker --- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#dockerls -- npm i -g dockerfile-language-server-nodejs lspconfig.dockerls.setup(config()) -- GraphQL --- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#graphql -- npm i -g graphql-language-service-cli lspconfig.graphql.setup(config()) --- Groovy --- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#groovyls --- https://github.com/prominic/groovy-language-server.git --- lspconfig.groovyls.setup(config({ --- cmd = { vim.fn.expand("~/.nvim/lang/groovy/run.sh") }, --- })) - -- Go require("plugin/lsp/lang/go").setup(config) -- Rust -- Handled by rust-tools - -- lspconfig.rust_analyzer.setup(lsconfig({ -- settings = { -- -- Add clippy warnings to rust-anayzer @@ -136,53 +158,27 @@ require("plugin/lsp/lang/go").setup(config) -- }, -- })) --- Java --- java-language-server is unmaintained, migrated to jdtls --- https://github.com/georgewfraser/java-language-server --- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#java_language_server --- lspconfig.java_language_server.setup(config({ --- cmd = { data_dir .. "/lang-servers/java-language-server/dist/lang_server_linux.sh" }, --- })) - --- Kotlin --- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#kotlin_language_server --- https://github.com/fwcd/kotlin-language-server --- lspconfig.kotlin_language_server.setup(config({ --- cmd = { vim.fn.expand("~/.nvim/lang/kotlin/bin/kotlin-language-server") }, --- })) - -- Python --- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#pyright --- https://github.com/microsoft/pyright -- npm i --global pyright lspconfig.pyright.setup(config()) -- SQL --- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#sqlls --- https://github.com/joe-re/sql-language-server -- npm i -g sql-language-server lspconfig.sqlls.setup(config()) -- Svelte --- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#svelte --- https://github.com/sveltejs/language-tools/tree/master/packages/language-server -- npm i -g svelte-language-server lspconfig.svelte.setup(config()) -- Typescript --- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#tsserver --- https://github.com/theia-ide/typescript-language-server -- npm i -g typescript typescript-language-server lspconfig.tsserver.setup(config()) -- Vue --- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#vuels --- https://github.com/vuejs/vetur/tree/master/server -- npm i -g vls lspconfig.vuels.setup(config()) -- Stylelint --- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#stylelint_lsp -- npm i -g stylelint-lsp lspconfig.stylelint_lsp.setup(config({ filetypes = { @@ -192,6 +188,10 @@ lspconfig.stylelint_lsp.setup(config({ }, })) +-- Toml +-- cargo install --features lsp --locked taplo-cli +lspconfig.taplo.setup(config()) + -- Lua -- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#lua_ls -- https://github.com/luals/lua-language-server/wiki/Getting-Started#command-line diff --git a/nvim/.nvim/lua/plugin/lsp/on-attach.lua b/nvim/.nvim/lua/plugin/lsp/on-attach.lua index e3e8319..9053c19 100644 --- a/nvim/.nvim/lua/plugin/lsp/on-attach.lua +++ b/nvim/.nvim/lua/plugin/lsp/on-attach.lua @@ -24,6 +24,11 @@ local function diagnosticsOnHold(bufnr) vim.api.nvim_create_autocmd("CursorHold", { buffer = bufnr, callback = function() + for _, winid in pairs(vim.api.nvim_tabpage_list_wins(0)) do + if vim.api.nvim_win_get_config(winid).zindex then + return + end + end vim.diagnostic.open_float(nil, { focusable = false, close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, @@ -64,7 +69,7 @@ return function(client, bufnr) "lua vim.lsp.buf.clear_references() vim.lsp.buf.document_highlight()", opts ) - buf_set_keymap("n", prefix .. "t", "lua vim.lsp.buf.type_definition()", opts) + buf_set_keymap("n", prefix .. "T", "lua vim.lsp.buf.type_definition()", opts) buf_set_keymap("n", prefix .. "n", "lua vim.lsp.buf.rename()", opts) buf_set_keymap("n", prefix .. "a", "lua vim.lsp.buf.code_action()", opts) buf_set_keymap("n", prefix .. "r", "lua vim.lsp.buf.references()", opts) @@ -99,14 +104,11 @@ return function(client, bufnr) -- Save and format null_ls.configure_client(client, bufnr) local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype") - local supports_format = client.server_capabilities.documentFormattingProvider or null_ls.has_formatter(filetype) + local supports_format = client.server_capabilities.documentFormattingProvider ~= nil + or null_ls.has_formatter(filetype) if supports_format == true then buf_set_keymap("n", "", ":execute 'lua require(\"plugin/lsp/actions\").format()' | :w", opts) buf_set_keymap("i", "", ":execute 'lua require(\"plugin/lsp/actions\").format()' | :w", opts) buf_set_keymap("x", "", ":execute 'lua require(\"plugin/lsp/actions\").format()' | :w", opts) - else - buf_set_keymap("n", "", ":w", opts) - buf_set_keymap("i", "", ":w", opts) - buf_set_keymap("x", "", ":w", opts) end end diff --git a/nvim/.nvim/lua/plugin/null-ls.lua b/nvim/.nvim/lua/plugin/null-ls.lua index c8d1a0a..e7b327a 100644 --- a/nvim/.nvim/lua/plugin/null-ls.lua +++ b/nvim/.nvim/lua/plugin/null-ls.lua @@ -11,7 +11,7 @@ function M.config() -- formatting formatting.stylua, formatting.shfmt, - formatting.prettier, + formatting.prettier.with({ disabled_filetypes = { "yaml" }, extra_filetypes = { "toml" } }), -- liting diagnostics.golangci_lint, diagnostics.hadolint, diff --git a/nvim/.nvim/lua/plugin/nvim-cmp.lua b/nvim/.nvim/lua/plugin/nvim-cmp.lua index 32b1cd5..862fef4 100644 --- a/nvim/.nvim/lua/plugin/nvim-cmp.lua +++ b/nvim/.nvim/lua/plugin/nvim-cmp.lua @@ -61,7 +61,7 @@ cmp.setup({ [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then + elseif luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() elseif has_words_before() then cmp.mapping.complete() @@ -93,38 +93,23 @@ cmp.setup({ -- behavior = cmp.SelectBehavior.Select -- }), { 'i', 'c' }), }, + sorting = { + priority_weight = 10, + }, sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "path" }, { name = "luasnip" }, - }, { buffersrc }), + }), }) --- Lazy load rust crates completions -vim.api.nvim_exec( - [[ -autocmd FileType toml lua require('cmp').setup.buffer({ sources = { { name = 'crates' } } }) -]], - false -) - -- Set configuration for specific filetype. cmp.setup.filetype("gitcommit", { sources = cmp.config.sources({ { name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it. - }, { - buffersrc, }), }) --- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline({ "/", "?" }, { - mapping = cmp.mapping.preset.cmdline(), - sources = { - buffersrc, - }, -}) - -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline(":", { mapping = cmp.mapping.preset.cmdline(), @@ -134,3 +119,17 @@ cmp.setup.cmdline(":", { { name = "cmdline" }, }), }) + +-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline({ "/", "?" }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { buffersrc }, +}) + +-- Lazy load rust crates completions +vim.api.nvim_exec( + [[ +autocmd FileType toml lua require('cmp').setup.buffer({ sources = { { name = 'crates' } } }) +]], + false +) diff --git a/nvim/.nvim/lua/plugin/rust-tools.lua b/nvim/.nvim/lua/plugin/rust-tools.lua index 0959447..1b377c2 100644 --- a/nvim/.nvim/lua/plugin/rust-tools.lua +++ b/nvim/.nvim/lua/plugin/rust-tools.lua @@ -7,7 +7,8 @@ local liblldb_path = vim.fn.expand(extension_path .. "/lldb/lib/liblldb.*") -- local liblldb_path = extension_path .. '/lldb/lib/liblldb.so' -- linux require("rust-tools").setup({ - tools = { -- rust-tools options + tools = { + -- rust-tools options -- Automatically set inlay hints (type hints) autoSetHints = true, @@ -107,16 +108,28 @@ require("rust-tools").setup({ flags = { debounce_text_changes = 150 }, settings = { ["rust-analyzer"] = { - assist = { - importGranularity = "module", - importPrefix = "self", + completion = { postfix = { enable = false } }, + imports = { + granularity = { + group = "module", + }, + prefix = "self", }, cargo = { loadOutDirsFromCheck = true, + allFeatures = true, + buildScripts = { + enable = true, + }, }, procMacro = { enable = true, }, + diagnostics = { + enable = true, + disabled = { "unresolved-proc-macro" }, + experimental = { enable = false }, + }, checkOnSave = { allFeatures = true, overrideCommand = { diff --git a/nvim/.nvim/lua/plugin/telescope.lua b/nvim/.nvim/lua/plugin/telescope.lua index 3e2abaf..9b1f318 100644 --- a/nvim/.nvim/lua/plugin/telescope.lua +++ b/nvim/.nvim/lua/plugin/telescope.lua @@ -2,7 +2,6 @@ local _M = {} function _M.keymap() local map = require("util").keymap - map("n", "", "") map("n", "fx", ":Telescope") map("n", "f;", ":Telescope commands") map("n", "f:", ":Telescope command_history") diff --git a/nvim/.nvim/lua/plugin/tree/on-attach.lua b/nvim/.nvim/lua/plugin/tree/on-attach.lua index d624e1e..be0d57d 100644 --- a/nvim/.nvim/lua/plugin/tree/on-attach.lua +++ b/nvim/.nvim/lua/plugin/tree/on-attach.lua @@ -20,9 +20,10 @@ return function(bufnr) vim.keymap.set("n", "v", api.node.open.vertical, opts("Open: Vertical Split")) vim.keymap.set("n", "s", api.node.open.horizontal, opts("Open: Horizontal Split")) vim.keymap.set("n", "t", api.node.open.tab, opts("Open: New Tab")) + vim.keymap.set("n", "R", api.tree.reload, opts("Refresh")) vim.keymap.set("n", "a", api.fs.create, opts("Create")) - vim.keymap.set("n", "d", api.fs.trash, opts("Trash")) - vim.keymap.set("n", "D", api.fs.remove, opts("Delete")) + vim.keymap.set("n", "D", api.fs.trash, opts("Trash")) + vim.keymap.set("n", "d", api.fs.remove, opts("Delete")) vim.keymap.set("n", "n", api.fs.rename, opts("Rename")) vim.keymap.set("n", "N", api.fs.rename_sub, opts("Rename: Omit Filename")) vim.keymap.set("n", "x", api.fs.cut, opts("Cut")) diff --git a/nvim/.nvim/lua/plugins.lua b/nvim/.nvim/lua/plugins.lua index 65dd029..91255e7 100644 --- a/nvim/.nvim/lua/plugins.lua +++ b/nvim/.nvim/lua/plugins.lua @@ -192,14 +192,14 @@ packer.startup({ use({ "hrsh7th/nvim-cmp", requires = { - { "onsails/lspkind-nvim", after = "nvim-cmp" }, - { "hrsh7th/cmp-buffer", after = "nvim-cmp" }, - { "hrsh7th/cmp-cmdline", after = "nvim-cmp" }, - { "hrsh7th/cmp-git", after = "nvim-cmp" }, - { "hrsh7th/cmp-nvim-lsp", after = "nvim-cmp" }, - { "hrsh7th/cmp-nvim-lua", after = "nvim-cmp" }, - { "hrsh7th/cmp-path", after = "nvim-cmp" }, - { "hrsh7th/cmp-calc", after = "nvim-cmp" }, + { "onsails/lspkind-nvim", after = "nvim-cmp" }, + { "hrsh7th/cmp-buffer", after = "nvim-cmp" }, + { "hrsh7th/cmp-cmdline", after = "nvim-cmp" }, + { "hrsh7th/cmp-git", after = "nvim-cmp" }, + { "hrsh7th/cmp-nvim-lsp", after = "nvim-cmp" }, + { "hrsh7th/cmp-nvim-lua", after = "nvim-cmp" }, + { "hrsh7th/cmp-path", after = "nvim-cmp" }, + { "hrsh7th/cmp-calc", after = "nvim-cmp" }, { "saadparwaiz1/cmp_luasnip", after = "nvim-cmp" }, }, event = "InsertEnter", @@ -213,12 +213,6 @@ packer.startup({ tag = "*", config = [[require("plugin/surround")]], }) - -- Auto pair parenthesis - use({ - "windwp/nvim-autopairs", - after = "nvim-cmp", - config = [[require("plugin/autopairs")]], - }) -- Git use({ "lewis6991/gitsigns.nvim", @@ -242,11 +236,6 @@ packer.startup({ ft = "toml", requires = { "nvim-lua/plenary.nvim" }, }) - -- Toml - use({ - "cespare/vim-toml", - ft = "toml", - }) -- CSS use({ "norcalli/nvim-colorizer.lua", diff --git a/nvim/deps/docker.sh b/nvim/deps/docker.sh index 7cb22d5..9acb697 100755 --- a/nvim/deps/docker.sh +++ b/nvim/deps/docker.sh @@ -2,7 +2,7 @@ set -euf -o pipefail installHadolint() { - local -r version="$(curl -s "https://api.github.com/repos/hadolint/hadolint/releases/latest" | grep -Po '"tag_name": "v\K[^"]*')" + local -r version="$(curl -fs "https://api.github.com/repos/hadolint/hadolint/releases/latest" | grep -Po '"tag_name": "v\K[^"]*')" if [ -z "$version" ]; then echo "Could not locate newest lua version" >&2 return 1 @@ -16,7 +16,7 @@ installHadolint() { arch="arm64" fi tmpdir="$(mktemp -d -t hadolint-XXXX)" - curl -Lo $tmpdir/hadolint "https://github.com/hadolint/hadolint/releases/download/v$version/hadolint-$os-$arch" + curl -fLo $tmpdir/hadolint "https://github.com/hadolint/hadolint/releases/download/v$version/hadolint-$os-$arch" local -r appdir="$HOME/.local/app/hadolint" if [ -d "$appdir" ]; then rm -rf "${appdir}_bak" diff --git a/nvim/deps/frontend.sh b/nvim/deps/frontend.sh index 08a66c7..fd4b22b 100755 --- a/nvim/deps/frontend.sh +++ b/nvim/deps/frontend.sh @@ -8,7 +8,8 @@ if command -v npm &>/dev/null; then typescript-language-server \ vls \ stylelint-lsp \ - eslint + eslint \ + @tailwindcss/language-server else echo "Missing command: npm" >&2 echo "Skipped: typescript, eslint and more..." diff --git a/nvim/deps/go.sh b/nvim/deps/go.sh index 85ce519..a7a25e6 100755 --- a/nvim/deps/go.sh +++ b/nvim/deps/go.sh @@ -2,7 +2,7 @@ set -euf -o pipefail installGolangciLint() { - local -r version="$(curl -s "https://api.github.com/repos/golangci/golangci-lint/releases/latest" | grep -Po '"tag_name": "v\K[^"]*')" + local -r version="$(curl -fs "https://api.github.com/repos/golangci/golangci-lint/releases/latest" | grep -Po '"tag_name": "v\K[^"]*')" if [ -z "$version" ]; then echo "Could not locate newest lua version" >&2 return 1 @@ -18,7 +18,7 @@ installGolangciLint() { tmpdir="$(mktemp -d -t golangci-lint-XXXX)" ( cd "$tmpdir" && - curl -Lo golangci-lint.tar.gz "https://github.com/golangci/golangci-lint/releases/download/v$version/golangci-lint-$version-$os-$arch.tar.gz" && + curl -fLo golangci-lint.tar.gz "https://github.com/golangci/golangci-lint/releases/download/v$version/golangci-lint-$version-$os-$arch.tar.gz" && tar xf golangci-lint.tar.gz ) local -r appdir="$HOME/.local/app/golangci-lint" diff --git a/nvim/deps/lua.sh b/nvim/deps/lua.sh index 229df47..dd203fb 100755 --- a/nvim/deps/lua.sh +++ b/nvim/deps/lua.sh @@ -20,7 +20,7 @@ installLuaLangServer() { tmpdir="$(mktemp -d -t lua-XXXX)" ( cd "$tmpdir" && - curl -Lo lua.tar.gz "https://github.com/LuaLS/lua-language-server/releases/download/$version/lua-language-server-$version-$os-$arch.tar.gz" && + curl -fLo lua.tar.gz "https://github.com/LuaLS/lua-language-server/releases/download/$version/lua-language-server-$version-$os-$arch.tar.gz" && tar xf lua.tar.gz ) if [ -d "$luaDir" ]; then diff --git a/nvim/deps/rust.sh b/nvim/deps/rust.sh index f8e7eeb..76c8939 100755 --- a/nvim/deps/rust.sh +++ b/nvim/deps/rust.sh @@ -1,9 +1,25 @@ #!/usr/bin/env bash set -euf -o pipefail +installRustAnalyzer() { + local os="unknown-linux-gnu" + if [[ "$OSTYPE" == "darwin"* ]]; then + os="apple-darwin" + fi + local arch="x86_64" + if [ "$(uname -m)" == "arm64" ]; then + arch="aarch64" + fi + mkdir -p ~/.local/bin + curl -fL https://github.com/rust-lang/rust-analyzer/releases/latest/download/rust-analyzer-${arch}-${os}.gz | + gunzip -c - >~/.local/bin/rust-analyzer + chmod +x ~/.local/bin/rust-analyzer +} + if command -v rustup &>/dev/null; then rustup component add rls rust-analysis rust-src rustfmt clippy - rustup +nightly component add rust-analyzer-preview + rustup update nightly + installRustAnalyzer else echo "Missing command: rustup" >&2 echo "Skipped: rust-analyzer, rls and more..." diff --git a/nvim/deps/toml.sh b/nvim/deps/toml.sh new file mode 100755 index 0000000..bd070e8 --- /dev/null +++ b/nvim/deps/toml.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euf -o pipefail + +installTaplo() { + local os="linux" + if [[ "$OSTYPE" == "darwin"* ]]; then + os="darwin" + fi + local arch="x86_64" + if [ "$(uname -m)" == "arm64" ]; then + arch="aarch64" + fi + mkdir -p ~/.local/bin + curl -fL "https://github.com/tamasfe/taplo/releases/latest/download/taplo-full-$os-$arch.gz" | + gunzip -c - >~/.local/bin/taplo + chmod +x ~/.local/bin/taplo +} + +installTaplo