From 1b5730d51195fee74f3544bd29d017c46da3dea3 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Wed, 11 Aug 2021 17:29:20 +0200 Subject: [PATCH 01/64] feat: make autopairs configurable --- lua/core/autopairs.lua | 105 +++++++++++++++++++++++------------------ lua/default-config.lua | 1 + lua/plugins.lua | 2 +- 3 files changed, 60 insertions(+), 48 deletions(-) diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index a5f21a1b..53572a5b 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -1,54 +1,65 @@ --- if not package.loaded['nvim-autopairs'] then --- return --- end -local Log = require "core.log" -local status_ok, _ = pcall(require, "nvim-autopairs") -if not status_ok then - Log:get_default().error "Failed to load autopairs" - return -end -local npairs = require "nvim-autopairs" -local Rule = require "nvim-autopairs.rule" +local M = {} --- skip it, if you use another global object -_G.MUtils = {} - -vim.g.completion_confirm_key = "" -MUtils.completion_confirm = function() - if vim.fn.pumvisible() ~= 0 then - if vim.fn.complete_info()["selected"] ~= -1 then - return vim.fn["compe#confirm"](npairs.esc "") - else - return npairs.esc "" - end - else - return npairs.autopairs_cr() - end -end - -if package.loaded["compe"] then - local map_complete_optional = vim.bo.filetype ~= "tex" - require("nvim-autopairs.completion.compe").setup { - map_cr = true, -- map on insert mode - map_complete = map_complete_optional, -- it will auto insert `(` after select function or method item +function M.config() + lvim.builtin.autopairs = { + active = true, + ---@usage map on insert mode + map_cr = true, + ---@usage it will auto insert after select function or method item, + map_complete = map_complete_optional, + ---@usage check treesitter + check_ts = true, + ts_config = { + lua = { "string" }, + javascript = { "template_string" }, + java = false, + }, } end -npairs.setup { - check_ts = true, - ts_config = { - lua = { "string" }, -- it will not add pair on that treesitter node - javascript = { "template_string" }, - java = false, -- don't check treesitter on java - }, -} +M.setup = function() + -- skip it, if you use another global object + _G.MUtils = {} + local Log = require "core.log" + local npairs = require "nvim-autopairs" + local Rule = require "nvim-autopairs.rule" -require("nvim-treesitter.configs").setup { autopairs = { enable = true } } + vim.g.completion_confirm_key = "" + MUtils.completion_confirm = function() + if vim.fn.pumvisible() ~= 0 then + if vim.fn.complete_info()["selected"] ~= -1 then + return vim.fn["compe#confirm"](npairs.esc "") + else + return npairs.esc "" + end + else + return npairs.autopairs_cr() + end + end -local ts_conds = require "nvim-autopairs.ts-conds" + if package.loaded["compe"] then + local map_complete_optional = vim.bo.filetype ~= "tex" + require("nvim-autopairs.completion.compe").setup { + map_cr = lvim.builtin.autopairs.map_cr, + map_complete = lvim.builtin.autopairs.map_complete, + } + end --- press % => %% is only inside comment or string -npairs.add_rules { - Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }), - Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }), -} + npairs.setup { + check_ts = lvim.builtin.autopairs.check_ts, + ts_config = lvim.builtin.autopairs.ts_config, + } + + require("nvim-treesitter.configs").setup { autopairs = { enable = true } } + + local ts_conds = require "nvim-autopairs.ts-conds" + + -- TODO: can these rules be safely added from "config.lua" ? + -- press % => %% is only inside comment or string + npairs.add_rules { + Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }), + Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }), + } +end + +return M diff --git a/lua/default-config.lua b/lua/default-config.lua index bba21206..ae2f8dd3 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -1293,3 +1293,4 @@ require("core.treesitter").config() require("core.nvimtree").config() require("core.rooter").config() require("core.bufferline").config() +require("core.autopairs").config() diff --git a/lua/plugins.lua b/lua/plugins.lua index 8e497075..c2a0e0e2 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -68,7 +68,7 @@ return { -- event = "InsertEnter", after = "nvim-compe", config = function() - require "core.autopairs" + require("core.autopairs").setup() if lvim.builtin.autopairs.on_config_done then lvim.builtin.autopairs.on_config_done(require "nvim-autopairs") end From d512b57918ead21dec97bf33a7c63e9ea38310c4 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Wed, 11 Aug 2021 17:34:16 +0200 Subject: [PATCH 02/64] allow disabling autopairs completely --- lua/plugins.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/plugins.lua b/lua/plugins.lua index c2a0e0e2..cacc1e9f 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -73,6 +73,7 @@ return { lvim.builtin.autopairs.on_config_done(require "nvim-autopairs") end end, + disable = not lvim.builtin.autopairs.active, }, -- Treesitter From fb388d7ff81bdedf6e43c077dbf45e4288d45a49 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Wed, 11 Aug 2021 17:39:06 +0200 Subject: [PATCH 03/64] fix map_complete option --- lua/core/autopairs.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index 53572a5b..9309bac9 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -5,8 +5,8 @@ function M.config() active = true, ---@usage map on insert mode map_cr = true, - ---@usage it will auto insert after select function or method item, - map_complete = map_complete_optional, + ---@usage auto insert after select function or method item, + map_complete = vim.bo.filetype ~= "tex", ---@usage check treesitter check_ts = true, ts_config = { @@ -20,7 +20,6 @@ end M.setup = function() -- skip it, if you use another global object _G.MUtils = {} - local Log = require "core.log" local npairs = require "nvim-autopairs" local Rule = require "nvim-autopairs.rule" @@ -38,7 +37,6 @@ M.setup = function() end if package.loaded["compe"] then - local map_complete_optional = vim.bo.filetype ~= "tex" require("nvim-autopairs.completion.compe").setup { map_cr = lvim.builtin.autopairs.map_cr, map_complete = lvim.builtin.autopairs.map_complete, From abf7fee04885befaf99eff6a62c8c5774df8613e Mon Sep 17 00:00:00 2001 From: Ahmed Khalf Date: Thu, 12 Aug 2021 01:48:49 +0400 Subject: [PATCH 04/64] Use rounded borders for packer (#1296) --- lua/plugin-loader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/plugin-loader.lua b/lua/plugin-loader.lua index b7e68a1e..e238b193 100644 --- a/lua/plugin-loader.lua +++ b/lua/plugin-loader.lua @@ -23,7 +23,7 @@ function plugin_loader:init() git = { clone_timeout = 300 }, display = { open_fn = function() - return util.float { border = "single" } + return util.float { border = "rounded" } end, }, } From a3344203818658441d176fe279e1978505940432 Mon Sep 17 00:00:00 2001 From: Andrew Fridley <34749972+afridley@users.noreply.github.com> Date: Thu, 12 Aug 2021 00:49:37 -0500 Subject: [PATCH 05/64] Please... reverse history and cycle next telescope bindings (#1276) --- lua/core/telescope.lua | 4 ++-- utils/installer/config.example-no-ts.lua | 13 +++++++++++++ utils/installer/config.example.lua | 13 +++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index f4d154b0..f8862260 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -60,8 +60,8 @@ M.config = function() -- [""] = actions.select_default + actions.center + my_cool_custom_action, }, n = { - [""] = actions.move_selection_next, - [""] = actions.move_selection_previous, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, [""] = actions.smart_send_to_qflist + actions.open_qflist, -- [""] = trouble.open_with_trouble, -- [""] = my_cool_custom_action, diff --git a/utils/installer/config.example-no-ts.lua b/utils/installer/config.example-no-ts.lua index 4303d264..b0de00f0 100644 --- a/utils/installer/config.example-no-ts.lua +++ b/utils/installer/config.example-no-ts.lua @@ -14,6 +14,19 @@ lvim.keys.normal_mode[""] = ":w" -- edit a default keymapping -- lvim.keys.normal_mode[""] = ":q" +-- Change Telescope navigation to use j and k for navigation and n and p for history in both input and normal mode. +-- lvim.builtin.telescope.on_config_done = function() +-- local actions = require "telescope.actions" +-- -- for input mode +-- lvim.builtin.telescope.defaults.mappings.i[""] = actions.move_selection_next +-- lvim.builtin.telescope.defaults.mappings.i[""] = actions.move_selection_previous +-- lvim.builtin.telescope.defaults.mappings.i[""] = actions.cycle_history_next +-- lvim.builtin.telescope.defaults.mappings.i[""] = actions.cycle_history_prev +-- -- for normal mode +-- lvim.builtin.telescope.defaults.mappings.n[""] = actions.move_selection_next +-- lvim.builtin.telescope.defaults.mappings.n[""] = actions.move_selection_previous +-- end + -- Use which-key to add extra bindings with the leader-key prefix -- lvim.builtin.which_key.mappings["P"] = { "lua require'telescope'.extensions.project.project{}", "Projects" } -- lvim.builtin.which_key.mappings["t"] = { diff --git a/utils/installer/config.example.lua b/utils/installer/config.example.lua index 0aee0275..1c39a571 100644 --- a/utils/installer/config.example.lua +++ b/utils/installer/config.example.lua @@ -23,6 +23,19 @@ lvim.keys.normal_mode[""] = ":w" -- edit a default keymapping -- lvim.keys.normal_mode[""] = ":q" +-- Change Telescope navigation to use j and k for navigation and n and p for history in both input and normal mode. +-- lvim.builtin.telescope.on_config_done = function() +-- local actions = require "telescope.actions" +-- -- for input mode +-- lvim.builtin.telescope.defaults.mappings.i[""] = actions.move_selection_next +-- lvim.builtin.telescope.defaults.mappings.i[""] = actions.move_selection_previous +-- lvim.builtin.telescope.defaults.mappings.i[""] = actions.cycle_history_next +-- lvim.builtin.telescope.defaults.mappings.i[""] = actions.cycle_history_prev +-- -- for normal mode +-- lvim.builtin.telescope.defaults.mappings.n[""] = actions.move_selection_next +-- lvim.builtin.telescope.defaults.mappings.n[""] = actions.move_selection_previous +-- end + -- Use which-key to add extra bindings with the leader-key prefix -- lvim.builtin.which_key.mappings["P"] = { "lua require'telescope'.extensions.project.project{}", "Projects" } -- lvim.builtin.which_key.mappings["t"] = { From 4fd72b1be2c1220a519d5b8d58219939a11df0c9 Mon Sep 17 00:00:00 2001 From: abzcoding Date: Thu, 12 Aug 2021 12:05:54 +0430 Subject: [PATCH 06/64] Revert "Merge pull request #1294 from kylo252/autopairs-refactor" This reverts commit d71c3280c88c72665a21875522f0be3b157075b4, reversing changes made to a3344203818658441d176fe279e1978505940432. --- lua/core/autopairs.lua | 97 +++++++++++++++++++----------------------- lua/default-config.lua | 1 - lua/plugins.lua | 3 +- 3 files changed, 45 insertions(+), 56 deletions(-) diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index 9309bac9..a5f21a1b 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -1,63 +1,54 @@ -local M = {} - -function M.config() - lvim.builtin.autopairs = { - active = true, - ---@usage map on insert mode - map_cr = true, - ---@usage auto insert after select function or method item, - map_complete = vim.bo.filetype ~= "tex", - ---@usage check treesitter - check_ts = true, - ts_config = { - lua = { "string" }, - javascript = { "template_string" }, - java = false, - }, - } +-- if not package.loaded['nvim-autopairs'] then +-- return +-- end +local Log = require "core.log" +local status_ok, _ = pcall(require, "nvim-autopairs") +if not status_ok then + Log:get_default().error "Failed to load autopairs" + return end +local npairs = require "nvim-autopairs" +local Rule = require "nvim-autopairs.rule" -M.setup = function() - -- skip it, if you use another global object - _G.MUtils = {} - local npairs = require "nvim-autopairs" - local Rule = require "nvim-autopairs.rule" +-- skip it, if you use another global object +_G.MUtils = {} - vim.g.completion_confirm_key = "" - MUtils.completion_confirm = function() - if vim.fn.pumvisible() ~= 0 then - if vim.fn.complete_info()["selected"] ~= -1 then - return vim.fn["compe#confirm"](npairs.esc "") - else - return npairs.esc "" - end +vim.g.completion_confirm_key = "" +MUtils.completion_confirm = function() + if vim.fn.pumvisible() ~= 0 then + if vim.fn.complete_info()["selected"] ~= -1 then + return vim.fn["compe#confirm"](npairs.esc "") else - return npairs.autopairs_cr() + return npairs.esc "" end + else + return npairs.autopairs_cr() end +end - if package.loaded["compe"] then - require("nvim-autopairs.completion.compe").setup { - map_cr = lvim.builtin.autopairs.map_cr, - map_complete = lvim.builtin.autopairs.map_complete, - } - end - - npairs.setup { - check_ts = lvim.builtin.autopairs.check_ts, - ts_config = lvim.builtin.autopairs.ts_config, - } - - require("nvim-treesitter.configs").setup { autopairs = { enable = true } } - - local ts_conds = require "nvim-autopairs.ts-conds" - - -- TODO: can these rules be safely added from "config.lua" ? - -- press % => %% is only inside comment or string - npairs.add_rules { - Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }), - Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }), +if package.loaded["compe"] then + local map_complete_optional = vim.bo.filetype ~= "tex" + require("nvim-autopairs.completion.compe").setup { + map_cr = true, -- map on insert mode + map_complete = map_complete_optional, -- it will auto insert `(` after select function or method item } end -return M +npairs.setup { + check_ts = true, + ts_config = { + lua = { "string" }, -- it will not add pair on that treesitter node + javascript = { "template_string" }, + java = false, -- don't check treesitter on java + }, +} + +require("nvim-treesitter.configs").setup { autopairs = { enable = true } } + +local ts_conds = require "nvim-autopairs.ts-conds" + +-- press % => %% is only inside comment or string +npairs.add_rules { + Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }), + Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }), +} diff --git a/lua/default-config.lua b/lua/default-config.lua index ae2f8dd3..bba21206 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -1293,4 +1293,3 @@ require("core.treesitter").config() require("core.nvimtree").config() require("core.rooter").config() require("core.bufferline").config() -require("core.autopairs").config() diff --git a/lua/plugins.lua b/lua/plugins.lua index cacc1e9f..8e497075 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -68,12 +68,11 @@ return { -- event = "InsertEnter", after = "nvim-compe", config = function() - require("core.autopairs").setup() + require "core.autopairs" if lvim.builtin.autopairs.on_config_done then lvim.builtin.autopairs.on_config_done(require "nvim-autopairs") end end, - disable = not lvim.builtin.autopairs.active, }, -- Treesitter From 03b7da74eee555064741fbc54e667eb918e8aa52 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 12 Aug 2021 11:31:31 +0200 Subject: [PATCH 07/64] Fix formatting according to style-guide (#1057) --- .github/workflows/format.yaml | 3 +- lua/lsp/null-ls.lua | 2 +- utils/bin/jdtls | 62 +++---- utils/installer/install.sh | 282 +++++++++++++++--------------- utils/installer/install_stylua.sh | 68 +++---- utils/installer/uninstall.sh | 8 +- 6 files changed, 213 insertions(+), 212 deletions(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 22e56d61..5f9db8cb 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -37,7 +37,8 @@ jobs: run: | GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt + # https://google.github.io/styleguide/shellguide.html - name: Check formatting run: | - shfmt -l -d . + shfmt -i 2 -ci -l -d . diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 697eac39..2ce98f2c 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -97,7 +97,7 @@ function M.setup(filetype) local builtin_formatter = null_ls.builtins.formatting[formatter.exe] if not vim.tbl_contains(M.requested_providers, builtin_formatter) then -- FIXME: why doesn't this work? - -- builtin_formatter._opts.args = formatter.args or builtin_formatter._opts.args + builtin_formatter._opts.args = formatter.args or builtin_formatter._opts.args -- builtin_formatter._opts.to_stdin = formatter.stdin or builtin_formatter._opts.to_stdin local resolved_path = validate_provider_request(builtin_formatter) if resolved_path then diff --git a/utils/bin/jdtls b/utils/bin/jdtls index adfd5e20..2b0f226a 100755 --- a/utils/bin/jdtls +++ b/utils/bin/jdtls @@ -8,31 +8,31 @@ # to point to the `config_mac' or `config_win` folders depending on your system. case Darwin in -Linux) - CONFIG="$HOME/.local/share/nvim/lspinstall/java/config_linux" - ;; -Darwin) - CONFIG="$HOME/.local/share/nvim/lspinstall/java/config_mac" - ;; + Linux) + CONFIG="$HOME/.local/share/nvim/lspinstall/java/config_linux" + ;; + Darwin) + CONFIG="$HOME/.local/share/nvim/lspinstall/java/config_mac" + ;; esac # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ]; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ]; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi + fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." @@ -41,20 +41,20 @@ fi # JAR="$HOME/.config/nvim/.language-servers/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/plugins/org.eclipse.equinox.launcher_*.jar" JAR="$HOME/.local/share/nvim/lspinstall/java/plugins/org.eclipse.equinox.launcher_*.jar" GRADLE_HOME=$HOME/gradle "$JAVACMD" \ - -Declipse.application=org.eclipse.jdt.ls.core.id1 \ - -Dosgi.bundles.defaultStartLevel=4 \ - -Declipse.product=org.eclipse.jdt.ls.core.product \ - -Dlog.protocol=true \ - -Dlog.level=ALL \ - -javaagent:$HOME/.local/share/nvim/lspinstall/java/lombok.jar \ - -Xms1g \ - -Xmx2G \ - -jar $(echo "$JAR") \ - -configuration "$CONFIG" \ - -data "${1:-$HOME/workspace}" \ - --add-modules=ALL-SYSTEM \ - --add-opens java.base/java.util=ALL-UNNAMED \ - --add-opens java.base/java.lang=ALL-UNNAMED + -Declipse.application=org.eclipse.jdt.ls.core.id1 \ + -Dosgi.bundles.defaultStartLevel=4 \ + -Declipse.product=org.eclipse.jdt.ls.core.product \ + -Dlog.protocol=true \ + -Dlog.level=ALL \ + -javaagent:$HOME/.local/share/nvim/lspinstall/java/lombok.jar \ + -Xms1g \ + -Xmx2G \ + -jar $(echo "$JAR") \ + -configuration "$CONFIG" \ + -data "${1:-$HOME/workspace}" \ + --add-modules=ALL-SYSTEM \ + --add-opens java.base/java.util=ALL-UNNAMED \ + --add-opens java.base/java.lang=ALL-UNNAMED # for older java versions if you wanna use lombok # -Xbootclasspath/a:/usr/local/share/lombok/lombok.jar \ diff --git a/utils/installer/install.sh b/utils/installer/install.sh index 25b67f12..98040344 100755 --- a/utils/installer/install.sh +++ b/utils/installer/install.sh @@ -6,227 +6,227 @@ set -o nounset # error when referencing undefined variable set -o errexit # exit when command fails installnodemac() { - brew install lua - brew install node - brew install yarn + brew install lua + brew install node + brew install yarn } installnodeubuntu() { - sudo apt install nodejs - sudo apt install npm + sudo apt install nodejs + sudo apt install npm } installnodetermux() { - apt install nodejs + apt install nodejs } moveoldlvim() { - echo "Not installing LunarVim" - echo "Please move your ~/.local/share/lunarvim folder before installing" - exit + echo "Not installing LunarVim" + echo "Please move your ~/.local/share/lunarvim folder before installing" + exit } installnodearch() { - sudo pacman -S nodejs - sudo pacman -S npm + sudo pacman -S nodejs + sudo pacman -S npm } installnodefedora() { - sudo dnf install -y nodejs - sudo dnf install -y npm + sudo dnf install -y nodejs + sudo dnf install -y npm } installnodegentoo() { - echo "Printing current node status..." - emerge -pqv net-libs/nodejs - echo "Make sure the npm USE flag is enabled for net-libs/nodejs" - echo "If it isn't enabled, would you like to enable it with flaggie? (Y/N)" - read -r answer - [ "$answer" != "${answer#[Yy]}" ] && sudo flaggie net-libs/nodejs +npm - sudo emerge -avnN net-libs/nodejs + echo "Printing current node status..." + emerge -pqv net-libs/nodejs + echo "Make sure the npm USE flag is enabled for net-libs/nodejs" + echo "If it isn't enabled, would you like to enable it with flaggie? (Y/N)" + read -r answer + [ "$answer" != "${answer#[Yy]}" ] && sudo flaggie net-libs/nodejs +npm + sudo emerge -avnN net-libs/nodejs } installnode() { - echo "Installing node..." - [ "$(uname)" = "Darwin" ] && installnodemac - grep -q Ubuntu /etc/os-release && installnodeubuntu - [ -f "/etc/arch-release" ] && installnodearch - [ -f "/etc/artix-release" ] && installnodearch - [ -f "/etc/fedora-release" ] && installnodefedora - [ -f "/etc/gentoo-release" ] && installnodegentoo - [ -d "/data/data/com.termux" ] && installnodetermux - [ "$(uname -s | cut -c 1-10)" = "MINGW64_NT" ] && echo "Windows not currently supported" - sudo npm i -g neovim + echo "Installing node..." + [ "$(uname)" = "Darwin" ] && installnodemac + grep -q Ubuntu /etc/os-release && installnodeubuntu + [ -f "/etc/arch-release" ] && installnodearch + [ -f "/etc/artix-release" ] && installnodearch + [ -f "/etc/fedora-release" ] && installnodefedora + [ -f "/etc/gentoo-release" ] && installnodegentoo + [ -d "/data/data/com.termux" ] && installnodetermux + [ "$(uname -s | cut -c 1-10)" = "MINGW64_NT" ] && echo "Windows not currently supported" + sudo npm i -g neovim } installpiponmac() { - sudo curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py - python3 get-pip.py - rm get-pip.py + sudo curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py + python3 get-pip.py + rm get-pip.py } installpiponubuntu() { - sudo apt install python3-pip >/dev/null + sudo apt install python3-pip >/dev/null } installpipontermux() { - apt install python + apt install python } installpiponarch() { - sudo pacman -S python-pip + sudo pacman -S python-pip } installpiponfedora() { - sudo dnf install -y pip >/dev/null + sudo dnf install -y pip >/dev/null } installpipongentoo() { - sudo emerge -avn dev-python/pip + sudo emerge -avn dev-python/pip } installpip() { - echo "Installing pip..." - [ "$(uname)" = "Darwin" ] && installpiponmac - grep -q Ubuntu /etc/os-release && installpiponubuntu - [ -f "/etc/arch-release" ] && installpiponarch - [ -f "/etc/fedora-release" ] && installpiponfedora - [ -f "/etc/gentoo-release" ] && installpipongentoo - [ -d "/data/data/com.termux" ] && installpipontermux - [ "$(uname -s | cut -c 1-10)" = "MINGW64_NT" ] && echo "Windows not currently supported" + echo "Installing pip..." + [ "$(uname)" = "Darwin" ] && installpiponmac + grep -q Ubuntu /etc/os-release && installpiponubuntu + [ -f "/etc/arch-release" ] && installpiponarch + [ -f "/etc/fedora-release" ] && installpiponfedora + [ -f "/etc/gentoo-release" ] && installpipongentoo + [ -d "/data/data/com.termux" ] && installpipontermux + [ "$(uname -s | cut -c 1-10)" = "MINGW64_NT" ] && echo "Windows not currently supported" } installpynvim() { - echo "Installing pynvim..." - if [ -f "/etc/gentoo-release" ]; then - echo "Installing using Portage" - sudo emerge -avn dev-python/pynvim - else - pip3 install pynvim --user - fi + echo "Installing pynvim..." + if [ -f "/etc/gentoo-release" ]; then + echo "Installing using Portage" + sudo emerge -avn dev-python/pynvim + else + pip3 install pynvim --user + fi } installpacker() { - git clone https://github.com/wbthomason/packer.nvim ~/.local/share/lunarvim/site/pack/packer/start/packer.nvim + git clone https://github.com/wbthomason/packer.nvim ~/.local/share/lunarvim/site/pack/packer/start/packer.nvim } cloneconfig() { - if [ -d "/data/data/com.termux" ]; then - sudo() { - eval "$@" - } - USER_BIN_DIR="$HOME/../usr/bin" - fi - echo "Cloning LunarVim configuration" - mkdir -p ~/.local/share/lunarvim - case "$@" in + if [ -d "/data/data/com.termux" ]; then + sudo() { + eval "$@" + } + USER_BIN_DIR="$HOME/../usr/bin" + fi + echo "Cloning LunarVim configuration" + mkdir -p ~/.local/share/lunarvim + case "$@" in - *--testing*) - cp -r "$(pwd)" ~/.local/share/lunarvim/lvim - ;; - *) - git clone --branch "$LVBRANCH" https://github.com/lunarvim/lunarvim.git ~/.local/share/lunarvim/lvim - ;; - esac - mkdir -p "$HOME/.config/lvim" - sudo cp "$HOME/.local/share/lunarvim/lvim/utils/bin/lvim" "$USER_BIN_DIR" - sudo chmod a+rx "$USER_BIN_DIR"/lvim - cp "$HOME/.local/share/lunarvim/lvim/utils/installer/config.example-no-ts.lua" "$HOME/.config/lvim/config.lua" + *--testing*) + cp -r "$(pwd)" ~/.local/share/lunarvim/lvim + ;; + *) + git clone --branch "$LVBRANCH" https://github.com/lunarvim/lunarvim.git ~/.local/share/lunarvim/lvim + ;; + esac + mkdir -p "$HOME/.config/lvim" + sudo cp "$HOME/.local/share/lunarvim/lvim/utils/bin/lvim" "$USER_BIN_DIR" + sudo chmod a+rx "$USER_BIN_DIR"/lvim + cp "$HOME/.local/share/lunarvim/lvim/utils/installer/config.example-no-ts.lua" "$HOME/.config/lvim/config.lua" - nvim -u ~/.local/share/lunarvim/lvim/init.lua --cmd "set runtimepath+=~/.local/share/lunarvim/lvim" --headless \ - +'autocmd User PackerComplete sleep 100m | qall' \ - +PackerInstall + nvim -u ~/.local/share/lunarvim/lvim/init.lua --cmd "set runtimepath+=~/.local/share/lunarvim/lvim" --headless \ + +'autocmd User PackerComplete sleep 100m | qall' \ + +PackerInstall - nvim -u ~/.local/share/lunarvim/lvim/init.lua --cmd "set runtimepath+=~/.local/share/lunarvim/lvim" --headless \ - +'autocmd User PackerComplete sleep 100m | qall' \ - +PackerSync + nvim -u ~/.local/share/lunarvim/lvim/init.lua --cmd "set runtimepath+=~/.local/share/lunarvim/lvim" --headless \ + +'autocmd User PackerComplete sleep 100m | qall' \ + +PackerSync - printf "\nCompile Complete\n" + printf "\nCompile Complete\n" - if [ -e "$HOME/.local/share/lunarvim/lvim/init.lua" ]; then - echo 'config.lua already present' - else - cp "$HOME/.local/share/lunarvim/lvim/utils/installer/config.example.lua" "$HOME/.config/lvim/config.lua" - fi + if [ -e "$HOME/.local/share/lunarvim/lvim/init.lua" ]; then + echo 'config.lua already present' + else + cp "$HOME/.local/share/lunarvim/lvim/utils/installer/config.example.lua" "$HOME/.config/lvim/config.lua" + fi } asktoinstallnode() { - echo "node not found" - printf "Would you like to install node now (y/n)? " - read -r answer - [ "$answer" != "${answer#[Yy]}" ] && installnode + echo "node not found" + printf "Would you like to install node now (y/n)? " + read -r answer + [ "$answer" != "${answer#[Yy]}" ] && installnode } asktoinstallgit() { - echo "git not found, please install git" - exit + echo "git not found, please install git" + exit } asktoinstallpip() { - # echo "pip not found" - # echo -n "Would you like to install pip now (y/n)? " - # read answer - # [ "$answer" != "${answer#[Yy]}" ] && installpip - echo "Please install pip3 before continuing with install" - exit + # echo "pip not found" + # echo -n "Would you like to install pip now (y/n)? " + # read answer + # [ "$answer" != "${answer#[Yy]}" ] && installpip + echo "Please install pip3 before continuing with install" + exit } installonmac() { - brew install ripgrep fzf - npm install -g tree-sitter-cli + brew install ripgrep fzf + npm install -g tree-sitter-cli } installonubuntu() { - sudo apt install ripgrep fzf - sudo apt install libjpeg8-dev zlib1g-dev python-dev python3-dev libxtst-dev - pip3 install neovim-remote - npm install -g tree-sitter-cli + sudo apt install ripgrep fzf + sudo apt install libjpeg8-dev zlib1g-dev python-dev python3-dev libxtst-dev + pip3 install neovim-remote + npm install -g tree-sitter-cli } installtermux() { - apt install ripgrep fzf - pip install neovim-remote - npm install -g tree-sitter-cli + apt install ripgrep fzf + pip install neovim-remote + npm install -g tree-sitter-cli } installonarch() { - sudo pacman -S ripgrep fzf - pip3 install neovim-remote - npm install -g tree-sitter-cli + sudo pacman -S ripgrep fzf + pip3 install neovim-remote + npm install -g tree-sitter-cli } installonfedora() { - sudo dnf groupinstall "X Software Development" - sudo dnf install -y fzf ripgrep + sudo dnf groupinstall "X Software Development" + sudo dnf install -y fzf ripgrep } installongentoo() { - sudo emerge -avn sys-apps/ripgrep app-shells/fzf dev-python/neovim-remote virtual/jpeg sys-libs/zlib - npm install -g tree-sitter-cli + sudo emerge -avn sys-apps/ripgrep app-shells/fzf dev-python/neovim-remote virtual/jpeg sys-libs/zlib + npm install -g tree-sitter-cli } installextrapackages() { - [ "$(uname)" = "Darwin" ] && installonmac - grep -q Ubuntu /etc/os-release && installonubuntu - [ -f "/etc/arch-release" ] && installonarch - [ -f "/etc/artix-release" ] && installonarch - [ -f "/etc/fedora-release" ] && installonfedora - [ -f "/etc/gentoo-release" ] && installongentoo - [ -d "/data/data/com.termux" ] && installtermux - [ "$(uname -s | cut -c 1-10)" = "MINGW64_NT" ] && echo "Windows not currently supported" + [ "$(uname)" = "Darwin" ] && installonmac + grep -q Ubuntu /etc/os-release && installonubuntu + [ -f "/etc/arch-release" ] && installonarch + [ -f "/etc/artix-release" ] && installonarch + [ -f "/etc/fedora-release" ] && installonfedora + [ -f "/etc/gentoo-release" ] && installongentoo + [ -d "/data/data/com.termux" ] && installtermux + [ "$(uname -s | cut -c 1-10)" = "MINGW64_NT" ] && echo "Windows not currently supported" } # Welcome echo 'Installing LunarVim' case "$@" in -*--overwrite*) - echo '!!Warning!! -> Removing all lunarvim related config because of the --overwrite flag' - rm -rf "$HOME/.local/share/lunarvim" - rm -rf "$HOME/.cache/nvim" - rm -rf "$HOME/.config/lvim" - ;; + *--overwrite*) + echo '!!Warning!! -> Removing all lunarvim related config because of the --overwrite flag' + rm -rf "$HOME/.local/share/lunarvim" + rm -rf "$HOME/.cache/nvim" + rm -rf "$HOME/.config/lvim" + ;; esac # move old lvim directory if it exists @@ -245,27 +245,27 @@ esac (pip3 list | grep pynvim >/dev/null && echo "pynvim installed, moving on...") || installpynvim if [ -e "$HOME/.local/share/lunarvim/site/pack/packer/start/packer.nvim" ]; then - echo 'packer already installed' + echo 'packer already installed' else - installpacker + installpacker fi if [ -e "$HOME/.local/share/lunarvim/lvim/init.lua" ]; then - echo 'LunarVim already installed' + echo 'LunarVim already installed' else - # clone config down - cloneconfig "$@" - # echo 'export PATH=$HOME/.config/nvim/utils/bin:$PATH' >>~/.zshrc - # echo 'export PATH=$HOME/.config/lunarvim/utils/bin:$PATH' >>~/.bashrc + # clone config down + cloneconfig "$@" + # echo 'export PATH=$HOME/.config/nvim/utils/bin:$PATH' >>~/.zshrc + # echo 'export PATH=$HOME/.config/lunarvim/utils/bin:$PATH' >>~/.bashrc fi if [ "$(uname)" != "Darwin" ]; then - if [ -e "$HOME/.local/share/applications/lvim.desktop" ]; then - echo 'Desktop file already available' - else - mkdir -p "$HOME/.local/share/applications" - cp "$HOME/.local/share/lunarvim/lvim/utils/desktop/lvim.desktop" "$HOME/.local/share/applications/lvim.desktop" - fi + if [ -e "$HOME/.local/share/applications/lvim.desktop" ]; then + echo 'Desktop file already available' + else + mkdir -p "$HOME/.local/share/applications" + cp "$HOME/.local/share/lunarvim/lvim/utils/desktop/lvim.desktop" "$HOME/.local/share/applications/lvim.desktop" + fi fi echo "I recommend you also install and activate a font from here: https://github.com/ryanoasis/nerd-fonts" diff --git a/utils/installer/install_stylua.sh b/utils/installer/install_stylua.sh index 2a33de7e..963416ea 100755 --- a/utils/installer/install_stylua.sh +++ b/utils/installer/install_stylua.sh @@ -11,53 +11,53 @@ declare -r FILENAME="stylua-$RELEASE-$OS" declare -a __deps=("curl" "unzip") function check_deps() { - for dep in "${__deps[@]}"; do - if ! command -v "$dep" >/dev/null; then - echo "Missing depdendecy!" - echo "The \"$dep\" command was not found!. Please install and try again." - fi - done + for dep in "${__deps[@]}"; do + if ! command -v "$dep" >/dev/null; then + echo "Missing depdendecy!" + echo "The \"$dep\" command was not found!. Please install and try again." + fi + done } function download_stylua() { - local DOWNLOAD_DIR - local URL="https://github.com/JohnnyMorganz/StyLua/releases/download/v$RELEASE/$FILENAME.zip" + local DOWNLOAD_DIR + local URL="https://github.com/JohnnyMorganz/StyLua/releases/download/v$RELEASE/$FILENAME.zip" - DOWNLOAD_DIR="$(mktemp -d)" - echo "Initiating download for Stylua v$RELEASE" - if ! curl --progress-bar --fail -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME.zip"; then - echo "Download failed. Check that the release/filename are correct." - exit 1 - fi + DOWNLOAD_DIR="$(mktemp -d)" + echo "Initiating download for Stylua v$RELEASE" + if ! curl --progress-bar --fail -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME.zip"; then + echo "Download failed. Check that the release/filename are correct." + exit 1 + fi - echo "Installation in progress.." - unzip -q "$DOWNLOAD_DIR/$FILENAME.zip" -d "$DOWNLOAD_DIR" + echo "Installation in progress.." + unzip -q "$DOWNLOAD_DIR/$FILENAME.zip" -d "$DOWNLOAD_DIR" - if [ -f "$DOWNLOAD_DIR/stylua" ]; then - mv "$DOWNLOAD_DIR/stylua" "$INSTALL_DIR/stylua" - else - mv "$DOWNLOAD_DIR/$FILENAME/stylua" "$INSTALL_DIR/." - fi + if [ -f "$DOWNLOAD_DIR/stylua" ]; then + mv "$DOWNLOAD_DIR/stylua" "$INSTALL_DIR/stylua" + else + mv "$DOWNLOAD_DIR/$FILENAME/stylua" "$INSTALL_DIR/." + fi - chmod u+x "$INSTALL_DIR/stylua" + chmod u+x "$INSTALL_DIR/stylua" } function verify_install() { - echo "Verifying installation.." - local DOWNLOADED_VER - DOWNLOADED_VER="$("$INSTALL_DIR/stylua" -V | awk '{ print $2 }')" - if [ "$DOWNLOADED_VER" != "$RELEASE" ]; then - echo "Mismatched version!" - echo "Expected: v$RELEASE but got v$DOWNLOADED_VER" - exit 1 - fi - echo "Verification complete!" + echo "Verifying installation.." + local DOWNLOADED_VER + DOWNLOADED_VER="$("$INSTALL_DIR/stylua" -V | awk '{ print $2 }')" + if [ "$DOWNLOADED_VER" != "$RELEASE" ]; then + echo "Mismatched version!" + echo "Expected: v$RELEASE but got v$DOWNLOADED_VER" + exit 1 + fi + echo "Verification complete!" } function main() { - check_deps - download_stylua - verify_install + check_deps + download_stylua + verify_install } main "$@" diff --git a/utils/installer/uninstall.sh b/utils/installer/uninstall.sh index b9a27252..8d9d039a 100755 --- a/utils/installer/uninstall.sh +++ b/utils/installer/uninstall.sh @@ -1,10 +1,10 @@ #!/bin/sh USER_BIN_DIR="/usr/local/bin" if [ -d "/data/data/com.termux" ]; then - sudo() { - eval "$@" - } - USER_BIN_DIR="$HOME/../usr/bin" + sudo() { + eval "$@" + } + USER_BIN_DIR="$HOME/../usr/bin" fi rm -rf ~/.local/share/lunarvim sudo rm "$USER_BIN_DIR"/lvim From 6bbce4ee07ac8428846dfb6722e15a932d6d9e05 Mon Sep 17 00:00:00 2001 From: Pasi Bergman Date: Thu, 12 Aug 2021 15:58:45 +0300 Subject: [PATCH 08/64] fix: use correct highlight group with LvimInfo (#1302) --- lua/core/info.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/core/info.lua b/lua/core/info.lua index 56fc3ca2..5e5c5edc 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -204,8 +204,8 @@ function M.toggle_popup(ft) local function set_syntax_hl() vim.cmd [[highlight LvimInfoIdentifier gui=bold]] vim.cmd [[highlight link LvimInfoHeader Type]] - vim.cmd [[let m=matchadd("DashboardHeader", "Language Server Protocol (LSP) info")]] - vim.cmd [[let m=matchadd("DashboardHeader", "Formatters and linters")]] + vim.cmd [[let m=matchadd("LvimInfoHeader", "Language Server Protocol (LSP) info")]] + vim.cmd [[let m=matchadd("LvimInfoHeader", "Formatters and linters")]] vim.cmd('let m=matchadd("LvimInfoIdentifier", " ' .. ft .. '$")') vim.cmd 'let m=matchadd("string", "true")' vim.cmd 'let m=matchadd("error", "false")' From 988c74ec5665250c572dcc6bae018ed0ea180c25 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 13 Aug 2021 12:11:18 +0200 Subject: [PATCH 09/64] feat: Add pre-commit hook for linting and formatting (#1132) * feat: Add pre-commit hook for linting and formatting * format with prettier --- .github/workflows/lint.yaml | 22 +++++++++------------- .pre-commit-config.yaml | 30 ++++++++++++++++++++++++++++++ CONTRIBUTING.md | 14 ++++++++++++-- utils/bin/jdtls | 10 ++++++---- 4 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 87f93a00..f5aab0eb 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -22,17 +22,13 @@ jobs: - name: Run luacheck run: luacheck *.lua lua/ - - shell-linter: - name: "Linting with shellcheck" - runs-on: ubuntu-20.04 + + shellcheck: + name: Shellcheck + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - name: Use shellcheck - run: sudo apt-get install shellcheck - - - name: Run shellcheck - run: | - pwd - shellcheck $(find . -name "*.sh") + - uses: actions/checkout@v2 + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master + with: + scandir: './utils' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..3e3e7d34 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +repos: + - repo: local + hooks: + - id: shfmt + name: shfmt + minimum_pre_commit_version: 2.4.0 + language: golang + additional_dependencies: [mvdan.cc/sh/v3/cmd/shfmt@v3.2.2] + entry: shfmt + args: [-i=2, -ci, -w] + types: [shell] + - id: shellcheck + name: shellcheck + language: system + types: [shell] + entry: bash + args: + [-c, "shfmt -f $(git rev-parse --show-toplevel) | xargs shellcheck"] + - id: stylua + name: StyLua + language: rust + entry: stylua + types: [lua] + args: [.] + - id: luacheck + name: luacheck + language: system + entry: luacheck + types: [lua] + args: [.] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7606fe46..45edf8c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,9 +17,19 @@ One of the best ways to begin contributing in a meaningful way is by helping fin ## Setting up development tools -1. Install [stylua](https://github.com/johnnymorganz/stylua#installation) +### For editing Lua files -2. Install [shfmt](https://github.com/mvdan/sh#shfmt) +1. Formatter: [stylua](https://github.com/johnnymorganz/stylua#installation). +2. Linter: [luacheck](https://github.com/luarocks/luacheck). + +### For editing shell scripts + +1. Formatter: [shfmt](https://github.com/mvdan/sh#shfmt). +2. Linter: [shellcheck](https://github.com/koalaman/shellcheck). + +### (Optional) + +Install [pre-commit](https://github.com/pre-commit/pre-commit) which will run all linters and formatters for you as a pre-commit-hook. ## Some Guidelines diff --git a/utils/bin/jdtls b/utils/bin/jdtls index 2b0f226a..961d2df5 100755 --- a/utils/bin/jdtls +++ b/utils/bin/jdtls @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# shellcheck disable=SC2116 # NOTE: # This doesn't work as is on Windows. You'll need to create an equivalent `.bat` file instead @@ -7,7 +8,8 @@ # If you're not using Linux you'll need to adjust the `-configuration` option # to point to the `config_mac' or `config_win` folders depending on your system. -case Darwin in +OS="$(uname -s)" +case "$OS" in Linux) CONFIG="$HOME/.local/share/nvim/lspinstall/java/config_linux" ;; @@ -32,7 +34,7 @@ location of your Java installation." fi else JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + command -v java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." @@ -46,10 +48,10 @@ GRADLE_HOME=$HOME/gradle "$JAVACMD" \ -Declipse.product=org.eclipse.jdt.ls.core.product \ -Dlog.protocol=true \ -Dlog.level=ALL \ - -javaagent:$HOME/.local/share/nvim/lspinstall/java/lombok.jar \ + -javaagent:"$HOME/.local/share/nvim/lspinstall/java/lombok.jar" \ -Xms1g \ -Xmx2G \ - -jar $(echo "$JAR") \ + -jar "$(echo "$JAR")" \ -configuration "$CONFIG" \ -data "${1:-$HOME/workspace}" \ --add-modules=ALL-SYSTEM \ From 53869f00be7eda020088342e6e1a160ef5fc2a53 Mon Sep 17 00:00:00 2001 From: Ahmed Khalf Date: Sat, 14 Aug 2021 00:16:04 +0400 Subject: [PATCH 10/64] Fix nvimtree quit to update bufferline (#1312) --- lua/core/nvimtree.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 4d15b1b5..25c69575 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -66,6 +66,7 @@ M.setup = function() { key = { "l", "", "o" }, cb = tree_cb "edit" }, { key = "h", cb = tree_cb "close_node" }, { key = "v", cb = tree_cb "vsplit" }, + { key = "q", cb = ":lua require('core.nvimtree').toggle_tree()" }, } end end From 70d139ac2771fac9b072aaebe505f9ac77480b2a Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Fri, 13 Aug 2021 22:32:56 +0200 Subject: [PATCH 11/64] [Refactor/Bugfix] Improve null ls handler (#1277) --- lua/core/galaxyline.lua | 8 +- lua/core/info.lua | 41 ++- lua/default-config.lua | 520 +++++++++++++++++---------------- lua/lsp/init.lua | 5 +- lua/lsp/null-ls.lua | 142 --------- lua/lsp/null-ls/formatters.lua | 79 +++++ lua/lsp/null-ls/init.lua | 44 +++ lua/lsp/null-ls/linters.lua | 79 +++++ lua/lsp/null-ls/services.lua | 55 ++++ lua/lsp/utils.lua | 27 ++ lua/utils/init.lua | 51 +--- 11 files changed, 577 insertions(+), 474 deletions(-) delete mode 100644 lua/lsp/null-ls.lua create mode 100644 lua/lsp/null-ls/formatters.lua create mode 100644 lua/lsp/null-ls/init.lua create mode 100644 lua/lsp/null-ls/linters.lua create mode 100644 lua/lsp/null-ls/services.lua create mode 100644 lua/lsp/utils.lua diff --git a/lua/core/galaxyline.lua b/lua/core/galaxyline.lua index ee0a317d..512dd78c 100644 --- a/lua/core/galaxyline.lua +++ b/lua/core/galaxyline.lua @@ -204,19 +204,23 @@ table.insert(gls.right, { local function get_attached_provider_name(msg) msg = msg or "LSP Inactive" + local buf_clients = vim.lsp.buf_get_clients() if next(buf_clients) == nil then return msg end - local buf_ft = vim.bo.filetype + local buf_client_names = {} - local null_ls_providers = require("lsp.null-ls").get_registered_providers_by_filetype(buf_ft) for _, client in pairs(buf_clients) do if client.name ~= "null-ls" then table.insert(buf_client_names, client.name) end end + + local null_ls = require "lsp.null-ls" + local null_ls_providers = null_ls.list_supported_provider_names(vim.bo.filetype) vim.list_extend(buf_client_names, null_ls_providers) + return table.concat(buf_client_names, ", ") end diff --git a/lua/core/info.lua b/lua/core/info.lua index 5e5c5edc..1610e763 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -1,6 +1,4 @@ local M = {} -local u = require "utils" -local null_ls_handler = require "lsp.null-ls" local indent = " " M.banner = { @@ -25,7 +23,8 @@ local function str_list(list) end local function get_formatter_suggestion_msg(ft) - local supported_formatters = u.get_supported_formatters_by_filetype(ft) + local null_formatters = require "lsp.null-ls.formatters" + local supported_formatters = null_formatters.list_available(ft) return { indent .. "───────────────────────────────────────────────────────────────────", @@ -36,7 +35,7 @@ local function get_formatter_suggestion_msg(ft) indent .. "* Configured formatter needs to be installed and executable.", indent .. "* Enable installed formatter(s) with following config in ~/.config/lvim/config.lua", "", - indent .. " lvim.lang." .. tostring(ft) .. [[.formatting = { { exe = ']] .. table.concat( + indent .. " lvim.lang." .. tostring(ft) .. [[.formatters = { { exe = ']] .. table.concat( supported_formatters, "│" ) .. [[' } }]], @@ -45,7 +44,8 @@ local function get_formatter_suggestion_msg(ft) end local function get_linter_suggestion_msg(ft) - local supported_linters = u.get_supported_linters_by_filetype(ft) + local null_linters = require "lsp.null-ls.linters" + local supported_linters = null_linters.list_available(ft) return { indent .. "───────────────────────────────────────────────────────────────────", @@ -129,16 +129,14 @@ local function tbl_set_highlight(terms, highlight_group) end function M.toggle_popup(ft) - local client = u.get_active_client_by_ft(ft) + local lsp_utils = require "lsp.utils" + local client = lsp_utils.get_active_client_by_ft(ft) local is_client_active = false local client_enabled_caps = {} local client_name = "" local client_id = 0 local document_formatting = false - local missing_linters = {} - local missing_formatters = {} local num_caps = 0 - local null_ls_providers = null_ls_handler.get_registered_providers_by_filetype(ft) if client ~= nil then is_client_active = not client.is_stopped() client_enabled_caps = require("lsp").get_ls_capabilities(client.id) @@ -147,10 +145,6 @@ function M.toggle_popup(ft) client_id = client.id document_formatting = client.resolved_capabilities.document_formatting end - if lvim.lang[ft] ~= nil then - missing_linters = lvim.lang[ft].linters._failed_requests or {} - missing_formatters = lvim.lang[ft].formatters._failed_requests or {} - end local buf_lines = {} vim.list_extend(buf_lines, M.banner) @@ -173,23 +167,27 @@ function M.toggle_popup(ft) } vim.list_extend(buf_lines, lsp_info) + local null_ls = require "lsp.null-ls" + local registered_providers = null_ls.list_supported_provider_names(ft) local null_ls_info = { indent .. "Formatters and linters", - indent .. "* Configured providers: " .. table.concat(null_ls_providers, "  , ") .. "  ", + indent .. "* Configured providers: " .. table.concat(registered_providers, "  , ") .. "  ", } vim.list_extend(buf_lines, null_ls_info) - local missing_formatters_status + local null_formatters = require "lsp.null-ls.formatters" + local missing_formatters = null_formatters.list_unsupported_names(ft) if vim.tbl_count(missing_formatters) > 0 then - missing_formatters_status = { + local missing_formatters_status = { indent .. "* Missing formatters: " .. table.concat(missing_formatters, "  , ") .. "  ", } vim.list_extend(buf_lines, missing_formatters_status) end - local missing_linters_status + local null_linters = require "lsp.null-ls.linters" + local missing_linters = null_linters.list_unsupported_names(ft) if vim.tbl_count(missing_linters) > 0 then - missing_linters_status = { + local missing_linters_status = { indent .. "* Missing linters: " .. table.concat(missing_linters, "  , ") .. "  ", } vim.list_extend(buf_lines, missing_linters_status) @@ -198,7 +196,6 @@ function M.toggle_popup(ft) vim.list_extend(buf_lines, { "" }) vim.list_extend(buf_lines, get_formatter_suggestion_msg(ft)) - vim.list_extend(buf_lines, get_linter_suggestion_msg(ft)) local function set_syntax_hl() @@ -209,11 +206,11 @@ function M.toggle_popup(ft) vim.cmd('let m=matchadd("LvimInfoIdentifier", " ' .. ft .. '$")') vim.cmd 'let m=matchadd("string", "true")' vim.cmd 'let m=matchadd("error", "false")' - tbl_set_highlight(null_ls_providers, "LvimInfoIdentifier") + tbl_set_highlight(registered_providers, "LvimInfoIdentifier") tbl_set_highlight(missing_formatters, "LvimInfoIdentifier") tbl_set_highlight(missing_linters, "LvimInfoIdentifier") - -- tbl_set_highlight(u.get_supported_formatters_by_filetype(ft), "LvimInfoIdentifier") - -- tbl_set_highlight(u.get_supported_linters_by_filetype(ft), "LvimInfoIdentifier") + -- tbl_set_highlight(require("lsp.null-ls.formatters").list_available(ft), "LvimInfoIdentifier") + -- tbl_set_highlight(require("lsp.null-ls.linters").list_available(ft), "LvimInfoIdentifier") vim.cmd('let m=matchadd("LvimInfoIdentifier", "' .. client_name .. '")') end diff --git a/lua/default-config.lua b/lua/default-config.lua index bba21206..13f74c30 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -127,11 +127,10 @@ end lvim.lang = { asm = { formatters = { - { - -- @usage can be asmfmt - exe = "", - args = {}, - }, + -- { + -- exe = "asmfmt", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -141,11 +140,10 @@ lvim.lang = { }, beancount = { formatters = { - { - -- @usage can be bean_format - exe = "", - args = {}, - }, + -- { + -- exe = "bean_format", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -160,12 +158,14 @@ lvim.lang = { }, c = { formatters = { - { - -- @usage can be clang_format or uncrustify - exe = "", - args = {}, - stdin = true, - }, + -- { + -- exe = "clang_format", + -- args = {}, + -- }, + -- { + -- exe = "uncrustify", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -187,12 +187,14 @@ lvim.lang = { }, cpp = { formatters = { - { - -- @usage can be clang_format or uncrustify - exe = "", - args = {}, - stdin = true, - }, + -- { + -- exe = "clang_format", + -- args = {}, + -- }, + -- { + -- exe = "uncrustify", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -214,11 +216,10 @@ lvim.lang = { }, crystal = { formatters = { - { - -- @usage can be crystal_format - exe = "", - args = {}, - }, + -- { + -- exe = "crystal_format", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -233,11 +234,14 @@ lvim.lang = { }, cs = { formatters = { - { - -- @usage can be clang_format or uncrustify - exe = "", - args = {}, - }, + -- { + -- exe = "clang_format ", + -- args = {}, + -- }, + -- { + -- exe = "uncrustify", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -257,11 +261,10 @@ lvim.lang = { }, cmake = { formatters = { - { - -- @usage can be cmake_format - exe = "", - args = {}, - }, + -- { + -- exe = "cmake_format", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -277,10 +280,7 @@ lvim.lang = { }, }, clojure = { - formatters = { { - exe = "", - args = {}, - } }, + formatters = {}, linters = {}, lsp = { provider = "clojure_lsp", @@ -297,11 +297,14 @@ lvim.lang = { }, css = { formatters = { - { - -- @usage can be prettier or prettierd - exe = "", - args = {}, - }, + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -320,11 +323,14 @@ lvim.lang = { }, less = { formatters = { - { - -- @usage can be prettier or prettierd - exe = "", - args = {}, - }, + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -343,11 +349,10 @@ lvim.lang = { }, d = { formatters = { - { - -- @usage can be dfmt - exe = "", - args = {}, - }, + -- { + -- exe = "dfmt", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -362,12 +367,10 @@ lvim.lang = { }, dart = { formatters = { - { - -- @usage can be dart_format - exe = "", - args = {}, - stdin = true, - }, + -- { + -- exe = "dart_format", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -385,13 +388,7 @@ lvim.lang = { }, }, docker = { - formatters = { - { - exe = "", - args = {}, - }, - -- @usage can be {"hadolint"} - }, + formatters = {}, linters = {}, lsp = { provider = "dockerls", @@ -408,12 +405,10 @@ lvim.lang = { }, elixir = { formatters = { - { - -- @usage can be mix - exe = "", - args = {}, - stdin = true, - }, + -- { + -- exe = "mix", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -430,12 +425,10 @@ lvim.lang = { }, elm = { formatters = { - { - -- @usage can be elm_format - exe = "", - args = {}, - stdin = true, - }, + -- { + -- exe = "elm_format", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -457,11 +450,10 @@ lvim.lang = { }, erlang = { formatters = { - { - -- @usage can be erlfmt - exe = "", - args = {}, - }, + -- { + -- exe = "erlfmt", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -479,11 +471,10 @@ lvim.lang = { emmet = { active = false }, fish = { formatters = { - { - -- @usage can be fish_indent - exe = "", - args = {}, - }, + -- { + -- exe = "fish_indent", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -497,12 +488,18 @@ lvim.lang = { }, go = { formatters = { - { - -- @usage can be gofmt or goimports or gofumpt - exe = "", - args = {}, - stdin = true, - }, + -- { + -- exe = "gofmt", + -- args = {}, + -- }, + -- { + -- exe = "goimports", + -- args = {}, + -- }, + -- { + -- exe = "gofumpt", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -518,10 +515,7 @@ lvim.lang = { }, }, graphql = { - formatters = { { - exe = "", - args = {}, - } }, + formatters = {}, linters = {}, lsp = { provider = "graphql", @@ -539,10 +533,7 @@ lvim.lang = { }, }, haskell = { - formatters = { { - exe = "", - args = {}, - } }, + formatters = {}, linters = {}, lsp = { provider = "hls", @@ -556,11 +547,14 @@ lvim.lang = { }, html = { formatters = { - { - -- @usage can be prettier or prettierd - exe = "", - args = {}, - }, + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -579,11 +573,14 @@ lvim.lang = { }, java = { formatters = { - { - -- @usage can be clang_format or uncrustify - exe = "", - args = {}, - }, + -- { + -- exe = "clang_format", + -- args = {}, + -- }, + -- { + -- exe = "uncrustify", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -598,12 +595,18 @@ lvim.lang = { }, json = { formatters = { - { - -- @usage can be json_tool or prettier or prettierd - exe = "", - args = {}, - stdin = true, - }, + -- { + -- exe = "json_tool", + -- args = {}, + -- }, + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -639,10 +642,7 @@ lvim.lang = { }, }, julia = { - formatters = { { - exe = "", - args = {}, - } }, + formatters = {}, linters = {}, lsp = { provider = "julials", @@ -661,10 +661,7 @@ lvim.lang = { }, }, kotlin = { - formatters = { { - exe = "", - args = {}, - } }, + formatters = {}, linters = {}, lsp = { provider = "kotlin_language_server", @@ -695,11 +692,14 @@ lvim.lang = { }, lua = { formatters = { - { - -- @usage can be stylua or lua_format - exe = "", - args = {}, - }, + -- { + -- exe = "stylua", + -- args = {}, + -- }, + -- { + -- exe = "lua_format", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -742,25 +742,23 @@ lvim.lang = { }, nginx = { formatters = { - { - -- @usage can be nginx_beautifier - exe = "", - args = { - provider = "", - setup = {}, - }, - }, + -- { + -- exe = "nginx_beautifier", + -- args = { + -- provider = "", + -- setup = {}, + -- }, + -- }, }, linters = {}, lsp = {}, }, perl = { formatters = { - { - -- @usage can be perltidy - exe = "", - args = {}, - }, + -- { + -- exe = "perltidy", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -770,11 +768,10 @@ lvim.lang = { }, sql = { formatters = { - { - -- @usage can be sqlformat - exe = "", - args = {}, - }, + -- { + -- exe = "sqlformat", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -786,11 +783,10 @@ lvim.lang = { }, php = { formatters = { - { - -- @usage can be phpcbf - exe = "", - args = {}, - }, + -- { + -- exe = "phpcbf", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -814,10 +810,7 @@ lvim.lang = { }, }, puppet = { - formatters = { { - exe = "", - args = {}, - } }, + formatters = {}, linters = {}, lsp = { provider = "puppet", @@ -829,12 +822,19 @@ lvim.lang = { }, }, javascript = { - -- @usage can be prettier or prettier_d_slim or prettierd formatters = { - { - exe = "", - args = {}, - }, + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettier_d_slim", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, }, -- @usage can be {"eslint"} or {"eslint_d"} linters = {}, @@ -854,13 +854,19 @@ lvim.lang = { }, javascriptreact = { formatters = { - { - -- @usage can be prettier or prettier_d_slim or prettierd - exe = "", - args = {}, - }, + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettier_d_slim", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, }, - -- @usage can be {"eslint"} or {"eslint_d"} linters = {}, lsp = { provider = "tsserver", @@ -878,11 +884,14 @@ lvim.lang = { }, python = { formatters = { - { - -- @usage can be black or yapf or isort - exe = "", - args = {}, - }, + -- { + -- exe = "yapf", + -- args = {}, + -- }, + -- { + -- exe = "isort", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -902,11 +911,10 @@ lvim.lang = { -- R -e 'install.packages("readr",repos = "http://cran.us.r-project.org")' r = { formatters = { - { - -- @usage can be format_r - exe = "", - args = {}, - }, + -- { + -- exe = "format_r", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -926,11 +934,10 @@ lvim.lang = { }, ruby = { formatters = { - { - -- @usage can be rufo - exe = "", - args = {}, - }, + -- { + -- exe = "rufo", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -961,11 +968,10 @@ lvim.lang = { }, rust = { formatters = { - { - -- @usage can be rustfmt - exe = "", - args = {}, - }, + -- { + -- exe = "rustfmt", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -982,11 +988,10 @@ lvim.lang = { }, scala = { formatters = { - { - -- @usage can be scalafmt - exe = "", - args = {}, - }, + -- { + -- exe = "scalafmt", + -- args = {}, + -- }, }, linters = { "" }, lsp = { @@ -1000,11 +1005,10 @@ lvim.lang = { }, sh = { formatters = { - { - -- @usage can be shfmt - exe = "", - args = {}, - }, + -- { + -- exe = "shfmt", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -1021,10 +1025,7 @@ lvim.lang = { }, }, svelte = { - formatters = { { - exe = "", - args = {}, - } }, + formatters = {}, linters = {}, lsp = { provider = "svelte", @@ -1041,11 +1042,10 @@ lvim.lang = { }, swift = { formatters = { - { - -- @usage can be swiftformat - exe = "", - args = {}, - }, + -- { + -- exe = "swiftformat", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -1075,11 +1075,10 @@ lvim.lang = { }, terraform = { formatters = { - { - -- @usage can be terraform_fmt - exe = "", - args = {}, - }, + -- { + -- exe = "terraform_fmt", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -1096,14 +1095,7 @@ lvim.lang = { }, }, tex = { - formatters = { - { - exe = "", - args = {}, - stdin = false, - }, - -- @usage can be chktex or vale - }, + formatters = {}, linters = {}, lsp = { provider = "texlab", @@ -1117,12 +1109,18 @@ lvim.lang = { }, typescript = { formatters = { - { - -- @usage can be prettier or prettierd or prettier_d_slim - exe = "", - args = {}, - }, - -- @usage can be {"eslint"} or {"eslint_d"} + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + -- { + -- exe = "prettier_d_slim", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -1141,11 +1139,18 @@ lvim.lang = { }, typescriptreact = { formatters = { - { - -- @usage can be prettier or prettierd or prettier_d_slim - exe = "", - args = {}, - }, + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + -- { + -- exe = "prettier_d_slim", + -- args = {}, + -- }, }, -- @usage can be {"eslint"} or {"eslint_d"} linters = {}, @@ -1164,13 +1169,7 @@ lvim.lang = { }, }, vim = { - formatters = { - { - exe = "", - args = {}, - }, - }, - -- @usage can be {"vint"} + formatters = {}, linters = { "" }, lsp = { provider = "vimls", @@ -1187,13 +1186,19 @@ lvim.lang = { }, vue = { formatters = { - { - -- @usage can be prettier or prettierd or prettier_d_slim - exe = "", - args = {}, - }, + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, + -- { + -- exe = "prettier_d_slim", + -- args = {}, + -- }, }, - -- @usage can be {"eslint"} or {"eslint_d"} linters = {}, lsp = { provider = "vuels", @@ -1209,11 +1214,14 @@ lvim.lang = { }, yaml = { formatters = { - { - -- @usage can be prettier or prettierd - exe = "", - args = {}, - }, + -- { + -- exe = "prettier", + -- args = {}, + -- }, + -- { + -- exe = "prettierd", + -- args = {}, + -- }, }, linters = {}, lsp = { @@ -1230,11 +1238,7 @@ lvim.lang = { }, }, zig = { - formatters = { { - exe = "", - args = {}, - stdin = false, - } }, + formatters = {}, linters = {}, lsp = { provider = "zls", diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index e4ea02db..891147e5 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -1,5 +1,6 @@ local M = {} local Log = require "core.log" + function M.config() vim.lsp.protocol.CompletionItemKind = lvim.lsp.completion.item_kind @@ -127,13 +128,13 @@ function M.common_on_attach(client, bufnr) end function M.setup(lang) + local lsp_utils = require "lsp.utils" local lsp = lvim.lang[lang].lsp - if require("utils").check_lsp_client_active(lsp.provider) then + if lsp_utils.is_client_active(lsp.provider) then return end local overrides = lvim.lsp.override - if type(overrides) == "table" then if vim.tbl_contains(overrides, lang) then return diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua deleted file mode 100644 index 2ce98f2c..00000000 --- a/lua/lsp/null-ls.lua +++ /dev/null @@ -1,142 +0,0 @@ -local M = {} -local Log = require "core.log" - -local null_ls = require "null-ls" - -local nodejs_local_providers = { "prettier", "prettierd", "prettier_d_slim", "eslint_d", "eslint" } - -M.requested_providers = {} - -function M.get_registered_providers_by_filetype(ft) - local matches = {} - for _, provider in pairs(M.requested_providers) do - if vim.tbl_contains(provider.filetypes, ft) then - local provider_name = provider.name - -- special case: show "eslint_d" instead of eslint - -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint - if string.find(provider._opts.command, "eslint_d") then - provider_name = "eslint_d" - end - table.insert(matches, provider_name) - end - end - - return matches -end - -function M.get_missing_providers_by_filetype(ft) - local matches = {} - for _, provider in pairs(M.requested_providers) do - if vim.tbl_contains(provider.filetypes, ft) then - local provider_name = provider.name - - table.insert(matches, provider_name) - end - end - - return matches -end - -local function register_failed_request(ft, provider, operation) - if not lvim.lang[ft][operation]._failed_requests then - lvim.lang[ft][operation]._failed_requests = {} - end - table.insert(lvim.lang[ft][operation]._failed_requests, provider) -end - -local function validate_nodejs_provider(provider) - local command_path - local root_dir - if lvim.builtin.rooter.active then - --- use vim-rooter to set root_dir - vim.cmd "let root_dir = FindRootDirectory()" - root_dir = vim.api.nvim_get_var "root_dir" - else - --- use LSP to set root_dir - local ts_client = require("utils").get_active_client_by_ft "typescript" - if ts_client == nil then - Log:get_default().error "Unable to determine root directory since tsserver didn't start correctly" - return - end - root_dir = ts_client.config.root_dir - end - local local_nodejs_command = root_dir .. "/node_modules/.bin/" .. provider._opts.command - Log:get_default().debug("checking for local node module: ", vim.inspect(provider)) - - if vim.fn.executable(local_nodejs_command) == 1 then - command_path = local_nodejs_command - elseif vim.fn.executable(provider._opts.command) == 1 then - Log:get_default().debug("checking in global path instead for node module", provider._opts.command) - command_path = provider._opts.command - else - Log:get_default().debug("Unable to find node module", provider._opts.command) - end - return command_path -end - -local function validate_provider_request(provider) - if provider == "" or provider == nil then - return - end - -- NOTE: we can't use provider.name because eslint_d uses eslint name - if vim.tbl_contains(nodejs_local_providers, provider._opts.command) then - return validate_nodejs_provider(provider) - end - if vim.fn.executable(provider._opts.command) ~= 1 then - Log:get_default().debug("Unable to find the path for", vim.inspect(provider)) - Log:get_default().warn("Unable to find the path for ", provider._opts.command) - return - end - return provider._opts.command -end - --- TODO: for linters and formatters with spaces and '-' replace with '_' -function M.setup(filetype) - for _, formatter in pairs(lvim.lang[filetype].formatters) do - Log:get_default().debug("validating format provider: ", formatter.exe) - local builtin_formatter = null_ls.builtins.formatting[formatter.exe] - if not vim.tbl_contains(M.requested_providers, builtin_formatter) then - -- FIXME: why doesn't this work? - builtin_formatter._opts.args = formatter.args or builtin_formatter._opts.args - -- builtin_formatter._opts.to_stdin = formatter.stdin or builtin_formatter._opts.to_stdin - local resolved_path = validate_provider_request(builtin_formatter) - if resolved_path then - builtin_formatter._opts.command = resolved_path - table.insert(M.requested_providers, builtin_formatter) - Log:get_default().info("Using format provider", builtin_formatter.name) - else - -- mark it here to avoid re-doing the lookup again - register_failed_request(filetype, formatter.exe, "formatters") - end - end - end - - for _, linter in pairs(lvim.lang[filetype].linters) do - local builtin_diagnoser = null_ls.builtins.diagnostics[linter.exe] - Log:get_default().debug("validating lint provider: ", linter.exe) - -- special case: fallback to "eslint" - -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/9b8458bd1648e84169a7e8638091ba15c2f20fc0/doc/BUILTINS.md#eslint - -- if provider.exe - if linter.exe == "eslint_d" then - builtin_diagnoser = null_ls.builtins.diagnostics.eslint.with { command = "eslint_d" } - end - if not vim.tbl_contains(M.requested_providers, builtin_diagnoser) then - -- FIXME: why doesn't this work? - -- builtin_diagnoser._opts.args = linter.args or builtin_diagnoser._opts.args - -- builtin_diagnoser._opts.to_stdin = linter.stdin or builtin_diagnoser._opts.to_stdin - local resolved_path = validate_provider_request(builtin_diagnoser) - if resolved_path then - builtin_diagnoser._opts.command = resolved_path - table.insert(M.requested_providers, builtin_diagnoser) - Log:get_default().info("Using linter provider", builtin_diagnoser.name) - else - -- mark it here to avoid re-doing the lookup again - register_failed_request(filetype, linter.exe, "linters") - end - end - end - - null_ls.register { sources = M.requested_providers } -end - -return M diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua new file mode 100644 index 00000000..dd88fa60 --- /dev/null +++ b/lua/lsp/null-ls/formatters.lua @@ -0,0 +1,79 @@ +local M = {} +local formatters_by_ft = {} + +local null_ls = require "null-ls" +local services = require "lsp.null-ls.services" +local logger = require("core.log"):get_default() + +local function list_names(formatters, options) + options = options or {} + local names = {} + + local filter = options.filter or "supported" + for name, _ in pairs(formatters[filter]) do + table.insert(names, name) + end + + return names +end + +function M.list_supported_names(filetype) + if not formatters_by_ft[filetype] then + return {} + end + return list_names(formatters_by_ft[filetype], { filter = "supported" }) +end + +function M.list_unsupported_names(filetype) + if not formatters_by_ft[filetype] then + return {} + end + return list_names(formatters_by_ft[filetype], { filter = "unsupported" }) +end + +function M.list_available(filetype) + local formatters = {} + for _, provider in pairs(null_ls.builtins.formatting) do + -- TODO: Add support for wildcard filetypes + if vim.tbl_contains(provider.filetypes or {}, filetype) then + table.insert(formatters, provider.name) + end + end + + return formatters +end + +function M.list_configured(formatter_configs) + local formatters, errors = {}, {} + + for _, fmt_config in ipairs(formatter_configs) do + local formatter = null_ls.builtins.formatting[fmt_config.exe] + + if not formatter then + logger.error("Not a valid formatter:", fmt_config.exe) + errors[fmt_config.exe] = {} -- Add data here when necessary + else + local formatter_cmd = services.find_command(formatter._opts.command) + if not formatter_cmd then + logger.warn("Not found:", formatter._opts.command) + errors[fmt_config.exe] = {} -- Add data here when necessary + else + logger.info("Using formatter:", formatter_cmd) + formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, args = fmt_config.args } + end + end + end + + return { supported = formatters, unsupported = errors } +end + +function M.setup(filetype, options) + if formatters_by_ft[filetype] and not options.force_reload then + return + end + + formatters_by_ft[filetype] = M.list_configured(lvim.lang[filetype].formatters) + null_ls.register { sources = formatters_by_ft[filetype].supported } +end + +return M diff --git a/lua/lsp/null-ls/init.lua b/lua/lsp/null-ls/init.lua new file mode 100644 index 00000000..8691982e --- /dev/null +++ b/lua/lsp/null-ls/init.lua @@ -0,0 +1,44 @@ +local M = {} + +function M.list_supported_provider_names(filetype) + local names = {} + + local formatters = require "lsp.null-ls.formatters" + local linters = require "lsp.null-ls.linters" + + vim.list_extend(names, formatters.list_supported_names(filetype)) + vim.list_extend(names, linters.list_supported_names(filetype)) + + return names +end + +function M.list_unsupported_provider_names(filetype) + local names = {} + + local formatters = require "lsp.null-ls.formatters" + local linters = require "lsp.null-ls.linters" + + vim.list_extend(names, formatters.list_unsupported_names(filetype)) + vim.list_extend(names, linters.list_unsupported_names(filetype)) + + return names +end + +-- TODO: for linters and formatters with spaces and '-' replace with '_' +function M.setup(filetype, options) + options = options or {} + + local ok, _ = pcall(require, "null-ls") + if not ok then + require("core.log"):get_default().error "Missing null-ls dependency" + return + end + + local formatters = require "lsp.null-ls.formatters" + local linters = require "lsp.null-ls.linters" + + formatters.setup(filetype, options) + linters.setup(filetype, options) +end + +return M diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua new file mode 100644 index 00000000..780a9c4d --- /dev/null +++ b/lua/lsp/null-ls/linters.lua @@ -0,0 +1,79 @@ +local M = {} +local linters_by_ft = {} + +local null_ls = require "null-ls" +local services = require "lsp.null-ls.services" +local logger = require("core.log"):get_default() + +local function list_names(linters, options) + options = options or {} + local names = {} + + local filter = options.filter or "supported" + for name, _ in pairs(linters[filter]) do + table.insert(names, name) + end + + return names +end + +function M.list_supported_names(filetype) + if not linters_by_ft[filetype] then + return {} + end + return list_names(linters_by_ft[filetype], { filter = "supported" }) +end + +function M.list_unsupported_names(filetype) + if not linters_by_ft[filetype] then + return {} + end + return list_names(linters_by_ft[filetype], { filter = "unsupported" }) +end + +function M.list_available(filetype) + local linters = {} + for _, provider in pairs(null_ls.builtins.diagnostics) do + -- TODO: Add support for wildcard filetypes + if vim.tbl_contains(provider.filetypes or {}, filetype) then + table.insert(linters, provider.name) + end + end + + return linters +end + +function M.list_configured(linter_configs) + local linters, errors = {}, {} + + for _, lnt_config in pairs(linter_configs) do + local linter = null_ls.builtins.diagnostics[lnt_config.exe] + + if not linter then + logger.error("Not a valid linter:", lnt_config.exe) + errors[lnt_config.exe] = {} -- Add data here when necessary + else + local linter_cmd = services.find_command(linter._opts.command) + if not linter_cmd then + logger.warn("Not found:", linter._opts.command) + errors[lnt_config.exe] = {} -- Add data here when necessary + else + logger.info("Using linter:", linter_cmd) + linters[lnt_config.exe] = linter.with { command = linter_cmd, args = lnt_config.args } + end + end + end + + return { supported = linters, unsupported = errors } +end + +function M.setup(filetype, options) + if linters_by_ft[filetype] and not options.force_reload then + return + end + + linters_by_ft[filetype] = M.list_configured(lvim.lang[filetype].linters) + null_ls.register { sources = linters_by_ft[filetype].supported } +end + +return M diff --git a/lua/lsp/null-ls/services.lua b/lua/lsp/null-ls/services.lua new file mode 100644 index 00000000..89073e5c --- /dev/null +++ b/lua/lsp/null-ls/services.lua @@ -0,0 +1,55 @@ +local M = {} + +local logger = require("core.log"):get_default() + +local function find_root_dir() + if lvim.builtin.rooter.active then + --- use vim-rooter to set root_dir + vim.cmd "let root_dir = FindRootDirectory()" + return vim.api.nvim_get_var "root_dir" + end + + -- TODO: Rework this to not make it javascript specific + --- use LSP to set root_dir + local lsp_utils = require "lsp.utils" + local ts_client = lsp_utils.get_active_client_by_ft "typescript" + if ts_client == nil then + logger.error "Unable to determine root directory since tsserver didn't start correctly" + return nil + end + + return ts_client.config.root_dir +end + +local function from_node_modules(command) + local root_dir = find_root_dir() + if not root_dir then + return nil + end + + return root_dir .. "/node_modules/.bin/" .. command +end + +local local_providers = { + prettier = { find = from_node_modules }, + prettierd = { find = from_node_modules }, + prettier_d_slim = { find = from_node_modules }, + eslint_d = { find = from_node_modules }, + eslint = { find = from_node_modules }, +} + +function M.find_command(command) + if local_providers[command] then + local local_command = local_providers[command].find(command) + if local_command and vim.fn.executable(local_command) == 1 then + return local_command + end + end + + if vim.fn.executable(command) == 1 then + return command + end + return nil +end + +return M diff --git a/lua/lsp/utils.lua b/lua/lsp/utils.lua new file mode 100644 index 00000000..e28c6085 --- /dev/null +++ b/lua/lsp/utils.lua @@ -0,0 +1,27 @@ +local M = {} + +function M.is_client_active(name) + local clients = vim.lsp.get_active_clients() + for _, client in pairs(clients) do + if client.name == name then + return true + end + end + return false +end + +function M.get_active_client_by_ft(filetype) + if not lvim.lang[filetype] or not lvim.lang[filetype].lsp then + return nil + end + + local clients = vim.lsp.get_active_clients() + for _, client in pairs(clients) do + if client.name == lvim.lang[filetype].lsp.provider then + return client + end + end + return nil +end + +return M diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 8264189d..0f42623b 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -99,57 +99,12 @@ function utils.reload_lv_config() vim.cmd ":PackerCompile" vim.cmd ":PackerInstall" -- vim.cmd ":PackerClean" + local null_ls = require "lsp.null-ls" + null_ls.setup(vim.bo.filetype, { force_reload = true }) + Log:get_default().info "Reloaded configuration" end -function utils.check_lsp_client_active(name) - local clients = vim.lsp.get_active_clients() - for _, client in pairs(clients) do - if client.name == name then - return true - end - end - return false -end - -function utils.get_active_client_by_ft(filetype) - local clients = vim.lsp.get_active_clients() - for _, client in pairs(clients) do - if client.name == lvim.lang[filetype].lsp.provider then - return client - end - end - return nil -end - --- TODO: consider porting this logic to null-ls instead -function utils.get_supported_linters_by_filetype(filetype) - local null_ls = require "null-ls" - local matches = {} - for _, provider in pairs(null_ls.builtins.diagnostics) do - if vim.tbl_contains(provider.filetypes, filetype) then - local provider_name = provider.name - - table.insert(matches, provider_name) - end - end - - return matches -end - -function utils.get_supported_formatters_by_filetype(filetype) - local null_ls = require "null-ls" - local matches = {} - for _, provider in pairs(null_ls.builtins.formatting) do - if provider.filetypes and vim.tbl_contains(provider.filetypes, filetype) then - -- table.insert(matches, { provider.name, ft }) - table.insert(matches, provider.name) - end - end - - return matches -end - function utils.unrequire(m) package.loaded[m] = nil _G[m] = nil From 9c9bcb1e0a1074e03290bae9c2c247b9c2a02b0f Mon Sep 17 00:00:00 2001 From: Pasi Bergman Date: Sat, 14 Aug 2021 14:43:48 +0300 Subject: [PATCH 12/64] fix: lviminfo highlight match fix (#1316) --- lua/core/info.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/core/info.lua b/lua/core/info.lua index 1610e763..d5bd94ce 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -124,7 +124,7 @@ local function tbl_set_highlight(terms, highlight_group) end for _, v in pairs(terms) do - vim.cmd('let m=matchadd("' .. highlight_group .. '", "' .. v .. '")') + vim.cmd('let m=matchadd("' .. highlight_group .. '", "' .. v .. "[ ,│']\")") end end From a42cde2638726cde84a1548764ff4c3825d8537e Mon Sep 17 00:00:00 2001 From: Marcelo Cerri Date: Sat, 14 Aug 2021 09:16:08 -0300 Subject: [PATCH 13/64] Add command mode key mapping table (#1306) --- lua/keymappings.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lua/keymappings.lua b/lua/keymappings.lua index e82df5ae..7d75e06b 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -8,6 +8,7 @@ local generic_opts = { normal_mode = generic_opts_any, visual_mode = generic_opts_any, visual_block_mode = generic_opts_any, + command_mode = generic_opts_any, term_mode = { silent = true }, } @@ -17,6 +18,7 @@ local mode_adapters = { term_mode = "t", visual_mode = "v", visual_block_mode = "x", + command_mode = "c", } -- Append key mappings to lunarvim's defaults for a given mode @@ -142,6 +144,14 @@ function M.config() [""] = ":m '>+1gv-gv", [""] = ":m '<-2gv-gv", }, + + ---@usage change or add keymappings for command mode + command_mode = { + -- navigate tab completion with and + -- runs conditionally + [""] = { 'pumvisible() ? "\\" : "\\"', { expr = true, noremap = true } }, + [""] = { 'pumvisible() ? "\\" : "\\"', { expr = true, noremap = true } }, + }, } if vim.fn.has "mac" == 1 then From fe55935c056a6b5f3dafa606b253324b1edc7ab5 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 14 Aug 2021 14:16:38 +0200 Subject: [PATCH 14/64] feat: use telescope to quickly open lunarvim files (#1310) --- lua/core/telescope.lua | 38 ++++++++++++++++++++++++++++++++++++-- lua/core/which-key.lua | 12 ++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index f8862260..30533b65 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -1,6 +1,6 @@ local M = {} local Log = require "core.log" -M.config = function() +function M.config() local status_ok, actions = pcall(require, "telescope.actions") if not status_ok then return @@ -77,7 +77,41 @@ M.config = function() } end -M.setup = function() +function M.find_lunarvim_files(opts) + opts = opts or {} + local themes = require "telescope.themes" + local theme_opts = themes.get_ivy { + previewer = false, + sorting_strategy = "ascending", + layout_strategy = "bottom_pane", + layout_config = { + height = 5, + width = 0.5, + }, + prompt = ">> ", + prompt_title = "~ LunarVim files ~", + cwd = CONFIG_PATH, + find_command = { "git", "ls-files" }, + } + opts = vim.tbl_deep_extend("force", theme_opts, opts) + require("telescope.builtin").find_files(opts) +end + +function M.grep_lunarvim_files(opts) + opts = opts or {} + local themes = require "telescope.themes" + local theme_opts = themes.get_ivy { + sorting_strategy = "ascending", + layout_strategy = "bottom_pane", + prompt = ">> ", + prompt_title = "~ search LunarVim ~", + cwd = CONFIG_PATH, + } + opts = vim.tbl_deep_extend("force", theme_opts, opts) + require("telescope.builtin").live_grep(opts) +end + +function M.setup() local status_ok, telescope = pcall(require, "telescope") if not status_ok then Log:get_default().error "Failed to load telescope" diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 96f3a8f7..66e3ffbb 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -169,6 +169,18 @@ M.config = function() }, L = { name = "+LunarVim", + c = { + "edit ~/.config/lvim/config.lua", + "Edit config.lua", + }, + f = { + "lua require('core.telescope').find_lunarvim_files()", + "Find LunarVim files", + }, + g = { + "lua require('core.telescope').grep_lunarvim_files()", + "Grep LunarVim files", + }, k = { "lua require('keymappings').print()", "View LunarVim's default keymappings" }, i = { "lua require('core.info').toggle_popup(vim.bo.filetype)", From ae118c5afc0a533118059a4681a2736055e8a2bc Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 15 Aug 2021 00:17:41 +0430 Subject: [PATCH 15/64] fix commentstring for elixir files (#1321) --- ftplugin/elixir.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/ftplugin/elixir.lua b/ftplugin/elixir.lua index f8ae8b64..2d4c90e2 100644 --- a/ftplugin/elixir.lua +++ b/ftplugin/elixir.lua @@ -1,4 +1,5 @@ require("lsp").setup "elixir" +vim.api.nvim_buf_set_option(0, "commentstring", "# %s") -- TODO: do we need this? -- needed for the LSP to recognize elixir files (alternatively just use elixir-editors/vim-elixir) From 0fbf66e379f10d816d875583f6805ab7e3ea9e78 Mon Sep 17 00:00:00 2001 From: Marcelo Cerri Date: Sat, 14 Aug 2021 16:56:37 -0300 Subject: [PATCH 16/64] Add a new option to show the mode name in galaxyline (#1303) --- lua/core/galaxyline.lua | 24 ++++++++++++++++++++++++ lua/core/status_colors.lua | 1 + 2 files changed, 25 insertions(+) diff --git a/lua/core/galaxyline.lua b/lua/core/galaxyline.lua index 512dd78c..0f31ef53 100644 --- a/lua/core/galaxyline.lua +++ b/lua/core/galaxyline.lua @@ -18,6 +18,20 @@ local condition = require "galaxyline.condition" local gls = gl.section gl.short_line_list = { "NvimTree", "vista", "dbui", "packer" } +local function get_mode_name() + local names = { + n = "NORMAL", + i = "INSERT", + c = "COMMAND", + v = "VISUAL", + V = "VISUAL LINE", + t = "TERMINAL", + R = "REPLACE", + [""] = "VISUAL BLOCK", + } + return names[vim.fn.mode()] +end + table.insert(gls.left, { ViMode = { provider = function() @@ -44,6 +58,16 @@ table.insert(gls.left, { ["!"] = colors.blue, t = colors.blue, } + if lvim.builtin.galaxyline.show_mode then + local name = get_mode_name() + -- Fall back to the default behavior is a name is not defined + if name ~= nil then + vim.api.nvim_command("hi GalaxyViMode guibg=" .. mode_color[vim.fn.mode()]) + vim.api.nvim_command("hi GalaxyViMode guifg=" .. colors.alt_bg) + return " " .. name .. " " + end + end + vim.api.nvim_command("hi GalaxyViMode guibg=" .. colors.alt_bg) vim.api.nvim_command("hi GalaxyViMode guifg=" .. mode_color[vim.fn.mode()]) return "▊" end, diff --git a/lua/core/status_colors.lua b/lua/core/status_colors.lua index 37e9d7c9..d6317309 100644 --- a/lua/core/status_colors.lua +++ b/lua/core/status_colors.lua @@ -1,5 +1,6 @@ lvim.builtin.galaxyline = { active = true, + show_mode = false, colors = { alt_bg = "#2E2E2E", grey = "#858585", From 6e0f56f09ec66f7e00ec095456fb113fdf6b07cb Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Sat, 14 Aug 2021 22:02:17 +0200 Subject: [PATCH 17/64] [Bugfix] Support extending null builtin args (#1317) --- lua/lsp/null-ls/formatters.lua | 9 ++------- lua/lsp/null-ls/linters.lua | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index dd88fa60..d6ede29d 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -7,14 +7,9 @@ local logger = require("core.log"):get_default() local function list_names(formatters, options) options = options or {} - local names = {} - local filter = options.filter or "supported" - for name, _ in pairs(formatters[filter]) do - table.insert(names, name) - end - return names + return vim.tbl_keys(formatters[filter]) end function M.list_supported_names(filetype) @@ -59,7 +54,7 @@ function M.list_configured(formatter_configs) errors[fmt_config.exe] = {} -- Add data here when necessary else logger.info("Using formatter:", formatter_cmd) - formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, args = fmt_config.args } + formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args } end end end diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index 780a9c4d..64d2db4a 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -7,14 +7,9 @@ local logger = require("core.log"):get_default() local function list_names(linters, options) options = options or {} - local names = {} - local filter = options.filter or "supported" - for name, _ in pairs(linters[filter]) do - table.insert(names, name) - end - return names + return vim.tbl_keys(linters[filter]) end function M.list_supported_names(filetype) @@ -59,7 +54,7 @@ function M.list_configured(linter_configs) errors[lnt_config.exe] = {} -- Add data here when necessary else logger.info("Using linter:", linter_cmd) - linters[lnt_config.exe] = linter.with { command = linter_cmd, args = lnt_config.args } + linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args } end end end From f36fd1907fd2480c766d96c65e1aebe69e5c855f Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 15 Aug 2021 03:08:42 +0430 Subject: [PATCH 18/64] support for puppet using lspinstall (#1322) --- lua/default-config.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/default-config.lua b/lua/default-config.lua index 13f74c30..dd8a2043 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -815,6 +815,10 @@ lvim.lang = { lsp = { provider = "puppet", setup = { + cmd = { + DATA_PATH .. "/lspinstall/puppet/puppet-editor-services/puppet-languageserver", + "--stdio", + }, on_attach = common_on_attach, on_init = common_on_init, capabilities = common_capabilities, From 6eb75c5678ddb4d040f644e331e222078b99b3a1 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 15 Aug 2021 17:38:47 +0200 Subject: [PATCH 19/64] [Refactor] Clean-up redundant module-load checks (#1011) --- .pre-commit-config.yaml | 5 ++--- lua/core/compe.lua | 7 +------ lua/core/dap.lua | 7 +------ lua/core/gitsigns.lua | 8 +------- lua/core/telescope.lua | 2 +- lua/core/terminal.lua | 17 ++++------------- lua/core/which-key.lua | 16 +++------------- lua/plugins.lua | 10 ++-------- 8 files changed, 15 insertions(+), 57 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3e3e7d34..9172b0f1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,8 +4,7 @@ repos: - id: shfmt name: shfmt minimum_pre_commit_version: 2.4.0 - language: golang - additional_dependencies: [mvdan.cc/sh/v3/cmd/shfmt@v3.2.2] + language: system entry: shfmt args: [-i=2, -ci, -w] types: [shell] @@ -21,7 +20,7 @@ repos: language: rust entry: stylua types: [lua] - args: [.] + args: ['-'] - id: luacheck name: luacheck language: system diff --git a/lua/core/compe.lua b/lua/core/compe.lua index c2f97e27..b5b37805 100644 --- a/lua/core/compe.lua +++ b/lua/core/compe.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" M.config = function() lvim.builtin.compe = { enabled = true, @@ -61,11 +60,7 @@ end M.setup = function() vim.g.vsnip_snippet_dir = lvim.vsnip_dir - local status_ok, compe = pcall(require, "compe") - if not status_ok then - Log:get_default().error "Failed to load compe" - return - end + local compe = require "compe" compe.setup(lvim.builtin.compe) diff --git a/lua/core/dap.lua b/lua/core/dap.lua index 4e21cc4c..259ff87e 100644 --- a/lua/core/dap.lua +++ b/lua/core/dap.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" M.config = function() lvim.builtin.dap = { active = false, @@ -13,11 +12,7 @@ M.config = function() end M.setup = function() - local status_ok, dap = pcall(require, "dap") - if not status_ok then - Log:get_default().error "Failed to load dap" - return - end + local dap = require "dap" vim.fn.sign_define("DapBreakpoint", lvim.builtin.dap.breakpoint) dap.defaults.fallback.terminal_win_cmd = "50vsplit new" diff --git a/lua/core/gitsigns.lua b/lua/core/gitsigns.lua index 9e023762..0c0efa91 100644 --- a/lua/core/gitsigns.lua +++ b/lua/core/gitsigns.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" M.config = function() lvim.builtin.gitsigns = { signs = { @@ -49,12 +48,7 @@ M.config = function() end M.setup = function() - local status_ok, gitsigns = pcall(require, "gitsigns") - if not status_ok then - Log:get_default().error "Failed to load gitsigns" - return - end - gitsigns.setup(lvim.builtin.gitsigns) + require("gitsigns").setup(lvim.builtin.gitsigns) end return M diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index 30533b65..d31edef9 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" function M.config() local status_ok, actions = pcall(require, "telescope.actions") if not status_ok then @@ -114,6 +113,7 @@ end function M.setup() local status_ok, telescope = pcall(require, "telescope") if not status_ok then + local Log = require "core.log" Log:get_default().error "Failed to load telescope" return end diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index 818038fd..661e5b3b 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" local utils = require "utils" M.config = function() @@ -46,22 +45,13 @@ M.config = function() end M.setup = function() - local status_ok, terminal = pcall(require, "toggleterm") - if not status_ok then - Log:get_default().error "Failed to load toggleterm" - print(terminal) - return - end + local terminal = require "toggleterm" for _, exec in pairs(lvim.builtin.terminal.execs) do require("core.terminal").add_exec(exec[1], exec[2], exec[3]) end terminal.setup(lvim.builtin.terminal) end -local function is_installed(exe) - return vim.fn.executable(exe) == 1 -end - M.add_exec = function(exec, keymap, name) vim.api.nvim_set_keymap( "n", @@ -85,8 +75,9 @@ end M._exec_toggle = function(exec) local binary = M._split(exec)[1] - if is_installed(binary) ~= true then - print("Please install executable " .. binary .. ". Check documentation for more information") + if vim.fn.executable(binary) ~= 1 then + local Log = require "core.log" + Log:get_default().error("Unable to run executable " .. binary .. ". Please make sure it is installed properly.") return end local Terminal = require("toggleterm.terminal").Terminal diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 66e3ffbb..04f892d8 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" M.config = function() lvim.builtin.which_key = { active = false, @@ -230,14 +229,7 @@ M.config = function() end M.setup = function() - -- if not package.loaded['which-key'] then - -- return - -- end - local status_ok, which_key = pcall(require, "which-key") - if not status_ok then - Log:get_default "Failed to load whichkey" - return - end + local which_key = require "which-key" which_key.setup(lvim.builtin.which_key.setup) @@ -247,10 +239,8 @@ M.setup = function() local mappings = lvim.builtin.which_key.mappings local vmappings = lvim.builtin.which_key.vmappings - local wk = require "which-key" - - wk.register(mappings, opts) - wk.register(vmappings, vopts) + which_key.register(mappings, opts) + which_key.register(vmappings, vopts) end return M diff --git a/lua/plugins.lua b/lua/plugins.lua index 8e497075..5353de5b 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -131,15 +131,9 @@ return { "terrortylor/nvim-comment", event = "BufRead", config = function() - local status_ok, nvim_comment = pcall(require, "nvim_comment") - if not status_ok then - local Log = require "core.log" - Log:get_default().error "Failed to load nvim-comment" - return - end - nvim_comment.setup() + require("nvim_comment").setup() if lvim.builtin.comment.on_config_done then - lvim.builtin.comment.on_config_done(nvim_comment) + lvim.builtin.comment.on_config_done(require "nvim_comment") end end, }, From 1fbc34cf1d3c2ec5500ddb6e14f04751680d969f Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 15 Aug 2021 18:01:37 +0200 Subject: [PATCH 20/64] Fix slow CI by installing a neovim binary directly (#1059) --- .github/workflows/install.yaml | 19 +++-- utils/bin/install-latest-neovim | 9 --- utils/installer/install-neovim-from-release | 83 +++++++++++++++++++++ 3 files changed, 92 insertions(+), 19 deletions(-) delete mode 100755 utils/bin/install-latest-neovim create mode 100755 utils/installer/install-neovim-from-release diff --git a/.github/workflows/install.yaml b/.github/workflows/install.yaml index 08801f1b..6fb0d49c 100644 --- a/.github/workflows/install.yaml +++ b/.github/workflows/install.yaml @@ -22,19 +22,18 @@ jobs: if: github.event.pull_request.draft == false steps: - uses: actions/checkout@v2 - - - name: Install dependencies for Linux - if: matrix.os == 'linux' - run: | - sudo add-apt-repository ppa:neovim-ppa/unstable -y - sudo apt-get update - sudo apt-get install neovim -y - - name: Install dependencies for OSX + # sha256sum is not available by default + - name: Installl dependencies for OSX if: matrix.os == 'osx' run: | - brew update >/dev/null - brew install neovim + echo "HOMEBREW_NO_AUTO_UPDATE=1" >> $GITHUB_ENV + echo "$HOME/.local/bin" >> $GITHUB_PATH + brew install coreutils + + - name: Install neovim binary + run: | + bash ./utils/installer/install-neovim-from-release - name: Install LunarVim timeout-minutes: 4 diff --git a/utils/bin/install-latest-neovim b/utils/bin/install-latest-neovim deleted file mode 100755 index 8d1d95fd..00000000 --- a/utils/bin/install-latest-neovim +++ /dev/null @@ -1,9 +0,0 @@ -!#/bin/bash -cd ~ -sudo rm -r neovim -git clone --branch master --depth 1 https://github.com/neovim/neovim -cd neovim -sudo make CMAKE_BUILD_TYPE=Release install -cd ~ -sudo rm -r neovim - diff --git a/utils/installer/install-neovim-from-release b/utils/installer/install-neovim-from-release new file mode 100755 index 00000000..a2ba0513 --- /dev/null +++ b/utils/installer/install-neovim-from-release @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +set -eu pipefall + +declare -r LV_INSTALL_PREFIX="${INSTALL_PREFIX:-"$HOME/.local"}" +declare -r RELEASE_VER="${RELEASE_VER:-latest}" # can be set to nightly + +declare ARCHIVE_NAME +declare RELEASE_NAME +declare OS + +OS="$(uname -s)" + +if [ "$OS" == "Linux" ]; then + ARCHIVE_NAME="nvim-linux64" + RELEASE_NAME="nvim-linux64" +elif [ "$OS" == "Darwin" ]; then + ARCHIVE_NAME="nvim-macos" + # for some reason the archive has a different name + RELEASE_NAME="nvim-osx64" +else + echo "$OS platform is not supported currently" + exit 1 +fi + +declare -r RELEASE_URL="https://github.com/neovim/neovim/releases/$RELEASE_VER/download/$ARCHIVE_NAME.tar.gz" +declare -r CHECKSUM_URL="$RELEASE_URL.sha256sum" + +DOWNLOAD_DIR="$(mktemp -d)" +readonly DOWNLOAD_DIR + +RELEASE_SHA="$(curl -Ls "$CHECKSUM_URL" | awk '{print $1}')" +readonly RELEASE_SHA + +function main() { + if [ ! -d "$LV_INSTALL_PREFIX" ]; then + mkdir -p "$LV_INSTALL_PREFIX" || __invalid__prefix__handler + fi + download_neovim + verify_neovim + install_neovim +} + +function download_neovim() { + echo "Downloading Neovim's binary from $RELEASE_VER release.." + if ! curl --progress-bar --fail -L "$RELEASE_URL" -o "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz"; then + echo "Download failed. Check that the release/filename are correct." + exit 1 + fi + echo "Download complete!" +} + +function verify_neovim() { + echo "Verifying the installation.." + DOWNLOADED_SHA="$(sha256sum "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz" | awk '{print $1}')" + + if [ "$RELEASE_SHA" != "$DOWNLOADED_SHA" ]; then + echo "Error! checksum mis-match." + echo "Expected: $RELEASE_SHA but got: $DOWNLOADED_SHA" + exit 1 + fi + echo "Verification complete!" +} + +function install_neovim() { + + echo "Installing Neovim.." + pushd "$DOWNLOAD_DIR" + tar -xzf "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz" + popd + # https://dev.to/ackshaey/macos-vs-linux-the-cp-command-will-trip-you-up-2p00 + cp -r "$DOWNLOAD_DIR/$RELEASE_NAME/." "$LV_INSTALL_PREFIX" + echo "Installation complete!" + echo "Now you can run $LV_INSTALL_PREFIX/bin/nvim" +} + +function __invalid__prefix__handler() { + echo "Error! Invalid value for LV_INSTALL_PREFIX: [$INSTALL_PREFIX]" + echo "Please verify that the folder exists and re-run the installer!" + exit 1 +} + +main "$@" From 944dd4893508161d5477d1313d9e0c4368968653 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 16 Aug 2021 11:22:40 +0430 Subject: [PATCH 21/64] fix clojure language server not starting up (#1330) --- lua/default-config.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/default-config.lua b/lua/default-config.lua index dd8a2043..85a907d1 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -287,7 +287,6 @@ lvim.lang = { setup = { cmd = { DATA_PATH .. "/lspinstall/clojure/clojure-lsp", - "--stdio", }, on_attach = common_on_attach, on_init = common_on_init, From 9b36872d886c632ca93479321cde1e0f00629e3c Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Mon, 16 Aug 2021 15:07:46 +0200 Subject: [PATCH 22/64] [Feature] Encapsulate interface logic (#1320) * Provide a utility function for aligning text * Replace lvim banner with one using only ASCII chars * Use strings.format instead of .. operator * Center text in the popup based on its dimentions * Minor improvements * Provide a popup factory function * Add function documentation * Improve text alignment * Print marker only if provider list is not empty * Format client capabilities as list * Pretty format lsp client capabilities * Add a metatable to popup.lua * Improve rendering when no lsp is available * Take cmdheight into acount when computing popup size and pos Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com> --- lua/core/info.lua | 237 +++++++++++++++++----------------------- lua/interface/popup.lua | 62 +++++++++++ lua/interface/text.lua | 79 ++++++++++++++ 3 files changed, 242 insertions(+), 136 deletions(-) create mode 100644 lua/interface/popup.lua create mode 100644 lua/interface/text.lua diff --git a/lua/core/info.lua b/lua/core/info.lua index d5bd94ce..d9b348b5 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -1,128 +1,63 @@ -local M = {} -local indent = " " - -M.banner = { - " ", - indent - .. "⠀⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀ ⠀⠀⠀ ⠀⠀ ⣺⡿⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀", - indent - .. "⠀⣿⠇⠀⠀⠀⠀⠀⣤⡄⠀⠀⢠⣤⡄⠀.⣠⣤⣤⣤⡀⠀⠀⢀⣤⣤⣤⣤⡄⠀⠀⠀⣤⣄⣤⣤⣤⠀⠀ ⣿⣯ ⣿⡟⠀ ⣤⣤⠀⠀⠀⠀⣠⣤⣤⣤⣄⣤⣤", - indent - .. "⢠⣿⠀⠀⠀⠀⠀⠀⣿⠃⠀⠀⣸⣿⠁⠀⣿⣿⠉⠀⠈⣿⡇⠀⠀⠛⠋⠀⠀⢹⣿⠀⠀⠀⣿⠏⠀⠸⠿⠃⠀⣿⣿⠀⣰⡟⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡟⢸⣿⡇⢀⣿", - indent - .. "⣸⡇⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⣿⡟⠀⢠⣿⡇⠀⠀⢰⣿⡇⠀⣰⣾⠟⠛⠛⣻⡇⠀⠀⢸⡿⠀⠀⠀⠀⠀⠀⢻⣿⢰⣿⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⢸⣿⠇⢸⣿⠀⢸⡏", - indent - .. "⣿⣧⣤⣤⣤⡄⠀⠘⣿⣤⣤⡤⣿⠇⠀⢸⣿⠁⠀⠀⣼⣿⠀⠀⢿⣿⣤⣤⠔⣿⠃⠀⠀⣾⡇⠀⠀⠀⠀⠀⠀⢸⣿⣿⠋⠀⠀⠀⢠⣤⣤⣿⣥⣤⡄⠀⣼⣿⠀⣸⡏⠀⣿⠃", - indent - .. "⠉⠉⠉⠉⠉⠁⠀⠀⠈⠉⠉⠀⠉⠀⠀⠈⠉⠀⠀⠀⠉⠉⠀⠀⠀⠉⠉⠁⠈⠉⠀⠀⠀⠉⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠀⠀⠀⠀⠈⠉⠉⠉⠉⠉⠁⠀⠉⠁⠀⠉⠁⠀⠉⠀", - "", +local M = { + banner = { + "", + [[ __ _ ___ ]], + [[ / / __ ______ ____ _____| | / (_)___ ___ ]], + [[ / / / / / / __ \/ __ `/ ___/ | / / / __ `__ \]], + [[ / /___/ /_/ / / / / /_/ / / | |/ / / / / / / /]], + [[/_____/\__,_/_/ /_/\__,_/_/ |___/_/_/ /_/ /_/ ]], + }, } +local fmt = string.format + local function str_list(list) - return "[ " .. table.concat(list, ", ") .. " ]" + return fmt("[ %s ]", table.concat(list, ", ")) end local function get_formatter_suggestion_msg(ft) local null_formatters = require "lsp.null-ls.formatters" local supported_formatters = null_formatters.list_available(ft) - return { - indent - .. "───────────────────────────────────────────────────────────────────", - "", - indent .. " HINT ", - "", - indent .. "* List of supported formatters: " .. str_list(supported_formatters), - indent .. "* Configured formatter needs to be installed and executable.", - indent .. "* Enable installed formatter(s) with following config in ~/.config/lvim/config.lua", - "", - indent .. " lvim.lang." .. tostring(ft) .. [[.formatters = { { exe = ']] .. table.concat( - supported_formatters, - "│" - ) .. [[' } }]], + local section = { + " HINT ", "", + fmt("* List of supported formatters: %s", str_list(supported_formatters)), } + + if not vim.tbl_isempty(supported_formatters) then + vim.list_extend(section, { + "* Configured formatter needs to be installed and executable.", + fmt("* Enable installed formatter(s) with following config in %s", USER_CONFIG_PATH), + "", + fmt(" lvim.lang.%s.formatters = { { exe = '%s' } }", ft, table.concat(supported_formatters, "│")), + }) + end + + return section end local function get_linter_suggestion_msg(ft) local null_linters = require "lsp.null-ls.linters" local supported_linters = null_linters.list_available(ft) - return { - indent - .. "───────────────────────────────────────────────────────────────────", - "", - indent .. " HINT ", - "", - indent .. "* List of supported linters: " .. str_list(supported_linters), - indent .. "* Configured linter needs to be installed and executable.", - indent .. "* Enable installed linter(s) with following config in ~/.config/lvim/config.lua", - "", - indent - .. " lvim.lang." - .. tostring(ft) - .. [[.linters = { { exe = ']] - .. table.concat(supported_linters, "│") - .. [[' } }]], + local section = { + " HINT ", "", + fmt("* List of supported linters: %s", str_list(supported_linters)), } -end ----creates an average size popup ----@param buf_lines a list of lines to print ----@param callback could be used to set syntax highlighting rules for example ----@return bufnr buffer number of the created buffer ----@return win_id window ID of the created popup -function M.create_simple_popup(buf_lines, callback) - -- runtime/lua/vim/lsp/util.lua - local bufnr = vim.api.nvim_create_buf(false, true) - local height_percentage = 0.9 - local width_percentage = 0.8 - local row_start_percentage = (1 - height_percentage) / 2 - local col_start_percentage = (1 - width_percentage) / 2 - local opts = {} - opts.relative = "editor" - opts.height = math.min(math.ceil(vim.o.lines * height_percentage), #buf_lines) - opts.row = math.ceil(vim.o.lines * row_start_percentage) - opts.col = math.floor(vim.o.columns * col_start_percentage) - opts.width = math.floor(vim.o.columns * width_percentage) - opts.style = "minimal" - opts.border = "rounded" - --[[ - opts.border = { - lvim.builtin.telescope.defaults.borderchars[5], -- "┌", - lvim.builtin.telescope.defaults.borderchars[3], -- "-", - lvim.builtin.telescope.defaults.borderchars[6], -- "┐", - lvim.builtin.telescope.defaults.borderchars[2], -- "|", - lvim.builtin.telescope.defaults.borderchars[7], -- "┘", - lvim.builtin.telescope.defaults.borderchars[3], -- "-", - lvim.builtin.telescope.defaults.borderchars[8], -- "└", - lvim.builtin.telescope.defaults.borderchars[4], -- "|", - } - --]] - - local win_id = vim.api.nvim_open_win(bufnr, true, opts) - - vim.api.nvim_win_set_buf(win_id, bufnr) - -- this needs to be window option! - vim.api.nvim_win_set_option(win_id, "number", false) - vim.cmd "setlocal nocursorcolumn" - vim.cmd "setlocal wrap" - -- set buffer options - vim.api.nvim_buf_set_option(bufnr, "filetype", "lspinfo") - vim.lsp.util.close_preview_autocmd({ "BufHidden", "BufLeave" }, win_id) - buf_lines = vim.lsp.util._trim(buf_lines, {}) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, buf_lines) - vim.api.nvim_buf_set_option(bufnr, "modifiable", false) - if type(callback) == "function" then - callback() + if not vim.tbl_isempty(supported_linters) then + vim.list_extend(section, { + "* Configured linter needs to be installed and executable.", + fmt("* Enable installed linter(s) with following config in %s", USER_CONFIG_PATH), + "", + fmt(" lvim.lang.%s.linters = { { exe = '%s' } }", ft, table.concat(supported_linters, "│")), + }) end - return bufnr, win_id + + return section end local function tbl_set_highlight(terms, highlight_group) - if type(terms) ~= "table" then - return - end - for _, v in pairs(terms) do vim.cmd('let m=matchadd("' .. highlight_group .. '", "' .. v .. "[ ,│']\")") end @@ -136,67 +71,90 @@ function M.toggle_popup(ft) local client_name = "" local client_id = 0 local document_formatting = false - local num_caps = 0 if client ~= nil then is_client_active = not client.is_stopped() client_enabled_caps = require("lsp").get_ls_capabilities(client.id) - num_caps = vim.tbl_count(client_enabled_caps) client_name = client.name client_id = client.id document_formatting = client.resolved_capabilities.document_formatting end - local buf_lines = {} - vim.list_extend(buf_lines, M.banner) - local header = { - indent .. "Detected filetype: " .. tostring(ft), - indent .. "Treesitter active: " .. tostring(next(vim.treesitter.highlighter.active) ~= nil), - "", + fmt("Detected filetype: %s", ft), + fmt("Treesitter active: %s", tostring(next(vim.treesitter.highlighter.active) ~= nil)), } - vim.list_extend(buf_lines, header) + local text = require "interface.text" local lsp_info = { - indent .. "Language Server Protocol (LSP) info", - indent .. "* Associated server: " .. client_name, - indent .. "* Active: " .. tostring(is_client_active) .. " (id: " .. tostring(client_id) .. ")", - indent .. "* Supports formatting: " .. tostring(document_formatting), - indent .. "* Capabilities list: " .. table.concat(vim.list_slice(client_enabled_caps, 1, num_caps / 2), ", "), - indent .. indent .. indent .. table.concat(vim.list_slice(client_enabled_caps, ((num_caps / 2) + 1)), ", "), - "", + "Language Server Protocol (LSP) info", + fmt("* Associated server: %s", client_name), + fmt("* Active: %s (id: %d)", tostring(is_client_active), client_id), + fmt("* Supports formatting: %s", tostring(document_formatting)), } - vim.list_extend(buf_lines, lsp_info) - + if not vim.tbl_isempty(client_enabled_caps) then + local caps_text = "* Capabilities list: " + local caps_text_len = caps_text:len() + local enabled_caps = text.format_table(client_enabled_caps, 3, " | ") + enabled_caps = text.shift_left(enabled_caps, caps_text_len) + enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1)) + vim.list_extend(lsp_info, enabled_caps) + end local null_ls = require "lsp.null-ls" local registered_providers = null_ls.list_supported_provider_names(ft) + local registered_count = vim.tbl_count(registered_providers) local null_ls_info = { - indent .. "Formatters and linters", - indent .. "* Configured providers: " .. table.concat(registered_providers, "  , ") .. "  ", + "Formatters and linters", + fmt( + "* Configured providers: %s%s", + table.concat(registered_providers, "  , "), + registered_count > 0 and "  " or "" + ), } - vim.list_extend(buf_lines, null_ls_info) local null_formatters = require "lsp.null-ls.formatters" local missing_formatters = null_formatters.list_unsupported_names(ft) - if vim.tbl_count(missing_formatters) > 0 then - local missing_formatters_status = { - indent .. "* Missing formatters: " .. table.concat(missing_formatters, "  , ") .. "  ", + local missing_formatters_status = {} + if not vim.tbl_isempty(missing_formatters) then + missing_formatters_status = { + fmt("* Missing formatters: %s", table.concat(missing_formatters, "  , ") .. "  "), } - vim.list_extend(buf_lines, missing_formatters_status) end local null_linters = require "lsp.null-ls.linters" local missing_linters = null_linters.list_unsupported_names(ft) - if vim.tbl_count(missing_linters) > 0 then - local missing_linters_status = { - indent .. "* Missing linters: " .. table.concat(missing_linters, "  , ") .. "  ", + local missing_linters_status = {} + if not vim.tbl_isempty(missing_linters) then + missing_linters_status = { + fmt("* Missing linters: %s", table.concat(missing_linters, "  , ") .. "  "), } - vim.list_extend(buf_lines, missing_linters_status) end - vim.list_extend(buf_lines, { "" }) + local content_provider = function(popup) + local content = {} - vim.list_extend(buf_lines, get_formatter_suggestion_msg(ft)) - vim.list_extend(buf_lines, get_linter_suggestion_msg(ft)) + for _, section in ipairs { + M.banner, + { "" }, + { "" }, + header, + { "" }, + lsp_info, + { "" }, + null_ls_info, + missing_formatters_status, + missing_linters_status, + { "" }, + { "" }, + get_formatter_suggestion_msg(ft), + { "" }, + { "" }, + get_linter_suggestion_msg(ft), + } do + vim.list_extend(content, section) + end + + return text.align(popup, content, 0.5) + end local function set_syntax_hl() vim.cmd [[highlight LvimInfoIdentifier gui=bold]] @@ -214,6 +172,13 @@ function M.toggle_popup(ft) vim.cmd('let m=matchadd("LvimInfoIdentifier", "' .. client_name .. '")') end - return M.create_simple_popup(buf_lines, set_syntax_hl) + local Popup = require("interface.popup"):new { + win_opts = { number = false }, + buf_opts = { modifiable = false, filetype = "lspinfo" }, + } + Popup:display(content_provider) + set_syntax_hl() + + return Popup end return M diff --git a/lua/interface/popup.lua b/lua/interface/popup.lua new file mode 100644 index 00000000..b628125c --- /dev/null +++ b/lua/interface/popup.lua @@ -0,0 +1,62 @@ +local Popup = {} + +--- Create a new floating window +-- @param config The configuration passed to vim.api.nvim_open_win +-- @param win_opts The options registered with vim.api.nvim_win_set_option +-- @param buf_opts The options registered with vim.api.nvim_buf_set_option +-- @return A new popup +function Popup:new(opts) + opts = opts or {} + opts.layout = opts.layout or {} + opts.win_opts = opts.win_opts or {} + opts.buf_opts = opts.buf_opts or {} + + Popup.__index = Popup + + local editor_layout = { + height = vim.o.lines - vim.o.cmdheight - 2, -- Add margin for status and buffer line + width = vim.o.columns, + } + local popup_layout = { + relative = "editor", + height = math.floor(editor_layout.height * 0.9), + width = math.floor(editor_layout.width * 0.8), + style = "minimal", + border = "rounded", + } + popup_layout.row = math.floor((editor_layout.height - popup_layout.height) / 2) + popup_layout.col = math.floor((editor_layout.width - popup_layout.width) / 2) + + local obj = { + buffer = vim.api.nvim_create_buf(false, true), + layout = vim.tbl_deep_extend("force", popup_layout, opts.layout), + win_opts = opts.win_opts, + buf_opts = opts.buf_opts, + } + + setmetatable(obj, Popup) + + return obj +end + +--- Display the popup with the provided content +-- @param content_provider A function accepting the popup's layout and returning the content to display +function Popup:display(content_provider) + self.win_id = vim.api.nvim_open_win(self.buffer, true, self.layout) + vim.lsp.util.close_preview_autocmd({ "BufHidden", "BufLeave" }, self.win_id) + + local lines = content_provider(self.layout) + vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, lines) + + -- window options + for key, value in pairs(self.win_opts) do + vim.api.nvim_win_set_option(self.win_id, key, value) + end + + -- buffer options + for key, value in pairs(self.buf_opts) do + vim.api.nvim_buf_set_option(self.buffer, key, value) + end +end + +return Popup diff --git a/lua/interface/text.lua b/lua/interface/text.lua new file mode 100644 index 00000000..f68cc491 --- /dev/null +++ b/lua/interface/text.lua @@ -0,0 +1,79 @@ +local M = {} + +local function max_len_line(lines) + local max_len = 0 + + for _, line in ipairs(lines) do + local line_len = line:len() + if line_len > max_len then + max_len = line_len + end + end + + return max_len +end + +--- Center align lines relatively to the parent container +-- @param container The container where lines will be displayed +-- @param lines The text to align +-- @param alignment The alignment value, range: [0-1] +function M.align(container, lines, alignment) + local max_len = max_len_line(lines) + local indent_amount = math.ceil(math.max(container.width - max_len, 0) * alignment) + return M.shift_left(lines, indent_amount) +end + +--- Shift lines by a given amount +-- @params lines The lines the shift +-- @param amount The amount of spaces to add +function M.shift_left(lines, amount) + local output = {} + local padding = string.rep(" ", amount) + + for _, line in ipairs(lines) do + table.insert(output, padding .. line) + end + + return output +end + +--- Pretty format tables +-- @param entries The table to format +-- @param col_count The number of column to span the table on +-- @param col_sep The separator between each colummn, default: " " +function M.format_table(entries, col_count, col_sep) + col_sep = col_sep or " " + + local col_rows = math.ceil(vim.tbl_count(entries) / col_count) + local cols = {} + local count = 0 + + for i, entry in ipairs(entries) do + if ((i - 1) % col_rows) == 0 then + table.insert(cols, {}) + count = count + 1 + end + table.insert(cols[count], entry) + end + + local col_max_len = {} + for _, col in ipairs(cols) do + table.insert(col_max_len, max_len_line(col)) + end + + local output = {} + for i, col in ipairs(cols) do + for j, entry in ipairs(col) do + if not output[j] then + output[j] = entry + else + local padding = string.rep(" ", col_max_len[i - 1] - cols[i - 1][j]:len()) + output[j] = output[j] .. padding .. col_sep .. entry + end + end + end + + return output +end + +return M From ae1dea8b6499afbc35d3386654f9d0d8d208d342 Mon Sep 17 00:00:00 2001 From: dklymenk <64093836+dklymenk@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:31:03 +0300 Subject: [PATCH 23/64] [Feature] Expose null ls setup to user config (#1323) * expose null_ls setup to user config * add new config to example configs * fix tabs with stylua * change else statement in the example --- init.lua | 2 +- lua/default-config.lua | 3 +++ utils/installer/config.example-no-ts.lua | 15 +++++++++++++++ utils/installer/config.example.lua | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 0224a383..5844d79d 100644 --- a/init.lua +++ b/init.lua @@ -58,7 +58,7 @@ require("lsp").config() local null_status_ok, null_ls = pcall(require, "null-ls") if null_status_ok then null_ls.config {} - require("lspconfig")["null-ls"].setup {} + require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) end local lsp_settings_status_ok, lsp_settings = pcall(require, "nlspsettings") diff --git a/lua/default-config.lua b/lua/default-config.lua index 85a907d1..44da8954 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -104,6 +104,9 @@ lvim = { on_init_callback = nil, ---@usage query the project directory from the language server and use it to set the CWD smart_cwd = true, + null_ls = { + setup = {}, + }, }, plugins = { diff --git a/utils/installer/config.example-no-ts.lua b/utils/installer/config.example-no-ts.lua index b0de00f0..e5c24274 100644 --- a/utils/installer/config.example-no-ts.lua +++ b/utils/installer/config.example-no-ts.lua @@ -61,6 +61,21 @@ lvim.builtin.treesitter.highlight.enabled = true -- --Enable completion triggered by -- buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") -- end +-- you can overwrite the null_ls setup table (useful for setting the root_dir function) +-- lvim.lsp.null_ls.setup = { +-- root_dir = require("lspconfig").util.root_pattern("Makefile", ".git", "node_modules"), +-- } +-- or if you need something more advanced +-- lvim.lsp.null_ls.setup.root_dir = function(fname) +-- if vim.bo.filetype == "javascript" then +-- return require("lspconfig/util").root_pattern("Makefile", ".git", "node_modules")(fname) +-- or require("lspconfig/util").path.dirname(fname) +-- elseif vim.bo.filetype == "php" then +-- return require("lspconfig/util").root_pattern("Makefile", ".git", "composer.json")(fname) or vim.fn.getcwd() +-- else +-- return require("lspconfig/util").root_pattern("Makefile", ".git")(fname) or require("lspconfig/util").path.dirname(fname) +-- end +-- end -- set a formatter if you want to override the default lsp one (if it exists) -- lvim.lang.python.formatters = { diff --git a/utils/installer/config.example.lua b/utils/installer/config.example.lua index 1c39a571..2f8984bb 100644 --- a/utils/installer/config.example.lua +++ b/utils/installer/config.example.lua @@ -70,6 +70,21 @@ lvim.builtin.treesitter.highlight.enabled = true -- --Enable completion triggered by -- buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") -- end +-- you can overwrite the null_ls setup table (useful for setting the root_dir function) +-- lvim.lsp.null_ls.setup = { +-- root_dir = require("lspconfig").util.root_pattern("Makefile", ".git", "node_modules"), +-- } +-- or if you need something more advanced +-- lvim.lsp.null_ls.setup.root_dir = function(fname) +-- if vim.bo.filetype == "javascript" then +-- return require("lspconfig/util").root_pattern("Makefile", ".git", "node_modules")(fname) +-- or require("lspconfig/util").path.dirname(fname) +-- elseif vim.bo.filetype == "php" then +-- return require("lspconfig/util").root_pattern("Makefile", ".git", "composer.json")(fname) or vim.fn.getcwd() +-- else +-- return require("lspconfig/util").root_pattern("Makefile", ".git")(fname) or require("lspconfig/util").path.dirname(fname) +-- end +-- end -- set a formatter if you want to override the default lsp one (if it exists) -- lvim.lang.python.formatters = { From 8becb83eeba4c35c9d7fae90438f3d6ef60be790 Mon Sep 17 00:00:00 2001 From: rebuilt Date: Mon, 16 Aug 2021 18:46:36 +0200 Subject: [PATCH 24/64] Check if emmet is active. Enable emmet completion if emmet language server is active (#1335) * Check if emmet is active. Enable emmet completion if it is active * move emmet check after the check for a space character * Check if emmet is active for the current buffer only --- lua/core/compe.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/core/compe.lua b/lua/core/compe.lua index b5b37805..9edb2af0 100644 --- a/lua/core/compe.lua +++ b/lua/core/compe.lua @@ -77,6 +77,17 @@ M.setup = function() end end + local is_emmet_active = function() + local clients = vim.lsp.buf_get_clients() + + for _, client in pairs(clients) do + if client.name == "emmet_ls" then + return true + end + end + return false + end + -- Use (s-)tab to: --- move to prev/next item in completion menuone --- jump to prev/next snippet's placeholder @@ -87,8 +98,9 @@ M.setup = function() return t "(vsnip-jump-next)" elseif check_back_space() then return t "" + elseif is_emmet_active() then + return vim.fn["compe#complete"]() else - -- return vim.fn["compe#complete"]() -- < use this if you want to always offer completion return t "" end end From c76cc0ea8ae793b4feb0c28407d0f0de104aef43 Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Mon, 16 Aug 2021 20:10:53 -0400 Subject: [PATCH 25/64] fix java again, this file cannot be formatted, don't ask me why, because I have no idea --- utils/bin/jdtls | 66 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/utils/bin/jdtls b/utils/bin/jdtls index 961d2df5..adfd5e20 100755 --- a/utils/bin/jdtls +++ b/utils/bin/jdtls @@ -1,5 +1,4 @@ #!/usr/bin/env bash -# shellcheck disable=SC2116 # NOTE: # This doesn't work as is on Windows. You'll need to create an equivalent `.bat` file instead @@ -8,33 +7,32 @@ # If you're not using Linux you'll need to adjust the `-configuration` option # to point to the `config_mac' or `config_win` folders depending on your system. -OS="$(uname -s)" -case "$OS" in - Linux) - CONFIG="$HOME/.local/share/nvim/lspinstall/java/config_linux" - ;; - Darwin) - CONFIG="$HOME/.local/share/nvim/lspinstall/java/config_mac" - ;; +case Darwin in +Linux) + CONFIG="$HOME/.local/share/nvim/lspinstall/java/config_linux" + ;; +Darwin) + CONFIG="$HOME/.local/share/nvim/lspinstall/java/config_mac" + ;; esac # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ]; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ]; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi + fi else - JAVACMD="java" - command -v java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." @@ -43,20 +41,20 @@ fi # JAR="$HOME/.config/nvim/.language-servers/eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository/plugins/org.eclipse.equinox.launcher_*.jar" JAR="$HOME/.local/share/nvim/lspinstall/java/plugins/org.eclipse.equinox.launcher_*.jar" GRADLE_HOME=$HOME/gradle "$JAVACMD" \ - -Declipse.application=org.eclipse.jdt.ls.core.id1 \ - -Dosgi.bundles.defaultStartLevel=4 \ - -Declipse.product=org.eclipse.jdt.ls.core.product \ - -Dlog.protocol=true \ - -Dlog.level=ALL \ - -javaagent:"$HOME/.local/share/nvim/lspinstall/java/lombok.jar" \ - -Xms1g \ - -Xmx2G \ - -jar "$(echo "$JAR")" \ - -configuration "$CONFIG" \ - -data "${1:-$HOME/workspace}" \ - --add-modules=ALL-SYSTEM \ - --add-opens java.base/java.util=ALL-UNNAMED \ - --add-opens java.base/java.lang=ALL-UNNAMED + -Declipse.application=org.eclipse.jdt.ls.core.id1 \ + -Dosgi.bundles.defaultStartLevel=4 \ + -Declipse.product=org.eclipse.jdt.ls.core.product \ + -Dlog.protocol=true \ + -Dlog.level=ALL \ + -javaagent:$HOME/.local/share/nvim/lspinstall/java/lombok.jar \ + -Xms1g \ + -Xmx2G \ + -jar $(echo "$JAR") \ + -configuration "$CONFIG" \ + -data "${1:-$HOME/workspace}" \ + --add-modules=ALL-SYSTEM \ + --add-opens java.base/java.util=ALL-UNNAMED \ + --add-opens java.base/java.lang=ALL-UNNAMED # for older java versions if you wanna use lombok # -Xbootclasspath/a:/usr/local/share/lombok/lombok.jar \ From 1cc2452eb7b76aad36a6d9d210abff88edf6721a Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Tue, 17 Aug 2021 12:07:11 +0430 Subject: [PATCH 26/64] [Bugfix] ignore jdtls to fix `CI` (#1339) --- .github/workflows/format.yaml | 2 +- .github/workflows/lint.yaml | 1 + .pre-commit-config.yaml | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 5f9db8cb..142ba7f1 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -40,5 +40,5 @@ jobs: # https://google.github.io/styleguide/shellguide.html - name: Check formatting run: | - shfmt -i 2 -ci -l -d . + shfmt -f . | grep -v jdtls | xargs shfmt -i 2 -ci -l -d diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index f5aab0eb..d187f497 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -32,3 +32,4 @@ jobs: uses: ludeeus/action-shellcheck@master with: scandir: './utils' + ignore: 'bin' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9172b0f1..8ecda3bd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,16 +5,16 @@ repos: name: shfmt minimum_pre_commit_version: 2.4.0 language: system - entry: shfmt - args: [-i=2, -ci, -w] types: [shell] + entry: bash + args: [-c, "shfmt -f $(git rev-parse --show-toplevel) | grep -v jdtls | xargs shfmt -i=2 -ci -w"] - id: shellcheck name: shellcheck language: system types: [shell] entry: bash args: - [-c, "shfmt -f $(git rev-parse --show-toplevel) | xargs shellcheck"] + [-c, "shfmt -f $(git rev-parse --show-toplevel) | grep -v jdtls | xargs shellcheck"] - id: stylua name: StyLua language: rust From 335e707b2aae38c0cd5d0d962b27038ab1117aa6 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Tue, 17 Aug 2021 17:20:18 +0200 Subject: [PATCH 27/64] [Feature] Make the rest of the builtins configurable (#1318) --- lua/core/autopairs.lua | 104 ++++++++++++++++++++++------------------- lua/core/comment.lua | 25 ++++++++++ lua/core/compe.lua | 2 +- lua/core/dashboard.lua | 17 ++----- lua/core/gitsigns.lua | 85 +++++++++++++++++---------------- lua/core/nvimtree.lua | 1 + lua/core/telescope.lua | 3 +- lua/core/which-key.lua | 3 +- lua/default-config.lua | 2 + lua/lsp/init.lua | 6 ++- lua/plugins.lua | 11 ++++- 11 files changed, 154 insertions(+), 105 deletions(-) create mode 100644 lua/core/comment.lua diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index a5f21a1b..470f8335 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -1,54 +1,64 @@ --- if not package.loaded['nvim-autopairs'] then --- return --- end -local Log = require "core.log" -local status_ok, _ = pcall(require, "nvim-autopairs") -if not status_ok then - Log:get_default().error "Failed to load autopairs" - return -end -local npairs = require "nvim-autopairs" -local Rule = require "nvim-autopairs.rule" +local M = {} --- skip it, if you use another global object -_G.MUtils = {} - -vim.g.completion_confirm_key = "" -MUtils.completion_confirm = function() - if vim.fn.pumvisible() ~= 0 then - if vim.fn.complete_info()["selected"] ~= -1 then - return vim.fn["compe#confirm"](npairs.esc "") - else - return npairs.esc "" - end - else - return npairs.autopairs_cr() - end -end - -if package.loaded["compe"] then - local map_complete_optional = vim.bo.filetype ~= "tex" - require("nvim-autopairs.completion.compe").setup { - map_cr = true, -- map on insert mode - map_complete = map_complete_optional, -- it will auto insert `(` after select function or method item +function M.config() + lvim.builtin.autopairs = { + active = true, + ---@usage map on insert mode + map_cr = true, + ---@usage auto insert after select function or method item + -- NOTE: This should be wrapped into a function so that it is re-evaluated when opening new files + map_complete = vim.bo.filetype ~= "tex", + ---@usage check treesitter + check_ts = true, + ts_config = { + lua = { "string" }, + javascript = { "template_string" }, + java = false, + }, } end -npairs.setup { - check_ts = true, - ts_config = { - lua = { "string" }, -- it will not add pair on that treesitter node - javascript = { "template_string" }, - java = false, -- don't check treesitter on java - }, -} +M.setup = function() + -- skip it, if you use another global object + _G.MUtils = {} + local npairs = require "nvim-autopairs" + local Rule = require "nvim-autopairs.rule" -require("nvim-treesitter.configs").setup { autopairs = { enable = true } } + vim.g.completion_confirm_key = "" + MUtils.completion_confirm = function() + if vim.fn.pumvisible() ~= 0 then + if vim.fn.complete_info()["selected"] ~= -1 then + return vim.fn["compe#confirm"](npairs.esc "") + else + return npairs.esc "" + end + else + return npairs.autopairs_cr() + end + end -local ts_conds = require "nvim-autopairs.ts-conds" + if package.loaded["compe"] then + require("nvim-autopairs.completion.compe").setup { + map_cr = lvim.builtin.autopairs.map_cr, + map_complete = lvim.builtin.autopairs.map_complete, + } + end --- press % => %% is only inside comment or string -npairs.add_rules { - Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }), - Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }), -} + npairs.setup { + check_ts = lvim.builtin.autopairs.check_ts, + ts_config = lvim.builtin.autopairs.ts_config, + } + + require("nvim-treesitter.configs").setup { autopairs = { enable = true } } + + local ts_conds = require "nvim-autopairs.ts-conds" + + -- TODO: can these rules be safely added from "config.lua" ? + -- press % => %% is only inside comment or string + npairs.add_rules { + Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }), + Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }), + } +end + +return M diff --git a/lua/core/comment.lua b/lua/core/comment.lua new file mode 100644 index 00000000..79d711b6 --- /dev/null +++ b/lua/core/comment.lua @@ -0,0 +1,25 @@ +local M = {} + +function M.config() + lvim.builtin.comment = { + active = true, + -- Linters prefer comment and line to have a space in between markers + marker_padding = true, + -- should comment out empty or whitespace only lines + comment_empty = false, + -- Should key mappings be created + create_mappings = true, + -- Normal mode mapping left hand side + line_mapping = "gcc", + -- Visual/Operator mapping left hand side + operator_mapping = "gc", + -- Hook function to call before commenting takes place + hook = nil, + } +end + +function M.setup() + require("nvim_comment").setup(lvim.builtin.comment) +end + +return M diff --git a/lua/core/compe.lua b/lua/core/compe.lua index 9edb2af0..29344d97 100644 --- a/lua/core/compe.lua +++ b/lua/core/compe.lua @@ -1,7 +1,7 @@ local M = {} M.config = function() lvim.builtin.compe = { - enabled = true, + active = true, autocomplete = true, debug = false, min_length = 1, diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index d5e5bfe9..649be14c 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -3,6 +3,8 @@ M.config = function() lvim.builtin.dashboard = { active = false, search_handler = "telescope", + disable_at_vim_enter = 0, + session_directory = os.getenv "HOME" .. "/.cache/lvim/sessions", custom_header = { "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣶⣾⠿⠿⠟⠛⠛⠛⠛⠿⠿⣿⣷⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", @@ -52,7 +54,7 @@ M.config = function() end M.setup = function() - vim.g.dashboard_disable_at_vimenter = 0 + vim.g.dashboard_disable_at_vimenter = lvim.builtin.dashboard.disable_at_vim_enter vim.g.dashboard_custom_header = lvim.builtin.dashboard.custom_header @@ -62,12 +64,8 @@ M.setup = function() lvim.builtin.which_key.mappings[";"] = { "Dashboard", "Dashboard" } - -- f = { - -- description = { " Neovim Config Files" }, - -- command = "Telescope find_files cwd=" .. CONFIG_PATH, - -- }, - -- e = {description = {' Marks '}, command = 'Telescope marks'} - vim.cmd 'let g:dashboard_session_directory = "~/.config/lvim/.sessions"' + vim.g.dashboard_session_directory = lvim.builtin.dashboard.session_directory + vim.cmd "let packages = len(globpath('~/.local/share/lunarvim/site/pack/packer/start', '*', 0, 1))" vim.api.nvim_exec( @@ -77,11 +75,6 @@ M.setup = function() false ) - -- file_browser = {description = {' File Browser'}, command = 'Telescope find_files'}, - - -- vim.g.dashboard_session_directory = CACHE_PATH..'/session' - -- vim.g.dashboard_custom_footer = lvim.dashboard.footer - require("core.autocmds").define_augroups { _dashboard = { -- seems to be nobuflisted that makes my stuff disappear will do more testing diff --git a/lua/core/gitsigns.lua b/lua/core/gitsigns.lua index 0c0efa91..80a31500 100644 --- a/lua/core/gitsigns.lua +++ b/lua/core/gitsigns.lua @@ -1,54 +1,57 @@ local M = {} M.config = function() lvim.builtin.gitsigns = { - signs = { - add = { - hl = "GitSignsAdd", - text = "▎", - numhl = "GitSignsAddNr", - linehl = "GitSignsAddLn", + active = true, + opts = { + signs = { + add = { + hl = "GitSignsAdd", + text = "▎", + numhl = "GitSignsAddNr", + linehl = "GitSignsAddLn", + }, + change = { + hl = "GitSignsChange", + text = "▎", + numhl = "GitSignsChangeNr", + linehl = "GitSignsChangeLn", + }, + delete = { + hl = "GitSignsDelete", + text = "契", + numhl = "GitSignsDeleteNr", + linehl = "GitSignsDeleteLn", + }, + topdelete = { + hl = "GitSignsDelete", + text = "契", + numhl = "GitSignsDeleteNr", + linehl = "GitSignsDeleteLn", + }, + changedelete = { + hl = "GitSignsChange", + text = "▎", + numhl = "GitSignsChangeNr", + linehl = "GitSignsChangeLn", + }, }, - change = { - hl = "GitSignsChange", - text = "▎", - numhl = "GitSignsChangeNr", - linehl = "GitSignsChangeLn", - }, - delete = { - hl = "GitSignsDelete", - text = "契", - numhl = "GitSignsDeleteNr", - linehl = "GitSignsDeleteLn", - }, - topdelete = { - hl = "GitSignsDelete", - text = "契", - numhl = "GitSignsDeleteNr", - linehl = "GitSignsDeleteLn", - }, - changedelete = { - hl = "GitSignsChange", - text = "▎", - numhl = "GitSignsChangeNr", - linehl = "GitSignsChangeLn", + numhl = false, + linehl = false, + keymaps = { + -- Default keymap options + noremap = true, + buffer = true, }, + watch_index = { interval = 1000 }, + sign_priority = 6, + update_debounce = 200, + status_formatter = nil, -- Use default }, - numhl = false, - linehl = false, - keymaps = { - -- Default keymap options - noremap = true, - buffer = true, - }, - watch_index = { interval = 1000 }, - sign_priority = 6, - update_debounce = 200, - status_formatter = nil, -- Use default } end M.setup = function() - require("gitsigns").setup(lvim.builtin.gitsigns) + require("gitsigns").setup(lvim.builtin.gitsigns.opts) end return M diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 25c69575..7c99a91e 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -3,6 +3,7 @@ local Log = require "core.log" -- M.config = function() lvim.builtin.nvimtree = { + active = true, side = "left", width = 30, show_icons = { diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index d31edef9..e72727a4 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -6,7 +6,8 @@ function M.config() end lvim.builtin.telescope = { - active = false, + ---@usage disable telescope completely [not recommeded] + active = true, defaults = { prompt_prefix = " ", selection_caret = " ", diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 04f892d8..ff53142c 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -1,7 +1,8 @@ local M = {} M.config = function() lvim.builtin.which_key = { - active = false, + ---@usage disable which-key completely [not recommeded] + active = true, setup = { plugins = { marks = true, -- shows a list of your marks on ' and ` diff --git a/lua/default-config.lua b/lua/default-config.lua index 44da8954..ed9b17d6 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -1303,3 +1303,5 @@ require("core.treesitter").config() require("core.nvimtree").config() require("core.rooter").config() require("core.bufferline").config() +require("core.autopairs").config() +require("core.comment").config() diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 891147e5..920aceb3 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -34,7 +34,11 @@ local function lsp_highlight_document(client) end local function add_lsp_buffer_keybindings(bufnr) - local wk = require "which-key" + local status_ok, wk = pcall(require, "which-key") + if not status_ok then + return + end + local keys = { ["K"] = { "lua vim.lsp.buf.hover()", "Show hover" }, ["gd"] = { "lua vim.lsp.buf.definition()", "Goto Definition" }, diff --git a/lua/plugins.lua b/lua/plugins.lua index 5353de5b..c9e7f3c2 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -27,6 +27,7 @@ return { lvim.builtin.telescope.on_config_done(require "telescope") end end, + disable = not lvim.builtin.telescope.active, }, -- Completion & Snippets @@ -39,6 +40,7 @@ return { lvim.builtin.compe.on_config_done(require "compe") end end, + disable = not lvim.builtin.compe.active, -- wants = "vim-vsnip", -- requires = { -- { @@ -56,10 +58,12 @@ return { "hrsh7th/vim-vsnip", -- wants = "friendly-snippets", event = "InsertEnter", + disable = not lvim.builtin.compe.active, }, { "rafamadriz/friendly-snippets", event = "InsertCharPre", + disable = not lvim.builtin.compe.active, }, -- Autopairs @@ -68,11 +72,12 @@ return { -- event = "InsertEnter", after = "nvim-compe", config = function() - require "core.autopairs" + require("core.autopairs").setup() if lvim.builtin.autopairs.on_config_done then lvim.builtin.autopairs.on_config_done(require "nvim-autopairs") end end, + disable = not lvim.builtin.autopairs.active or not lvim.builtin.compe.active, }, -- Treesitter @@ -100,6 +105,7 @@ return { lvim.builtin.nvimtree.on_config_done(require "nvim-tree.config") end end, + disable = not lvim.builtin.nvimtree.active, }, { @@ -112,6 +118,7 @@ return { end end, event = "BufRead", + disable = not lvim.builtin.gitsigns.active, }, -- Whichkey @@ -124,6 +131,7 @@ return { end end, event = "BufWinEnter", + disable = not lvim.builtin.which_key.active, }, -- Comments @@ -136,6 +144,7 @@ return { lvim.builtin.comment.on_config_done(require "nvim_comment") end end, + disable = not lvim.builtin.comment.active, }, -- vim-rooter From 08c0dca3071ec2df16553dd724836307999e6aef Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Tue, 17 Aug 2021 17:26:59 +0200 Subject: [PATCH 28/64] [Refactor]: Remove vim-rooter dependency (#1319) --- lua/lsp/null-ls/services.lua | 26 ++++++++++---------------- lua/lsp/utils.lua | 3 ++- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lua/lsp/null-ls/services.lua b/lua/lsp/null-ls/services.lua index 89073e5c..6f3516ad 100644 --- a/lua/lsp/null-ls/services.lua +++ b/lua/lsp/null-ls/services.lua @@ -1,29 +1,23 @@ local M = {} -local logger = require("core.log"):get_default() - local function find_root_dir() - if lvim.builtin.rooter.active then - --- use vim-rooter to set root_dir - vim.cmd "let root_dir = FindRootDirectory()" - return vim.api.nvim_get_var "root_dir" - end - - -- TODO: Rework this to not make it javascript specific - --- use LSP to set root_dir + local util = require "lspconfig/util" local lsp_utils = require "lsp.utils" - local ts_client = lsp_utils.get_active_client_by_ft "typescript" - if ts_client == nil then - logger.error "Unable to determine root directory since tsserver didn't start correctly" - return nil - end - return ts_client.config.root_dir + local status_ok, ts_client = lsp_utils.is_client_active "typescript" + if status_ok then + return ts_client.config.root_dir + end + local dirname = vim.fn.expand "%:p:h" + return util.root_pattern "package.json"(dirname) end local function from_node_modules(command) + local logger = require("core.log"):get_default() local root_dir = find_root_dir() + if not root_dir then + logger.error(string.format("Unable to find the [%s] node module.", command)) return nil end diff --git a/lua/lsp/utils.lua b/lua/lsp/utils.lua index e28c6085..17b9c3bc 100644 --- a/lua/lsp/utils.lua +++ b/lua/lsp/utils.lua @@ -4,12 +4,13 @@ function M.is_client_active(name) local clients = vim.lsp.get_active_clients() for _, client in pairs(clients) do if client.name == name then - return true + return true, client end end return false end +-- FIXME: this should return a list instead function M.get_active_client_by_ft(filetype) if not lvim.lang[filetype] or not lvim.lang[filetype].lsp then return nil From 21b621c95af592d0da46a29fe4dcc02e5d16c6eb Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Tue, 17 Aug 2021 21:08:19 +0200 Subject: [PATCH 29/64] fix: remove wrongful log entry from null-ls setup (#1341) --- lua/lsp/null-ls/services.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lua/lsp/null-ls/services.lua b/lua/lsp/null-ls/services.lua index 6f3516ad..a1e3a06c 100644 --- a/lua/lsp/null-ls/services.lua +++ b/lua/lsp/null-ls/services.lua @@ -13,11 +13,9 @@ local function find_root_dir() end local function from_node_modules(command) - local logger = require("core.log"):get_default() local root_dir = find_root_dir() if not root_dir then - logger.error(string.format("Unable to find the [%s] node module.", command)) return nil end From b9b9c69615b469146e3cc75adcf9bd61047404eb Mon Sep 17 00:00:00 2001 From: Ahmed Khalf Date: Wed, 18 Aug 2021 09:34:26 +0400 Subject: [PATCH 30/64] [Refactor]: Remove vim-rooter and smart-cwd; then use project.nvim (#1315) * Replace vim-rooter with project.nvim * Implement stylua format * Remove smart_cwd * Implicitly update nvim-tree dir when project active * Link datapath to cache * Fix stylua * Fix lint * Fix telescope bug * Fix telescope dependency * Fix telescope once and for all * Fix telescope once again --- lua/core/dashboard.lua | 11 ++++------ lua/core/nvimtree.lua | 6 ++++++ lua/core/project.lua | 48 ++++++++++++++++++++++++++++++++++++++++++ lua/core/rooter.lua | 15 ------------- lua/core/telescope.lua | 3 +++ lua/default-config.lua | 6 ++---- lua/lsp/init.lua | 9 -------- lua/plugins.lua | 13 ++++++------ 8 files changed, 69 insertions(+), 42 deletions(-) create mode 100644 lua/core/project.lua delete mode 100644 lua/core/rooter.lua diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index 649be14c..423cddd8 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -31,19 +31,16 @@ M.config = function() description = { " Find File " }, command = "Telescope find_files", }, - b = { + -- b is reserved for the core.project module + c = { description = { " Recently Used Files" }, command = "Telescope oldfiles", }, - -- c = { - -- description = { " Load Last Session " }, - -- command = "SessionLoad", - -- }, - c = { + d = { description = { " Find Word " }, command = "Telescope live_grep", }, - d = { + e = { description = { " Settings " }, command = ":e " .. USER_CONFIG_PATH, }, diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 7c99a91e..737f248e 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -60,6 +60,12 @@ M.setup = function() g["nvim_tree_" .. opt] = val end + -- Implicitly update nvim-tree when project module is active + if lvim.builtin.project.active then + vim.g.nvim_tree_update_cwd = 1 + vim.g.nvim_tree_respect_buf_cwd = 1 + end + local tree_cb = nvim_tree_config.nvim_tree_callback if not g.nvim_tree_bindings then diff --git a/lua/core/project.lua b/lua/core/project.lua new file mode 100644 index 00000000..650f2924 --- /dev/null +++ b/lua/core/project.lua @@ -0,0 +1,48 @@ +local M = {} +-- +function M.config() + lvim.builtin.project = { + --- This is on by default since it's currently the expected behavior. + ---@usage set to false to disable project.nvim. + active = true, + + -- Manual mode doesn't automatically change your root directory, so you have + -- the option to manually do so using `:ProjectRoot` command. + manual_mode = false, + + -- Methods of detecting the root directory. **"lsp"** uses the native neovim + -- lsp, while **"pattern"** uses vim-rooter like glob pattern matching. Here + -- order matters: if one is not detected, the other is used as fallback. You + -- can also delete or rearangne the detection methods. + detection_methods = { "lsp", "pattern" }, + + -- All the patterns used to detect root dir, when **"pattern"** is in + -- detection_methods + patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" }, + + -- When set to false, you will get a message when project.nvim changes your + -- directory. + silent_chdir = true, + } +end +-- +function M.setup() + local settings = lvim.builtin.project + + -- Table of lsp clients to ignore by name + -- eg: { "efm", ... } + settings["ignore_lsp"] = {} + + -- Path where project.nvim will store the project history for use in + -- telescope + settings["datapath"] = CACHE_PATH + + require("project_nvim").setup(settings) + + lvim.builtin.dashboard.custom_section["b"] = { + description = { " Recent Projects " }, + command = "Telescope projects", + } +end +-- +return M diff --git a/lua/core/rooter.lua b/lua/core/rooter.lua deleted file mode 100644 index 8ebdf7cc..00000000 --- a/lua/core/rooter.lua +++ /dev/null @@ -1,15 +0,0 @@ -local M = {} -function M.config() - lvim.builtin.rooter = { - --- This is on by default since it's currently the expected behavior. - ---@usage set to false to disable vim-rooter. - active = true, - silent_chdir = 1, - manual_only = 0, - } -end -function M.setup() - vim.g.rooter_silent_chdir = lvim.builtin.rooter.silent_chdir - vim.g.rooter_manual_only = lvim.builtin.rooter.manual_only -end -return M diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index e72727a4..5d9263d7 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -119,6 +119,9 @@ function M.setup() return end telescope.setup(lvim.builtin.telescope) + if lvim.builtin.project.active then + pcall(require("telescope").load_extension, "projects") + end end return M diff --git a/lua/default-config.lua b/lua/default-config.lua index ed9b17d6..f381b0b6 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -26,7 +26,7 @@ lvim = { gitsigns = {}, which_key = {}, comment = {}, - rooter = {}, + project = {}, galaxyline = {}, bufferline = {}, dap = {}, @@ -102,8 +102,6 @@ lvim = { popup_border = "single", on_attach_callback = nil, on_init_callback = nil, - ---@usage query the project directory from the language server and use it to set the CWD - smart_cwd = true, null_ls = { setup = {}, }, @@ -1301,7 +1299,7 @@ require("core.terminal").config() require("core.telescope").config() require("core.treesitter").config() require("core.nvimtree").config() -require("core.rooter").config() +require("core.project").config() require("core.bufferline").config() require("core.autopairs").config() require("core.comment").config() diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 920aceb3..1a6ceda3 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -55,14 +55,6 @@ local function add_lsp_buffer_keybindings(bufnr) wk.register(keys, { mode = "n", buffer = bufnr }) end -local function set_smart_cwd(client) - local proj_dir = client.config.root_dir - if lvim.lsp.smart_cwd and proj_dir ~= "/" then - vim.api.nvim_set_current_dir(proj_dir) - require("core.nvimtree").change_tree_dir(proj_dir) - end -end - function M.common_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true @@ -127,7 +119,6 @@ function M.common_on_attach(client, bufnr) end lsp_highlight_document(client) add_lsp_buffer_keybindings(bufnr) - set_smart_cwd(client) require("lsp.null-ls").setup(vim.bo.filetype) end diff --git a/lua/plugins.lua b/lua/plugins.lua index c9e7f3c2..1cf494bc 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -147,17 +147,16 @@ return { disable = not lvim.builtin.comment.active, }, - -- vim-rooter + -- project.nvim { - "airblade/vim-rooter", - -- event = "BufReadPre", + "ahmedkhalf/project.nvim", config = function() - require("core.rooter").setup() - if lvim.builtin.rooter.on_config_done then - lvim.builtin.rooter.on_config_done() + require("core.project").setup() + if lvim.builtin.project.on_config_done then + lvim.builtin.project.on_config_done() end end, - disable = not lvim.builtin.rooter.active, + disable = not lvim.builtin.project.active, }, -- Icons From a190306e477a95b7dd91e375c0cf82e0b72b1cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=C3=BAc=20L=C3=AA=20Kh=E1=BA=AFc?= Date: Wed, 18 Aug 2021 15:44:10 +0100 Subject: [PATCH 31/64] [Feature]: LSP Fortran (#1342) * null-ls needs to be pinned as well * unpin null-ls * lsp: fortran Co-authored-by: Abouzar Parvan Co-authored-by: christianchiarulli --- ftplugin/fortran.lua | 1 + lua/default-config.lua | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 ftplugin/fortran.lua diff --git a/ftplugin/fortran.lua b/ftplugin/fortran.lua new file mode 100644 index 00000000..36f4f484 --- /dev/null +++ b/ftplugin/fortran.lua @@ -0,0 +1 @@ +require("lsp").setup "fortran" diff --git a/lua/default-config.lua b/lua/default-config.lua index f381b0b6..0f9e6daa 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -486,6 +486,21 @@ lvim.lang = { }, }, }, + fortran = { + formatters = {}, + linters = {}, + lsp = { + provider = "fortls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/fortran/venv/bin/fortls", + }, + on_attach = common_on_attach, + on_init = common_on_init, + capabilities = common_capabilities, + }, + }, + }, go = { formatters = { -- { From a4073e9992010e3bcb429d266bc077dabf5956a7 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Thu, 19 Aug 2021 13:14:55 +0430 Subject: [PATCH 32/64] support nix language (#1347) --- ftdetect/nix.lua | 1 + ftplugin/nix.lua | 1 + lua/default-config.lua | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 ftdetect/nix.lua create mode 100644 ftplugin/nix.lua diff --git a/ftdetect/nix.lua b/ftdetect/nix.lua new file mode 100644 index 00000000..a85bcfdf --- /dev/null +++ b/ftdetect/nix.lua @@ -0,0 +1 @@ +vim.cmd [[ au BufRead,BufNewFile *.nix set filetype=nix ]] diff --git a/ftplugin/nix.lua b/ftplugin/nix.lua new file mode 100644 index 00000000..41152a75 --- /dev/null +++ b/ftplugin/nix.lua @@ -0,0 +1 @@ +require("lsp").setup "nix" diff --git a/lua/default-config.lua b/lua/default-config.lua index 0f9e6daa..09a25fd3 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -1301,6 +1301,31 @@ lvim.lang = { }, }, }, + nix = { + formatters = { + -- { + -- exe = "nixfmt", + -- args = {}, + -- }, + }, + linters = {}, + lsp = { + provider = "rnix", + setup = { + cmd = { "rnix-lsp" }, + filetypes = { "nix" }, + init_options = {}, + settings = {}, + root_dir = function(fname) + local util = require "lspconfig/util" + return util.root_pattern ".git"(fname) or vim.fn.getcwd() + end, + on_attach = common_on_attach, + on_init = common_on_init, + capabilities = common_capabilities, + }, + }, + }, } require("keymappings").config() From 0bf6fd68c625396d83eb8fca8d7248c5543ae6f1 Mon Sep 17 00:00:00 2001 From: Binx <68950943+Binx-Codes@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:44:21 +0400 Subject: [PATCH 33/64] rename settings to configuration in dashboard (#1350) --- lua/core/dashboard.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index 423cddd8..f98721cc 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -41,7 +41,7 @@ M.config = function() command = "Telescope live_grep", }, e = { - description = { " Settings " }, + description = { " Configuration " }, command = ":e " .. USER_CONFIG_PATH, }, }, From 1f45d1531d3636102f8971f8b2103b5302f48b68 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Thu, 19 Aug 2021 18:30:44 +0430 Subject: [PATCH 34/64] [Bugfix] fix formatter/linter nil issue (#1353) * fix formatter/linter issue for undefined lang/filetypes * revrese the order --- lua/default-config.lua | 2 +- lua/lsp/null-ls/formatters.lua | 2 +- lua/lsp/null-ls/linters.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/default-config.lua b/lua/default-config.lua index 09a25fd3..7e8ebea6 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -1189,7 +1189,7 @@ lvim.lang = { }, vim = { formatters = {}, - linters = { "" }, + linters = {}, lsp = { provider = "vimls", setup = { diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index d6ede29d..cae1fa7d 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -63,7 +63,7 @@ function M.list_configured(formatter_configs) end function M.setup(filetype, options) - if formatters_by_ft[filetype] and not options.force_reload then + if not lvim.lang[filetype] or (formatters_by_ft[filetype] and not options.force_reload) then return end diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index 64d2db4a..b449a4f2 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -63,7 +63,7 @@ function M.list_configured(linter_configs) end function M.setup(filetype, options) - if linters_by_ft[filetype] and not options.force_reload then + if not lvim.lang[filetype] or (linters_by_ft[filetype] and not options.force_reload) then return end From 59598723077ac6728fc585c3c88e0ec84ba430c3 Mon Sep 17 00:00:00 2001 From: Ahmed Khalf Date: Fri, 20 Aug 2021 11:31:18 +0400 Subject: [PATCH 35/64] [Refactor]: consistent update of bufferline offset with nvim-tree (#1351) * Refactor nvim-tree * Fix stylua comments * Delete useless functions * Remove autocmd and fix tasty's bug * Fix luacheck * Fix icon issue * Fix formatting * Fix formatting again * Resolve Tasty's request * Replace double dashes with blank line --- lua/core/nvimtree.lua | 80 +++++++++++++++--------------------------- lua/core/which-key.lua | 1 - 2 files changed, 29 insertions(+), 52 deletions(-) diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 737f248e..ff52029d 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -1,6 +1,6 @@ local M = {} local Log = require "core.log" --- + M.config = function() lvim.builtin.nvimtree = { active = true, @@ -47,7 +47,7 @@ M.config = function() }, } end --- + M.setup = function() local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") if not status_ok then @@ -73,64 +73,42 @@ M.setup = function() { key = { "l", "", "o" }, cb = tree_cb "edit" }, { key = "h", cb = tree_cb "close_node" }, { key = "v", cb = tree_cb "vsplit" }, - { key = "q", cb = ":lua require('core.nvimtree').toggle_tree()" }, } end -end --- -M.focus_or_close = function() - local view_status_ok, view = pcall(require, "nvim-tree.view") - if not view_status_ok then - return - end - local a = vim.api - local curwin = a.nvim_get_current_win() - local curbuf = a.nvim_win_get_buf(curwin) - local bufnr = view.View.bufnr - local winnr = view.get_winnr() + lvim.builtin.which_key.mappings["e"] = { "NvimTreeToggle", "Explorer" } - if view.win_open() then - if curwin == winnr and curbuf == bufnr then - view.close() - if package.loaded["bufferline.state"] then - require("bufferline.state").set_offset(0) - end - else - view.focus() - end - else - view.open() - if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then - -- require'bufferline.state'.set_offset(lvim.builtin.nvimtree.width + 1, 'File Explorer') - require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "") - end + local tree_view = require "nvim-tree.view" + + -- Add nvim_tree open callback + local open = tree_view.open + tree_view.open = function() + M.on_open() + open() + end + + vim.cmd "au WinClosed * lua require('core.nvimtree').on_close()" +end + +M.on_open = function() + if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then + require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "") end end --- -M.toggle_tree = function() - local view_status_ok, view = pcall(require, "nvim-tree.view") - if not view_status_ok then - return - end - if view.win_open() then - require("nvim-tree").close() - if package.loaded["bufferline.state"] then - require("bufferline.state").set_offset(0) - end - else - if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then - -- require'bufferline.state'.set_offset(lvim.builtin.nvimtree.width + 1, 'File Explorer') - require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "") - end - require("nvim-tree").toggle() + +M.on_close = function() + local buf = tonumber(vim.fn.expand "") + local ft = vim.api.nvim_buf_get_option(buf, "filetype") + if ft == "NvimTree" and package.loaded["bufferline.state"] then + require("bufferline.state").set_offset(0) end end --- + function M.change_tree_dir(dir) - if vim.g.loaded_tree then - require("nvim-tree.lib").change_dir(dir) + local lib_status_ok, lib = pcall(require, "nvim-tree.lib") + if lib_status_ok then + lib.change_dir(dir) end end --- + return M diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index ff53142c..5b249430 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -66,7 +66,6 @@ M.config = function() ["q"] = { "q!", "Quit" }, ["/"] = { "CommentToggle", "Comment" }, ["c"] = { "BufferClose!", "Close Buffer" }, - ["e"] = { "lua require'core.nvimtree'.toggle_tree()", "Explorer" }, ["f"] = { "Telescope find_files", "Find File" }, ["h"] = { "nohlsearch", "No Highlight" }, b = { From 85fe093efb8353552171575809c02a5e9124fa68 Mon Sep 17 00:00:00 2001 From: chaeing Date: Fri, 20 Aug 2021 02:16:29 -0700 Subject: [PATCH 36/64] [Feature] switch galaxyline to lualine (#1329) --- lua/core/galaxyline.lua | 348 -------------------------------- lua/core/lualine/colors.lua | 16 ++ lua/core/lualine/components.lua | 130 ++++++++++++ lua/core/lualine/conditions.lua | 17 ++ lua/core/lualine/init.lua | 47 +++++ lua/core/lualine/styles.lua | 170 ++++++++++++++++ lua/core/lualine/utils.lua | 24 +++ lua/core/status_colors.lua | 20 -- lua/default-config.lua | 4 +- lua/plugins.lua | 12 +- lua/utils/init.lua | 2 +- 11 files changed, 412 insertions(+), 378 deletions(-) delete mode 100644 lua/core/galaxyline.lua create mode 100644 lua/core/lualine/colors.lua create mode 100644 lua/core/lualine/components.lua create mode 100644 lua/core/lualine/conditions.lua create mode 100644 lua/core/lualine/init.lua create mode 100644 lua/core/lualine/styles.lua create mode 100644 lua/core/lualine/utils.lua delete mode 100644 lua/core/status_colors.lua diff --git a/lua/core/galaxyline.lua b/lua/core/galaxyline.lua deleted file mode 100644 index 0f31ef53..00000000 --- a/lua/core/galaxyline.lua +++ /dev/null @@ -1,348 +0,0 @@ --- if not package.loaded['galaxyline'] then --- return --- end -local Log = require "core.log" -local status_ok, gl = pcall(require, "galaxyline") -if not status_ok then - Log:get_default().error "Failed to load galaxyline" - return -end - --- NOTE: if someone defines colors but doesn't have them then this will break -local palette_status_ok, colors = pcall(require, lvim.colorscheme .. ".palette") -if not palette_status_ok then - colors = lvim.builtin.galaxyline.colors -end - -local condition = require "galaxyline.condition" -local gls = gl.section -gl.short_line_list = { "NvimTree", "vista", "dbui", "packer" } - -local function get_mode_name() - local names = { - n = "NORMAL", - i = "INSERT", - c = "COMMAND", - v = "VISUAL", - V = "VISUAL LINE", - t = "TERMINAL", - R = "REPLACE", - [""] = "VISUAL BLOCK", - } - return names[vim.fn.mode()] -end - -table.insert(gls.left, { - ViMode = { - provider = function() - -- auto change color according the vim mode - local mode_color = { - n = colors.blue, - i = colors.green, - v = colors.purple, - [""] = colors.purple, - V = colors.purple, - c = colors.magenta, - no = colors.blue, - s = colors.orange, - S = colors.orange, - [""] = colors.orange, - ic = colors.yellow, - R = colors.red, - Rv = colors.red, - cv = colors.blue, - ce = colors.blue, - r = colors.cyan, - rm = colors.cyan, - ["r?"] = colors.cyan, - ["!"] = colors.blue, - t = colors.blue, - } - if lvim.builtin.galaxyline.show_mode then - local name = get_mode_name() - -- Fall back to the default behavior is a name is not defined - if name ~= nil then - vim.api.nvim_command("hi GalaxyViMode guibg=" .. mode_color[vim.fn.mode()]) - vim.api.nvim_command("hi GalaxyViMode guifg=" .. colors.alt_bg) - return " " .. name .. " " - end - end - vim.api.nvim_command("hi GalaxyViMode guibg=" .. colors.alt_bg) - vim.api.nvim_command("hi GalaxyViMode guifg=" .. mode_color[vim.fn.mode()]) - return "▊" - end, - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { "NONE", colors.alt_bg }, - }, -}) --- print(vim.fn.getbufvar(0, 'ts')) -vim.fn.getbufvar(0, "ts") - -table.insert(gls.left, { - GitIcon = { - provider = function() - return " " - end, - condition = condition.check_git_workspace, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.orange, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - GitBranch = { - provider = "GitBranch", - condition = condition.check_git_workspace, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - DiffAdd = { - provider = "DiffAdd", - condition = condition.hide_in_width, - icon = "  ", - highlight = { colors.green, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - DiffModified = { - provider = "DiffModified", - condition = condition.hide_in_width, - icon = " 柳", - highlight = { colors.blue, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - DiffRemove = { - provider = "DiffRemove", - condition = condition.hide_in_width, - icon = "  ", - highlight = { colors.red, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - Filler = { - provider = function() - return " " - end, - highlight = { colors.grey, colors.alt_bg }, - }, -}) --- get output from shell command -function os.capture(cmd, raw) - local f = assert(io.popen(cmd, "r")) - local s = assert(f:read "*a") - f:close() - if raw then - return s - end - s = string.gsub(s, "^%s+", "") - s = string.gsub(s, "%s+$", "") - s = string.gsub(s, "[\n\r]+", " ") - return s -end --- cleanup virtual env -local function env_cleanup(venv) - if string.find(venv, "/") then - local final_venv = venv - for w in venv:gmatch "([^/]+)" do - final_venv = w - end - venv = final_venv - end - return venv -end -local PythonEnv = function() - if vim.bo.filetype == "python" then - local venv = os.getenv "CONDA_DEFAULT_ENV" - if venv ~= nil then - return "  (" .. env_cleanup(venv) .. ")" - end - venv = os.getenv "VIRTUAL_ENV" - if venv ~= nil then - return "  (" .. env_cleanup(venv) .. ")" - end - return "" - end - return "" -end -table.insert(gls.left, { - VirtualEnv = { - provider = PythonEnv, - event = "BufEnter", - highlight = { colors.green, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - DiagnosticError = { - provider = "DiagnosticError", - icon = "  ", - highlight = { colors.red, colors.alt_bg }, - }, -}) -table.insert(gls.right, { - DiagnosticWarn = { - provider = "DiagnosticWarn", - icon = "  ", - highlight = { colors.orange, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - DiagnosticInfo = { - provider = "DiagnosticInfo", - icon = "  ", - highlight = { colors.yellow, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - DiagnosticHint = { - provider = "DiagnosticHint", - icon = "  ", - highlight = { colors.blue, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - TreesitterIcon = { - provider = function() - if next(vim.treesitter.highlighter.active) ~= nil then - return " " - end - return "" - end, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.green, colors.alt_bg }, - }, -}) - -local function get_attached_provider_name(msg) - msg = msg or "LSP Inactive" - - local buf_clients = vim.lsp.buf_get_clients() - if next(buf_clients) == nil then - return msg - end - - local buf_client_names = {} - for _, client in pairs(buf_clients) do - if client.name ~= "null-ls" then - table.insert(buf_client_names, client.name) - end - end - - local null_ls = require "lsp.null-ls" - local null_ls_providers = null_ls.list_supported_provider_names(vim.bo.filetype) - vim.list_extend(buf_client_names, null_ls_providers) - - return table.concat(buf_client_names, ", ") -end - -table.insert(gls.right, { - ShowLspClient = { - provider = get_attached_provider_name, - condition = function() - local tbl = { ["dashboard"] = true, [" "] = true } - if tbl[vim.bo.filetype] then - return false - end - return true - end, - icon = " ", - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - LineInfo = { - provider = "LineColumn", - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - PerCent = { - provider = "LinePercent", - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - Tabstop = { - provider = function() - local label = "Spaces: " - if not vim.api.nvim_buf_get_option(0, "expandtab") then - label = "Tab size: " - end - return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " - end, - condition = condition.hide_in_width, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - BufferType = { - provider = "FileTypeName", - condition = condition.hide_in_width, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - FileEncode = { - provider = "FileEncode", - condition = condition.hide_in_width, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - Space = { - provider = function() - return " " - end, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.short_line_left, { - BufferType = { - provider = "FileTypeName", - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.alt_bg, colors.alt_bg }, - }, -}) - -table.insert(gls.short_line_left, { - SFileName = { - provider = "SFileName", - condition = condition.buffer_not_empty, - highlight = { colors.alt_bg, colors.alt_bg }, - }, -}) - ---table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.alt_bg}}}) diff --git a/lua/core/lualine/colors.lua b/lua/core/lualine/colors.lua new file mode 100644 index 00000000..4984cd1f --- /dev/null +++ b/lua/core/lualine/colors.lua @@ -0,0 +1,16 @@ +local colors = { + bg = "#202328", + fg = "#bbc2cf", + yellow = "#ECBE7B", + cyan = "#008080", + darkblue = "#081633", + green = "#98be65", + orange = "#FF8800", + violet = "#a9a1e1", + magenta = "#c678dd", + purple = "#c678dd", + blue = "#51afef", + red = "#ec5f67", +} + +return colors diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua new file mode 100644 index 00000000..b9211a79 --- /dev/null +++ b/lua/core/lualine/components.lua @@ -0,0 +1,130 @@ +local conditions = require "core.lualine.conditions" +local colors = require "core.lualine.colors" + +return { + vi_mode = { + function() + return " " + end, + left_padding = 0, + right_padding = 0, + condition = conditions.hide_in_width, + }, + branch = { + "branch", + icon = " ", + condition = function() + return conditions.hide_in_width() and conditions.check_git_workspace() + end, + }, + diff = { + "diff", + symbols = { added = "  ", modified = "柳", removed = " " }, + color_added = { fg = colors.green }, + color_modified = { fg = colors.yellow }, + color_removed = { fg = colors.red }, + condition = conditions.hide_in_width, + }, + python_env = { + function() + local utils = require "core.lualine.utils" + if vim.bo.filetype == "python" then + local venv = os.getenv "CONDA_DEFAULT_ENV" + if venv then + return string.format("  (%s)", utils.env_cleanup(venv)) + end + venv = os.getenv "VIRTUAL_ENV" + if venv then + return string.format("  (%s)", utils.env_cleanup(venv)) + end + return "" + end + return "" + end, + color = { fg = colors.green }, + condition = conditions.hide_in_width, + }, + diagnostics = { + "diagnostics", + sources = { "nvim_lsp" }, + symbols = { error = " ", warn = " ", info = " ", hint = " " }, + condition = conditions.hide_in_width, + }, + treesitter = { + function() + if next(vim.treesitter.highlighter.active) then + return "  " + end + return "" + end, + color = { fg = colors.green }, + condition = conditions.hide_in_width, + }, + lsp = { + function(msg) + msg = msg or "LSP Inactive" + local buf_clients = vim.lsp.buf_get_clients() + if next(buf_clients) == nil then + return msg + end + local buf_ft = vim.bo.filetype + local buf_client_names = {} + + -- add client + local utils = require "lsp.utils" + local active_client = utils.get_active_client_by_ft(buf_ft) + for _, client in pairs(buf_clients) do + if client.name ~= "null-ls" then + table.insert(buf_client_names, client.name) + end + end + vim.list_extend(buf_client_names, active_client or {}) + + -- add formatter + local formatters = require "lsp.null-ls.formatters" + local supported_formatters = formatters.list_supported_names(buf_ft) + vim.list_extend(buf_client_names, supported_formatters) + + -- add linter + local linters = require "lsp.null-ls.linters" + local supported_linters = linters.list_supported_names(buf_ft) + vim.list_extend(buf_client_names, supported_linters) + + return table.concat(buf_client_names, ", ") + end, + condition = conditions.hide_in_width, + icon = " ", + color = { gui = "bold" }, + }, + location = { "location", condition = conditions.hide_in_width }, + progress = { "progress", condition = conditions.hide_in_width }, + spaces = { + function() + local label = "Spaces: " + if not vim.api.nvim_buf_get_option(0, "expandtab") then + label = "Tab size: " + end + return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " + end, + condition = conditions.hide_in_width, + }, + encoding = { + "o:encoding", + upper = true, + condition = conditions.hide_in_width, + }, + filetype = { "filetype", condition = conditions.hide_in_width }, + scrollbar = { + function() + local current_line = vim.fn.line "." + local total_lines = vim.fn.line "$" + local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" } + local line_ratio = current_line / total_lines + local index = math.ceil(line_ratio * #chars) + return chars[index] + end, + color = { fg = colors.yellow, bg = colors.bg }, + left_padding = 0, + right_padding = 0, + }, +} diff --git a/lua/core/lualine/conditions.lua b/lua/core/lualine/conditions.lua new file mode 100644 index 00000000..2d2d81ef --- /dev/null +++ b/lua/core/lualine/conditions.lua @@ -0,0 +1,17 @@ +local window_width_limit = 80 + +local conditions = { + buffer_not_empty = function() + return vim.fn.empty(vim.fn.expand "%:t") ~= 1 + end, + hide_in_width = function() + return vim.fn.winwidth(0) > window_width_limit + end, + check_git_workspace = function() + local filepath = vim.fn.expand "%:p:h" + local gitdir = vim.fn.finddir(".git", filepath .. ";") + return gitdir and #gitdir > 0 and #gitdir < #filepath + end, +} + +return conditions diff --git a/lua/core/lualine/init.lua b/lua/core/lualine/init.lua new file mode 100644 index 00000000..5b3ce2a1 --- /dev/null +++ b/lua/core/lualine/init.lua @@ -0,0 +1,47 @@ +local M = {} +M.config = function() + lvim.builtin.lualine = { + active = true, + style = "lvim", + options = { + icons_enabled = nil, + component_separators = nil, + section_separators = nil, + theme = nil, + disabled_filetypes = nil, + }, + sections = { + lualine_a = nil, + lualine_b = nil, + lualine_c = nil, + lualine_x = nil, + lualine_y = nil, + lualine_z = nil, + }, + inactive_sections = { + lualine_a = nil, + lualine_b = nil, + lualine_c = nil, + lualine_x = nil, + lualine_y = nil, + lualine_z = nil, + }, + tabline = nil, + extensions = nil, + on_config_done = nil, + } +end + +M.setup = function() + require("core.lualine.styles").update() + require("core.lualine.utils").validate_theme() + + local lualine = require "lualine" + lualine.setup(lvim.builtin.lualine) + + if lvim.builtin.lualine.on_config_done then + lvim.builtin.lualine.on_config_done(lualine, lvim.builtin.lualine) + end +end + +return M diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua new file mode 100644 index 00000000..e35f66fe --- /dev/null +++ b/lua/core/lualine/styles.lua @@ -0,0 +1,170 @@ +local M = {} +local components = require "core.lualine.components" + +local styles = { + lvim = nil, + default = nil, + none = nil, +} + +styles.none = { + style = "none", + options = { + icons_enabled = true, + component_separators = "", + section_separators = "", + disabled_filetypes = {}, + }, + sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = {}, +} + +styles.default = { + style = "default", + options = { + icons_enabled = true, + component_separators = { "", "" }, + section_separators = { "", "" }, + disabled_filetypes = {}, + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch" }, + lualine_c = { "filename" }, + lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = {}, +} + +styles.lvim = { + style = "lvim", + options = { + icons_enabled = true, + component_separators = "", + section_separators = "", + disabled_filetypes = { "dashboard", "" }, + }, + sections = { + lualine_a = { + components.vi_mode, + }, + lualine_b = { + components.branch, + }, + lualine_c = { + components.diff, + components.python_env, + }, + lualine_x = { + components.diagnostics, + components.treesitter, + components.lsp, + -- components.location, + -- components.progress, + -- components.spaces, + -- components.encoding, + components.filetype, + }, + lualine_y = { + -- components.filetype, + }, + lualine_z = { + components.scrollbar, + }, + }, + inactive_sections = { + lualine_a = { + "filename", + }, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = { "nvim-tree" }, +} + +function M.get_style(style) + local style_keys = vim.tbl_keys(styles) + if not vim.tbl_contains(style_keys, style) then + local Log = require "core.log" + local logger = Log:get_default() + logger.error( + "Invalid lualine style", + string.format('"%s"', style), + "options are: ", + string.format('"%s"', table.concat(style_keys, '", "')) + ) + logger.info '"lvim" style is applied.' + style = "lvim" + end + + return vim.deepcopy(styles[style]) +end + +function M.update() + local config = lvim.builtin.lualine + local style = M.get_style(config.style) + + lvim.builtin.lualine = { + active = true, + style = style.style, + options = { + icons_enabled = config.options.icons_enabled or style.options.icons_enabled, + component_separators = config.options.component_separators or style.options.component_separators, + section_separators = config.options.section_separators or style.options.section_separators, + theme = config.options.theme or lvim.colorscheme or "auto", + disabled_filetypes = config.options.disabled_filetypes or style.options.disabled_filetypes, + }, + sections = { + lualine_a = config.sections.lualine_a or style.sections.lualine_a, + lualine_b = config.sections.lualine_b or style.sections.lualine_b, + lualine_c = config.sections.lualine_c or style.sections.lualine_c, + lualine_x = config.sections.lualine_x or style.sections.lualine_x, + lualine_y = config.sections.lualine_y or style.sections.lualine_y, + lualine_z = config.sections.lualine_z or style.sections.lualine_z, + }, + inactive_sections = { + lualine_a = config.inactive_sections.lualine_a or style.inactive_sections.lualine_a, + lualine_b = config.inactive_sections.lualine_b or style.inactive_sections.lualine_b, + lualine_c = config.inactive_sections.lualine_c or style.inactive_sections.lualine_c, + lualine_x = config.inactive_sections.lualine_x or style.inactive_sections.lualine_x, + lualine_y = config.inactive_sections.lualine_y or style.inactive_sections.lualine_y, + lualine_z = config.inactive_sections.lualine_z or style.inactive_sections.lualine_z, + }, + tabline = config.tabline or style.tabline, + extensions = config.extensions or style.extensions, + on_config_done = config.on_config_done, + } +end + +return M diff --git a/lua/core/lualine/utils.lua b/lua/core/lualine/utils.lua new file mode 100644 index 00000000..f2f29592 --- /dev/null +++ b/lua/core/lualine/utils.lua @@ -0,0 +1,24 @@ +local M = {} + +function M.validate_theme() + local theme = lvim.builtin.lualine.options.theme + + local lualine_loader = require "lualine.utils.loader" + local ok = pcall(lualine_loader.load_theme, theme) + if not ok then + lvim.builtin.lualine.options.theme = "auto" + end +end + +function M.env_cleanup(venv) + if string.find(venv, "/") then + local final_venv = venv + for w in venv:gmatch "([^/]+)" do + final_venv = w + end + venv = final_venv + end + return venv +end + +return M diff --git a/lua/core/status_colors.lua b/lua/core/status_colors.lua deleted file mode 100644 index d6317309..00000000 --- a/lua/core/status_colors.lua +++ /dev/null @@ -1,20 +0,0 @@ -lvim.builtin.galaxyline = { - active = true, - show_mode = false, - colors = { - alt_bg = "#2E2E2E", - grey = "#858585", - blue = "#569CD6", - green = "#608B4E", - yellow = "#DCDCAA", - orange = "#FF8800", - purple = "#C586C0", - magenta = "#D16D9E", - cyan = "#4EC9B0", - red = "#D16969", - error_red = "#F44747", - warning_orange = "#FF8800", - info_yellow = "#FFCC66", - hint_blue = "#9CDCFE", - }, -} diff --git a/lua/default-config.lua b/lua/default-config.lua index 7e8ebea6..25e1d04a 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -27,7 +27,7 @@ lvim = { which_key = {}, comment = {}, project = {}, - galaxyline = {}, + lualine = {}, bufferline = {}, dap = {}, dashboard = {}, @@ -1330,7 +1330,6 @@ lvim.lang = { require("keymappings").config() require("core.which-key").config() -require "core.status_colors" require("core.gitsigns").config() require("core.compe").config() require("core.dashboard").config() @@ -1343,3 +1342,4 @@ require("core.project").config() require("core.bufferline").config() require("core.autopairs").config() require("core.comment").config() +require("core.lualine").config() diff --git a/lua/plugins.lua b/lua/plugins.lua index 1cf494bc..9aaea922 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -164,15 +164,13 @@ return { -- Status Line and Bufferline { - "glepnir/galaxyline.nvim", + -- "hoob3rt/lualine.nvim", + "shadmansaleh/lualine.nvim", + -- "Lunarvim/lualine.nvim", config = function() - require "core.galaxyline" - if lvim.builtin.galaxyline.on_config_done then - lvim.builtin.galaxyline.on_config_done(require "galaxyline") - end + require("core.lualine").setup() end, - event = "BufWinEnter", - disable = not lvim.builtin.galaxyline.active, + disable = not lvim.builtin.lualine.active, }, { diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 0f42623b..446a1509 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -88,6 +88,7 @@ function utils.toggle_autoformat() end function utils.reload_lv_config() + require("core.lualine").config() vim.cmd "source ~/.local/share/lunarvim/lvim/lua/settings.lua" vim.cmd("source " .. USER_CONFIG_PATH) require("keymappings").setup() -- this should be done before loading the plugins @@ -101,7 +102,6 @@ function utils.reload_lv_config() -- vim.cmd ":PackerClean" local null_ls = require "lsp.null-ls" null_ls.setup(vim.bo.filetype, { force_reload = true }) - Log:get_default().info "Reloaded configuration" end From 2bcbed14999f3c846028037c56ca855ef374d86c Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Fri, 20 Aug 2021 16:34:02 +0430 Subject: [PATCH 37/64] [feature] Move common parts of language server setup to lsp/init (#1355) * moving common parts of language server setup to lsp/init * fix formatting --- lua/default-config.lua | 154 +---------------------------------------- lua/lsp/init.lua | 11 +++ 2 files changed, 13 insertions(+), 152 deletions(-) diff --git a/lua/default-config.lua b/lua/default-config.lua index 25e1d04a..e88fee8d 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -115,10 +115,6 @@ lvim = { } local schemas = nil -local lsp = require "lsp" -local common_on_attach = lsp.common_on_attach -local common_capabilities = lsp.common_capabilities() -local common_on_init = lsp.common_on_init local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls") if status_ok then schemas = jsonls_settings.get_default_schemas() @@ -151,9 +147,6 @@ lvim.lang = { provider = "beancount", setup = { cmd = { "beancount-langserver" }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -180,9 +173,6 @@ lvim.lang = { "--clang-tidy", "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -209,9 +199,6 @@ lvim.lang = { "--clang-tidy", "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -227,9 +214,6 @@ lvim.lang = { provider = "crystalline", setup = { cmd = { "crystalline" }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -254,9 +238,6 @@ lvim.lang = { "--hostPID", tostring(vim.fn.getpid()), }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -274,9 +255,6 @@ lvim.lang = { cmd = { DATA_PATH .. "/lspinstall/cmake/venv/bin/cmake-language-server", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -289,9 +267,6 @@ lvim.lang = { cmd = { DATA_PATH .. "/lspinstall/clojure/clojure-lsp", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -315,9 +290,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -341,9 +313,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -359,9 +328,6 @@ lvim.lang = { provider = "serve_d", setup = { cmd = { "serve-d" }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -381,9 +347,6 @@ lvim.lang = { "/usr/lib/dart/bin/snapshots/analysis_server.dart.snapshot", "--lsp", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -397,9 +360,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/dockerfile/node_modules/.bin/docker-langserver", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -417,9 +377,6 @@ lvim.lang = { cmd = { DATA_PATH .. "/lspinstall/elixir/elixir-ls/language_server.sh", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -437,8 +394,6 @@ lvim.lang = { cmd = { DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-language-server", }, - on_attach = common_on_attach, - on_init = common_on_init, -- init_options = { -- elmAnalyseTrigger = "change", -- elmFormatPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-format", @@ -462,9 +417,6 @@ lvim.lang = { cmd = { "erlang_ls", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -479,11 +431,7 @@ lvim.lang = { linters = {}, lsp = { provider = "", - setup = { - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, + setup = {}, }, }, fortran = { @@ -495,9 +443,6 @@ lvim.lang = { cmd = { DATA_PATH .. "/lspinstall/fortran/venv/bin/fortls", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -523,9 +468,6 @@ lvim.lang = { cmd = { DATA_PATH .. "/lspinstall/go/gopls", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -541,9 +483,6 @@ lvim.lang = { "-m", "stream", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -554,9 +493,6 @@ lvim.lang = { provider = "hls", setup = { cmd = { DATA_PATH .. "/lspinstall/haskell/hls" }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -580,9 +516,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/html/vscode-html/html-language-features/server/dist/node/htmlServerMain.js", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -602,9 +535,6 @@ lvim.lang = { provider = "jdtls", setup = { cmd = { DATA_PATH .. "/lspinstall/java/jdtls.sh" }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -632,9 +562,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, settings = { json = { schemas = schemas, @@ -669,9 +596,6 @@ lvim.lang = { -- vim.fn.expand "~/.config/nvim/lua/lsp/julia/run.jl", CONFIG_PATH .. "/utils/julia/run.jl", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -684,8 +608,6 @@ lvim.lang = { cmd = { DATA_PATH .. "/lspinstall/kotlin/server/bin/kotlin-language-server", }, - on_attach = common_on_attach, - on_init = common_on_init, root_dir = function(fname) local util = require "lspconfig/util" @@ -725,9 +647,6 @@ lvim.lang = { "-E", DATA_PATH .. "/lspinstall/lua/main.lua", }, - capabilities = common_capabilities, - on_attach = common_on_attach, - on_init = common_on_init, settings = { Lua = { runtime = { @@ -811,8 +730,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/php/node_modules/.bin/intelephense", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, filetypes = { "php", "phtml" }, settings = { intelephense = { @@ -834,9 +751,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/puppet/puppet-editor-services/puppet-languageserver", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -865,9 +779,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -895,9 +806,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -920,9 +828,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -945,9 +850,6 @@ lvim.lang = { "-e", "languageserver::run()", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -966,9 +868,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph", "stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, filetypes = { "ruby" }, init_options = { formatting = true, @@ -999,9 +898,6 @@ lvim.lang = { cmd = { DATA_PATH .. "/lspinstall/rust/rust-analyzer", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1015,11 +911,7 @@ lvim.lang = { linters = { "" }, lsp = { provider = "metals", - setup = { - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, - }, + setup = {}, }, }, sh = { @@ -1037,9 +929,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", "start", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1053,9 +942,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/svelte/node_modules/.bin/svelteserver", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1074,9 +960,6 @@ lvim.lang = { "xcrun", "sourcekit-lsp", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1107,9 +990,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/terraform/terraform-ls", "serve", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1120,9 +1000,6 @@ lvim.lang = { provider = "texlab", setup = { cmd = { DATA_PATH .. "/lspinstall/latex/texlab" }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1150,9 +1027,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1181,9 +1055,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1197,9 +1068,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/vim/node_modules/.bin/vim-language-server", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1225,9 +1093,6 @@ lvim.lang = { cmd = { DATA_PATH .. "/lspinstall/vue/node_modules/.bin/vls", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1250,9 +1115,6 @@ lvim.lang = { DATA_PATH .. "/lspinstall/yaml/node_modules/.bin/yaml-language-server", "--stdio", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1265,9 +1127,6 @@ lvim.lang = { cmd = { "zls", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1282,9 +1141,6 @@ lvim.lang = { "localhost", "6008", }, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1295,9 +1151,6 @@ lvim.lang = { provider = "powershell_es", setup = { bundle_path = "", - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, @@ -1320,9 +1173,6 @@ lvim.lang = { local util = require "lspconfig/util" return util.root_pattern ".git"(fname) or vim.fn.getcwd() end, - on_attach = common_on_attach, - on_init = common_on_init, - capabilities = common_capabilities, }, }, }, diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 1a6ceda3..631f142a 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -138,6 +138,17 @@ function M.setup(lang) if lsp.provider ~= nil and lsp.provider ~= "" then local lspconfig = require "lspconfig" + + if not lsp.setup.on_attach then + lsp.setup.on_attach = M.common_on_attach + end + if not lsp.setup.on_init then + lsp.setup.on_init = M.common_on_init + end + if not lsp.setup.capabilities then + lsp.setup.capabilities = M.common_capabilities() + end + lspconfig[lsp.provider].setup(lsp.setup) end end From 7845b671ecb8634684f2d38158938bfe65fc5b31 Mon Sep 17 00:00:00 2001 From: Ahmed Khalf Date: Fri, 20 Aug 2021 23:22:35 +0400 Subject: [PATCH 38/64] Add show_hidden option to project module (#1359) --- lua/core/project.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/core/project.lua b/lua/core/project.lua index 650f2924..6d7aa56e 100644 --- a/lua/core/project.lua +++ b/lua/core/project.lua @@ -20,6 +20,9 @@ function M.config() -- detection_methods patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" }, + -- Show hidden files in telescope + show_hidden = false, + -- When set to false, you will get a message when project.nvim changes your -- directory. silent_chdir = true, From 33640834e4b07a8e9c5a6707ec0eadd863011ac0 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 20 Aug 2021 22:59:40 +0200 Subject: [PATCH 39/64] fix: set runtime directories correctly (#1354) * fix: set runtime directories correctly This also simplifies the way to invoke LunarVim to just be: `nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua"` Fixes #1352 * use libuv to get homedir path --- init.lua | 29 +++++++++++++++++------------ utils/bin/lvim | 4 +++- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/init.lua b/init.lua index 5844d79d..1d6cdc0f 100644 --- a/init.lua +++ b/init.lua @@ -1,16 +1,21 @@ -vim.cmd [[ - set packpath-=~/.config/nvim - set packpath-=~/.config/nvim/after - set packpath-=~/.local/share/nvim/site - set packpath^=~/.local/share/lunarvim/site - set packpath^=~/.config/lvim +-- {{{ Bootstrap +local home_dir = vim.loop.os_homedir() - set runtimepath-=~/.config/nvim - set runtimepath-=~/.config/nvim/after - set runtimepath+=~/.config/lvim - set runtimepath^=~/.local/share/lunarvim/lvim/after -]] --- vim.opt.rtp:append() instead of vim.cmd ? +vim.opt.rtp:append(home_dir .. "/.local/share/lunarvim/lvim") + +vim.opt.rtp:remove(home_dir .. "/.config/nvim") +vim.opt.rtp:remove(home_dir .. "/.config/nvim/after") +vim.opt.rtp:append(home_dir .. "/.config/lvim") +vim.opt.rtp:append(home_dir .. "/.config/lvim/after") + +vim.opt.rtp:remove(home_dir .. "/.local/share/nvim/site") +vim.opt.rtp:remove(home_dir .. "/.local/share/nvim/site/after") +vim.opt.rtp:append(home_dir .. "/.local/share/lunarvim/site") +vim.opt.rtp:append(home_dir .. "/.local/share/lunarvim/site/after") + +-- TODO: we need something like this: vim.opt.packpath = vim.opt.rtp +vim.cmd [[let &packpath = &runtimepath]] +-- }}} local function file_exists(name) local f = io.open(name, "r") diff --git a/utils/bin/lvim b/utils/bin/lvim index b94d544f..c55ddda7 100755 --- a/utils/bin/lvim +++ b/utils/bin/lvim @@ -1,3 +1,5 @@ #!/bin/sh -exec nvim -u ~/.local/share/lunarvim/lvim/init.lua --cmd "set runtimepath+=~/.local/share/lunarvim/lvim" "$@" +LUNARVIM_RUNTIME_DIR=${LUNARVIM_RUNTIME_DIR:-"$HOME/.local/share/lunarvim"} + +exec nvim -u "$LUNARVIM_RUNTIME_DIR"/lvim/init.lua "$@" From c5c9ae0fb68567c2a207c8c486b03bbafc650f98 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 22 Aug 2021 08:35:50 +0200 Subject: [PATCH 40/64] [fix]: don't overwrite user's dashboard config (#1366) --- lua/core/dashboard.lua | 5 ++++- lua/core/project.lua | 49 ++++++++++++++++++------------------------ 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index f98721cc..63ae7294 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -31,7 +31,10 @@ M.config = function() description = { " Find File " }, command = "Telescope find_files", }, - -- b is reserved for the core.project module + b = { + description = { " Recent Projects " }, + command = "Telescope projects", + }, c = { description = { " Recently Used Files" }, command = "Telescope oldfiles", diff --git a/lua/core/project.lua b/lua/core/project.lua index 6d7aa56e..7be65a11 100644 --- a/lua/core/project.lua +++ b/lua/core/project.lua @@ -2,50 +2,43 @@ local M = {} -- function M.config() lvim.builtin.project = { - --- This is on by default since it's currently the expected behavior. ---@usage set to false to disable project.nvim. + --- This is on by default since it's currently the expected behavior. active = true, - -- Manual mode doesn't automatically change your root directory, so you have - -- the option to manually do so using `:ProjectRoot` command. + ---@usage set to true to disable setting the current-woriking directory + --- Manual mode doesn't automatically change your root directory, so you have + --- the option to manually do so using `:ProjectRoot` command. manual_mode = false, - -- Methods of detecting the root directory. **"lsp"** uses the native neovim - -- lsp, while **"pattern"** uses vim-rooter like glob pattern matching. Here - -- order matters: if one is not detected, the other is used as fallback. You - -- can also delete or rearangne the detection methods. + ---@usage Methods of detecting the root directory + --- Allowed values: **"lsp"** uses the native neovim lsp + --- **"pattern"** uses vim-rooter like glob pattern matching. Here + --- order matters: if one is not detected, the other is used as fallback. You + --- can also delete or rearangne the detection methods. detection_methods = { "lsp", "pattern" }, - -- All the patterns used to detect root dir, when **"pattern"** is in - -- detection_methods + ---@usage patterns used to detect root dir, when **"pattern"** is in detection_methods patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" }, - -- Show hidden files in telescope + ---@ Show hidden files in telescope when searching for files in a project show_hidden = false, - -- When set to false, you will get a message when project.nvim changes your - -- directory. + ---@usage When set to false, you will get a message when project.nvim changes your directory. + -- When set to false, you will get a message when project.nvim changes your directory. silent_chdir = true, + + ---@usage list of lsp client names to ignore when using **lsp** detection. eg: { "efm", ... } + ignore_lsp = {}, + + ---@type string + ---@usage path to store the project history for use in telescope + datapath = CACHE_PATH, } end -- function M.setup() - local settings = lvim.builtin.project - - -- Table of lsp clients to ignore by name - -- eg: { "efm", ... } - settings["ignore_lsp"] = {} - - -- Path where project.nvim will store the project history for use in - -- telescope - settings["datapath"] = CACHE_PATH - - require("project_nvim").setup(settings) - - lvim.builtin.dashboard.custom_section["b"] = { - description = { " Recent Projects " }, - command = "Telescope projects", - } + require("project_nvim").setup(lvim.builtin.project) end -- return M From d85584d09f9028fa4202cea473f7f0ae3c531aef Mon Sep 17 00:00:00 2001 From: devtoi <508254+devtoi@users.noreply.github.com> Date: Sun, 22 Aug 2021 20:03:19 +0200 Subject: [PATCH 41/64] [Refactor/Bugfix] move on_config_done callbacks to relevant setup() (#1175) * Make autopairs config consistent with others * Fix two typos for autopairs * Remove extranous autopairs code. Return on setup * Remove extranous else for autopairs completion confirmation * Move on_config_done callbacks to setup functions. * Add on_config_done completion for builtins lacking a config function * enables galaxyline callbacks to work properly * Add modules for more builtins * Finish streamline of config function in plugin setup * Fix double use of which_key/wk * Fix erroneous remove of functionality in autopairs completion * consistency fixes * Work around telescope not found at config time * Match plugin definition of project and lualine with others * fix: restore config callback syntax Co-authored-by: Johan Melin Co-authored-by: rebuilt Co-authored-by: Luc Sinet Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com> --- lua/core/autopairs.lua | 17 ++++++++++------ lua/core/bufferline.lua | 5 +++++ lua/core/comment.lua | 8 +++++++- lua/core/compe.lua | 6 ++++++ lua/core/dap.lua | 6 ++++++ lua/core/dashboard.lua | 6 ++++++ lua/core/gitsigns.lua | 9 ++++++++- lua/core/lspinstall.lua | 19 ++++++++++++++++++ lua/core/nvimtree.lua | 13 ++++++++---- lua/core/project.lua | 15 ++++++++++---- lua/core/telescope.lua | 28 +++++++++++++++----------- lua/core/terminal.lua | 5 +++++ lua/core/treesitter.lua | 6 ++++++ lua/core/which-key.lua | 6 ++++++ lua/default-config.lua | 21 +++----------------- lua/plugins.lua | 44 +---------------------------------------- 16 files changed, 126 insertions(+), 88 deletions(-) create mode 100644 lua/core/lspinstall.lua diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index 470f8335..24aa1875 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -3,6 +3,7 @@ local M = {} function M.config() lvim.builtin.autopairs = { active = true, + on_config_done = nil, ---@usage map on insert mode map_cr = true, ---@usage auto insert after select function or method item @@ -21,19 +22,19 @@ end M.setup = function() -- skip it, if you use another global object _G.MUtils = {} - local npairs = require "nvim-autopairs" + local autopairs = require "nvim-autopairs" local Rule = require "nvim-autopairs.rule" vim.g.completion_confirm_key = "" MUtils.completion_confirm = function() if vim.fn.pumvisible() ~= 0 then if vim.fn.complete_info()["selected"] ~= -1 then - return vim.fn["compe#confirm"](npairs.esc "") + return vim.fn["compe#confirm"](autopairs.esc "") else - return npairs.esc "" + return autopairs.esc "" end else - return npairs.autopairs_cr() + return autopairs.autopairs_cr() end end @@ -44,7 +45,7 @@ M.setup = function() } end - npairs.setup { + autopairs.setup { check_ts = lvim.builtin.autopairs.check_ts, ts_config = lvim.builtin.autopairs.ts_config, } @@ -55,10 +56,14 @@ M.setup = function() -- TODO: can these rules be safely added from "config.lua" ? -- press % => %% is only inside comment or string - npairs.add_rules { + autopairs.add_rules { Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }), Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }), } + + if lvim.builtin.autopairs.on_config_done then + lvim.builtin.autopairs.on_config_done(autopairs) + end end return M diff --git a/lua/core/bufferline.lua b/lua/core/bufferline.lua index 8989ce21..e3f6b5de 100644 --- a/lua/core/bufferline.lua +++ b/lua/core/bufferline.lua @@ -3,6 +3,7 @@ local M = {} M.config = function() lvim.builtin.bufferline = { active = true, + on_config_done = nil, keymap = { normal_mode = { [""] = ":BufferNext", @@ -15,6 +16,10 @@ end M.setup = function() local keymap = require "keymappings" keymap.append_to_defaults(lvim.builtin.bufferline.keymap) + + if lvim.builtin.bufferline.on_config_done then + lvim.builtin.bufferline.on_config_done() + end end return M diff --git a/lua/core/comment.lua b/lua/core/comment.lua index 79d711b6..b98410ab 100644 --- a/lua/core/comment.lua +++ b/lua/core/comment.lua @@ -3,6 +3,7 @@ local M = {} function M.config() lvim.builtin.comment = { active = true, + on_config_done = nil, -- Linters prefer comment and line to have a space in between markers marker_padding = true, -- should comment out empty or whitespace only lines @@ -19,7 +20,12 @@ function M.config() end function M.setup() - require("nvim_comment").setup(lvim.builtin.comment) + local nvim_comment = require "nvim_comment" + + nvim_comment.setup(lvim.builtin.comment) + if lvim.builtin.comment.on_config_done then + lvim.builtin.comment.on_config_done(nvim_comment) + end end return M diff --git a/lua/core/compe.lua b/lua/core/compe.lua index 29344d97..9eb3dcfa 100644 --- a/lua/core/compe.lua +++ b/lua/core/compe.lua @@ -1,7 +1,9 @@ local M = {} + M.config = function() lvim.builtin.compe = { active = true, + on_config_done = nil, autocomplete = true, debug = false, min_length = 1, @@ -122,6 +124,10 @@ M.setup = function() vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", { expr = true }) vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", { expr = true }) vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", { expr = true }) + + if lvim.builtin.compe.on_config_done then + lvim.builtin.compe.on_config_done(compe) + end end return M diff --git a/lua/core/dap.lua b/lua/core/dap.lua index 259ff87e..5de3b7c4 100644 --- a/lua/core/dap.lua +++ b/lua/core/dap.lua @@ -1,7 +1,9 @@ local M = {} + M.config = function() lvim.builtin.dap = { active = false, + on_config_done = nil, breakpoint = { text = "", texthl = "LspDiagnosticsSignError", @@ -33,6 +35,10 @@ M.setup = function() s = { "lua require'dap'.continue()", "Start" }, q = { "lua require'dap'.close()", "Quit" }, } + + if lvim.builtin.dap.on_config_done then + lvim.builtin.dap.on_config_done(dap) + end end -- TODO put this up there ^^^ call in ftplugin diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index 63ae7294..c76d55c9 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -1,7 +1,9 @@ local M = {} + M.config = function() lvim.builtin.dashboard = { active = false, + on_config_done = nil, search_handler = "telescope", disable_at_vim_enter = 0, session_directory = os.getenv "HOME" .. "/.cache/lvim/sessions", @@ -91,6 +93,10 @@ M.setup = function() { "FileType", "dashboard", "nnoremap q :q" }, }, } + + if lvim.builtin.dashboard.on_config_done then + lvim.builtin.dashboard.on_config_done() + end end return M diff --git a/lua/core/gitsigns.lua b/lua/core/gitsigns.lua index 80a31500..bb9d088b 100644 --- a/lua/core/gitsigns.lua +++ b/lua/core/gitsigns.lua @@ -1,7 +1,9 @@ local M = {} + M.config = function() lvim.builtin.gitsigns = { active = true, + on_config_done = nil, opts = { signs = { add = { @@ -51,7 +53,12 @@ M.config = function() end M.setup = function() - require("gitsigns").setup(lvim.builtin.gitsigns.opts) + local gitsigns = require "gitsigns" + + gitsigns.setup(lvim.builtin.gitsigns.opts) + if lvim.builtin.gitsigns.on_config_done then + lvim.builtin.gitsigns.on_config_done(gitsigns) + end end return M diff --git a/lua/core/lspinstall.lua b/lua/core/lspinstall.lua new file mode 100644 index 00000000..0bb59e0e --- /dev/null +++ b/lua/core/lspinstall.lua @@ -0,0 +1,19 @@ +local M = {} + +M.config = function() + lvim.builtin.lspinstall = { + active = true, + on_config_done = nil, + } +end + +M.setup = function() + local lspinstall = require "lspinstall" + lspinstall.setup() + + if lvim.builtin.lspinstall.on_config_done then + lvim.builtin.lspinstall.on_config_done(lspinstall) + end +end + +return M diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index ff52029d..bea1add4 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -1,9 +1,10 @@ local M = {} local Log = require "core.log" -M.config = function() +function M.config() lvim.builtin.nvimtree = { active = true, + on_config_done = nil, side = "left", width = 30, show_icons = { @@ -48,7 +49,7 @@ M.config = function() } end -M.setup = function() +function M.setup() local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") if not status_ok then Log:get_default().error "Failed to load nvim-tree.config" @@ -88,15 +89,19 @@ M.setup = function() end vim.cmd "au WinClosed * lua require('core.nvimtree').on_close()" + + if lvim.builtin.nvimtree.on_config_done then + lvim.builtin.nvimtree.on_config_done(nvim_tree_config) + end end -M.on_open = function() +function M.on_open() if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "") end end -M.on_close = function() +function M.on_close() local buf = tonumber(vim.fn.expand "") local ft = vim.api.nvim_buf_get_option(buf, "filetype") if ft == "NvimTree" and package.loaded["bufferline.state"] then diff --git a/lua/core/project.lua b/lua/core/project.lua index 7be65a11..7fb04933 100644 --- a/lua/core/project.lua +++ b/lua/core/project.lua @@ -1,11 +1,13 @@ local M = {} --- + function M.config() lvim.builtin.project = { ---@usage set to false to disable project.nvim. --- This is on by default since it's currently the expected behavior. active = true, + on_config_done = nil, + ---@usage set to true to disable setting the current-woriking directory --- Manual mode doesn't automatically change your root directory, so you have --- the option to manually do so using `:ProjectRoot` command. @@ -36,9 +38,14 @@ function M.config() datapath = CACHE_PATH, } end --- + function M.setup() - require("project_nvim").setup(lvim.builtin.project) + local project = require "project_nvim" + + project.setup(lvim.builtin.project) + if lvim.builtin.project.on_config_done then + lvim.builtin.project.on_config_done(project) + end end --- + return M diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index 5d9263d7..4ae56df0 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -1,13 +1,19 @@ local M = {} + function M.config() + -- Define this minimal config so that it's available if telescope is not yet available. + lvim.builtin.telescope = { + ---@usage disable telescope completely [not recommeded] + active = true, + on_config_done = nil, + } + local status_ok, actions = pcall(require, "telescope.actions") if not status_ok then return end - lvim.builtin.telescope = { - ---@usage disable telescope completely [not recommeded] - active = true, + lvim.builtin.telescope = vim.tbl_extend("force", lvim.builtin.telescope, { defaults = { prompt_prefix = " ", selection_caret = " ", @@ -74,7 +80,7 @@ function M.config() override_file_sorter = true, }, }, - } + }) end function M.find_lunarvim_files(opts) @@ -112,15 +118,15 @@ function M.grep_lunarvim_files(opts) end function M.setup() - local status_ok, telescope = pcall(require, "telescope") - if not status_ok then - local Log = require "core.log" - Log:get_default().error "Failed to load telescope" - return - end + local telescope = require "telescope" + telescope.setup(lvim.builtin.telescope) if lvim.builtin.project.active then - pcall(require("telescope").load_extension, "projects") + telescope.load_extension "projects" + end + + if lvim.builtin.telescope.on_config_done then + lvim.builtin.telescope.on_config_done(telescope) end end diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index 661e5b3b..4fced26e 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -3,6 +3,7 @@ local utils = require "utils" M.config = function() lvim.builtin["terminal"] = { + on_config_done = nil, -- size can be a number or function which is passed the current terminal size = 20, -- open_mapping = [[]], @@ -50,6 +51,10 @@ M.setup = function() require("core.terminal").add_exec(exec[1], exec[2], exec[3]) end terminal.setup(lvim.builtin.terminal) + + if lvim.builtin.terminal.on_config_done then + lvim.builtin.terminal.on_config_done(terminal) + end end M.add_exec = function(exec, keymap, name) diff --git a/lua/core/treesitter.lua b/lua/core/treesitter.lua index 0a8a2ff2..d63024e6 100644 --- a/lua/core/treesitter.lua +++ b/lua/core/treesitter.lua @@ -1,7 +1,9 @@ local M = {} local Log = require "core.log" + M.config = function() lvim.builtin.treesitter = { + on_config_done = nil, ensure_installed = {}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages ignore_install = {}, matchup = { @@ -70,6 +72,10 @@ M.setup = function() end treesitter_configs.setup(lvim.builtin.treesitter) + + if lvim.builtin.treesitter.on_config_done then + lvim.builtin.treesitter.on_config_done(treesitter_configs) + end end return M diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 5b249430..71c0b695 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -1,8 +1,10 @@ local M = {} + M.config = function() lvim.builtin.which_key = { ---@usage disable which-key completely [not recommeded] active = true, + on_config_done = nil, setup = { plugins = { marks = true, -- shows a list of your marks on ' and ` @@ -241,6 +243,10 @@ M.setup = function() which_key.register(mappings, opts) which_key.register(vmappings, vopts) + + if lvim.builtin.which_key.on_config_done then + lvim.builtin.which_key.on_config_done(which_key) + end end return M diff --git a/lua/default-config.lua b/lua/default-config.lua index e88fee8d..9d84efaa 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -15,24 +15,7 @@ lvim = { database = { save_location = "~/.config/lunarvim_db", auto_execute = 1 }, keys = {}, - -- TODO why do we need this? - builtin = { - lspinstall = {}, - telescope = {}, - compe = {}, - autopairs = {}, - treesitter = {}, - nvimtree = {}, - gitsigns = {}, - which_key = {}, - comment = {}, - project = {}, - lualine = {}, - bufferline = {}, - dap = {}, - dashboard = {}, - terminal = {}, - }, + builtin = {}, log = { ---@usage can be { "trace", "debug", "info", "warn", "error", "fatal" }, @@ -1178,6 +1161,7 @@ lvim.lang = { }, } +-- NOTE: which-key should be first because it defines lvim.builtin.which_key.mappings require("keymappings").config() require("core.which-key").config() require("core.gitsigns").config() @@ -1192,4 +1176,5 @@ require("core.project").config() require("core.bufferline").config() require("core.autopairs").config() require("core.comment").config() +require("core.lspinstall").config() require("core.lualine").config() diff --git a/lua/plugins.lua b/lua/plugins.lua index 9aaea922..5aaac3ce 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -8,11 +8,8 @@ return { "kabouzeid/nvim-lspinstall", event = "VimEnter", config = function() - local lspinstall = require "lspinstall" + local lspinstall = require "core.lspinstall" lspinstall.setup() - if lvim.builtin.lspinstall.on_config_done then - lvim.builtin.lspinstall.on_config_done(lspinstall) - end end, }, @@ -23,9 +20,6 @@ return { "nvim-telescope/telescope.nvim", config = function() require("core.telescope").setup() - if lvim.builtin.telescope.on_config_done then - lvim.builtin.telescope.on_config_done(require "telescope") - end end, disable = not lvim.builtin.telescope.active, }, @@ -36,9 +30,6 @@ return { event = "InsertEnter", config = function() require("core.compe").setup() - if lvim.builtin.compe.on_config_done then - lvim.builtin.compe.on_config_done(require "compe") - end end, disable = not lvim.builtin.compe.active, -- wants = "vim-vsnip", @@ -73,9 +64,6 @@ return { after = "nvim-compe", config = function() require("core.autopairs").setup() - if lvim.builtin.autopairs.on_config_done then - lvim.builtin.autopairs.on_config_done(require "nvim-autopairs") - end end, disable = not lvim.builtin.autopairs.active or not lvim.builtin.compe.active, }, @@ -87,9 +75,6 @@ return { -- run = ":TSUpdate", config = function() require("core.treesitter").setup() - if lvim.builtin.treesitter.on_config_done then - lvim.builtin.treesitter.on_config_done(require "nvim-treesitter.configs") - end end, }, @@ -101,9 +86,6 @@ return { -- commit = "fd7f60e242205ea9efc9649101c81a07d5f458bb", config = function() require("core.nvimtree").setup() - if lvim.builtin.nvimtree.on_config_done then - lvim.builtin.nvimtree.on_config_done(require "nvim-tree.config") - end end, disable = not lvim.builtin.nvimtree.active, }, @@ -113,9 +95,6 @@ return { config = function() require("core.gitsigns").setup() - if lvim.builtin.gitsigns.on_config_done then - lvim.builtin.gitsigns.on_config_done(require "gitsigns") - end end, event = "BufRead", disable = not lvim.builtin.gitsigns.active, @@ -126,9 +105,6 @@ return { "folke/which-key.nvim", config = function() require("core.which-key").setup() - if lvim.builtin.which_key.on_config_done then - lvim.builtin.which_key.on_config_done(require "which-key") - end end, event = "BufWinEnter", disable = not lvim.builtin.which_key.active, @@ -140,9 +116,6 @@ return { event = "BufRead", config = function() require("nvim_comment").setup() - if lvim.builtin.comment.on_config_done then - lvim.builtin.comment.on_config_done(require "nvim_comment") - end end, disable = not lvim.builtin.comment.active, }, @@ -152,9 +125,6 @@ return { "ahmedkhalf/project.nvim", config = function() require("core.project").setup() - if lvim.builtin.project.on_config_done then - lvim.builtin.project.on_config_done() - end end, disable = not lvim.builtin.project.active, }, @@ -177,9 +147,6 @@ return { "romgrk/barbar.nvim", config = function() require("core.bufferline").setup() - if lvim.builtin.bufferline.on_config_done then - lvim.builtin.bufferline.on_config_done() - end end, event = "BufWinEnter", disable = not lvim.builtin.bufferline.active, @@ -191,9 +158,6 @@ return { -- event = "BufWinEnter", config = function() require("core.dap").setup() - if lvim.builtin.dap.on_config_done then - lvim.builtin.dap.on_config_done(require "dap") - end end, disable = not lvim.builtin.dap.active, }, @@ -212,9 +176,6 @@ return { event = "BufWinEnter", config = function() require("core.dashboard").setup() - if lvim.builtin.dashboard.on_config_done then - lvim.builtin.dashboard.on_config_done(require "dashboard") - end end, disable = not lvim.builtin.dashboard.active, }, @@ -225,9 +186,6 @@ return { event = "BufWinEnter", config = function() require("core.terminal").setup() - if lvim.builtin.terminal.on_config_done then - lvim.builtin.terminal.on_config_done(require "toggleterm") - end end, disable = not lvim.builtin.terminal.active, }, From 86796a0a97e0734be20614dd2586351fe83d4642 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 23 Aug 2021 08:20:36 +0430 Subject: [PATCH 42/64] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index edadcd37..c140c35d 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ lvim.keys.normal_mode[""] = ":w" -- lvim.keys.insert_mode["po"] = {'', { noremap = true }} -- Use which-key to add extra bindings with the leader-key prefix --- lvim.builtin.which_key.mappings["P"] = { "lua require'telescope'.extensions.project.project{}", "Projects" } +-- lvim.builtin.which_key.mappings["P"] = { "Telescope projects", "Projects" } -- lvim.builtin.which_key.mappings["t"] = { -- name = "+Trouble", -- r = { "Trouble lsp_references", "References" }, From 10091859a29e16f38b6eaca64db59308ddf24138 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 23 Aug 2021 08:21:17 +0430 Subject: [PATCH 43/64] Update config.example.lua --- utils/installer/config.example.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/installer/config.example.lua b/utils/installer/config.example.lua index 2f8984bb..c2c75fbb 100644 --- a/utils/installer/config.example.lua +++ b/utils/installer/config.example.lua @@ -37,7 +37,7 @@ lvim.keys.normal_mode[""] = ":w" -- end -- Use which-key to add extra bindings with the leader-key prefix --- lvim.builtin.which_key.mappings["P"] = { "lua require'telescope'.extensions.project.project{}", "Projects" } +-- lvim.builtin.which_key.mappings["P"] = { "Telescope projects", "Projects" } -- lvim.builtin.which_key.mappings["t"] = { -- name = "+Trouble", -- r = { "Trouble lsp_references", "References" }, From cc166d05039ac0dda71c4d17f2378f9c5bf2b4eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Vl=C4=8Dinsk=C3=BD?= Date: Mon, 23 Aug 2021 11:36:12 +0200 Subject: [PATCH 44/64] fix telescope.project call in sample config (without ts) (#1380) --- utils/installer/config.example-no-ts.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/installer/config.example-no-ts.lua b/utils/installer/config.example-no-ts.lua index e5c24274..aad13fe0 100644 --- a/utils/installer/config.example-no-ts.lua +++ b/utils/installer/config.example-no-ts.lua @@ -28,7 +28,7 @@ lvim.keys.normal_mode[""] = ":w" -- end -- Use which-key to add extra bindings with the leader-key prefix --- lvim.builtin.which_key.mappings["P"] = { "lua require'telescope'.extensions.project.project{}", "Projects" } +-- lvim.builtin.which_key.mappings["P"] = { "Telescope projects", "Projects" } -- lvim.builtin.which_key.mappings["t"] = { -- name = "+Trouble", -- r = { "Trouble lsp_references", "References" }, From 101c6834333ffb06856155054ea77747819ef5fc Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 23 Aug 2021 17:18:42 +0200 Subject: [PATCH 45/64] [Refactor] Installer v2 with support for backup (#1052) --- .github/workflows/install.yaml | 17 +- README.md | 16 +- utils/bin/lvim | 5 +- utils/installer/install.sh | 492 +++++++++++++++++---------------- 4 files changed, 279 insertions(+), 251 deletions(-) mode change 100755 => 100644 utils/bin/lvim diff --git a/.github/workflows/install.yaml b/.github/workflows/install.yaml index 6fb0d49c..f7d9da01 100644 --- a/.github/workflows/install.yaml +++ b/.github/workflows/install.yaml @@ -1,11 +1,11 @@ name: install on: push: - branches: '**' + branches: "**" pull_request: branches: - - 'master' - - 'rolling' + - "master" + - "rolling" jobs: unixish: @@ -38,14 +38,15 @@ jobs: - name: Install LunarVim timeout-minutes: 4 run: | - bash ./utils/installer/install.sh --testing + mkdir -p "$HOME/.local/share/lunarvim" + mkdir -p "$HOME/.config/lvim" + bash ./utils/installer/install.sh - name: Test LunarVim PackerCompile - run: if lvim --headless +PackerCompile -c ':qall' 2>&1|grep -q 'Error'; then false; fi + run: if "$HOME"/.local/bin/lvim --headless +PackerCompile -c ':qall' 2>&1|grep -q 'Error'; then false; fi - name: Test LunarVim Health - run: if lvim --headless +checkhealth -c ':qall' 2>&1|grep -q 'Error'; then false; fi - + run: if "$HOME"/.local/bin/lvim --headless +checkhealth -c ':qall' 2>&1|grep -q 'Error'; then false; fi # freebsd: # runs-on: macos-latest # if: github.event.pull_request.draft == false @@ -53,7 +54,7 @@ jobs: # name: "FreeBSD macos-latest" # steps: # - uses: actions/checkout@v2 - + # - name: Install dependencies for FreeBSD # uses: vmactions/freebsd-vm@v0.1.5 # with: diff --git a/README.md b/README.md index c140c35d..7f2f742d 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,20 @@ Make sure you have the newest version of Neovim (0.5). bash <(curl -s https://raw.githubusercontent.com/lunarvim/lunarvim/master/utils/installer/install.sh) ``` -### Installing -The following command installs LunarVim. Change `LVBRANCH` to the branch you'd like to install. `master` for the stable branch and `rolling` for the latest changes. +### Customizing the installation + +The following options are supported by setting environment variables: +- `"$LV_REMOTE"` Select a different LunarVim remote [default: 'lunarvim/lunarvim.git'] +- `"$LV_BRANCH"` Select LunarVim's branch [default: 'rolling'] +- `"$INSTALL_PREFIX"` Select LunarVim's install prefix [default: `'$HOME/.local'`] +- `"$LUNARVIM_RUNTIME_DIR"` Select LunarVim's runtime directory [default: `'$HOME/.local/share/lunarvim'`] +- `"$LUNARVIM_CONFIG_DIR"` Select LunarVim's configuration directory [default: `'$HOME/.config/lvim'`] + +Putting it all together + ``` bash -LVBRANCH=rolling bash <(curl -s https://raw.githubusercontent.com/lunarvim/lunarvim/rolling/utils/installer/install.sh) +curl -LSs https://raw.githubusercontent.com/lunarvim/lunarvim/rolling/utils/installer/install.sh -O install.sh +INSTALL_PREFIX=/tmp/t1 LUNARVIM_CONFIG_DIR=/tmp/t2 LUNARVIM_RUNTIME_DIR=/tmp/t3 bash ./install.sh ``` ### BREAKING CHANGE on rolling and master branches diff --git a/utils/bin/lvim b/utils/bin/lvim old mode 100755 new mode 100644 index c55ddda7..2303be3c --- a/utils/bin/lvim +++ b/utils/bin/lvim @@ -1,5 +1,6 @@ #!/bin/sh -LUNARVIM_RUNTIME_DIR=${LUNARVIM_RUNTIME_DIR:-"$HOME/.local/share/lunarvim"} +export LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-$HOME/.local/share/lunarvim}" +export LUNARVIM_CONFIG_DIR="${LUNARVIM_RUNTIME_DIR:-$HOME/.config/lvim}" -exec nvim -u "$LUNARVIM_RUNTIME_DIR"/lvim/init.lua "$@" +exec nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" "$@" diff --git a/utils/installer/install.sh b/utils/installer/install.sh index 98040344..989f5595 100755 --- a/utils/installer/install.sh +++ b/utils/installer/install.sh @@ -1,272 +1,288 @@ -#!/bin/sh -#Set Variable to master is not set differently -LVBRANCH="${LVBRANCH:-master}" -USER_BIN_DIR="/usr/local/bin" -set -o nounset # error when referencing undefined variable -set -o errexit # exit when command fails +#!/usr/bin/env bash +set -eo pipefail -installnodemac() { - brew install lua - brew install node - brew install yarn -} +#Set branch to master unless specified by the user +declare -r LV_BRANCH="${LV_BRANCH:-rolling}" +declare -r LV_REMOTE="${LV_REMOTE:-lunarvim/lunarvim.git}" +declare -r INSTALL_PREFIX="${INSTALL_PREFIX:-"$HOME/.local"}" -installnodeubuntu() { - sudo apt install nodejs - sudo apt install npm -} +declare -r XDG_DATA_HOME="${XDG_DATA_HOME:-"$HOME/.local/share"}" +declare -r XDG_CACHE_HOME="${XDG_CACHE_HOME:-"$HOME/.cache"}" +declare -r XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"$HOME/.config"}" -installnodetermux() { - apt install nodejs -} +# TODO: Use a dedicated cache directory #1256 +declare -r NEOVIM_CACHE_DIR="$XDG_CACHE_HOME/nvim" -moveoldlvim() { - echo "Not installing LunarVim" - echo "Please move your ~/.local/share/lunarvim folder before installing" - exit -} +declare -r LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"$XDG_DATA_HOME/lunarvim"}" +declare -r LUNARVIM_CONFIG_DIR="${LUNARVIM_CONFIG_DIR:-"$XDG_CONFIG_HOME/lvim"}" -installnodearch() { - sudo pacman -S nodejs - sudo pacman -S npm -} +declare -a __lvim_dirs=( + "$LUNARVIM_CONFIG_DIR" + "$LUNARVIM_RUNTIME_DIR" + "$NEOVIM_CACHE_DIR" # for now this is shared with neovim +) -installnodefedora() { - sudo dnf install -y nodejs - sudo dnf install -y npm -} +declare -a __npm_deps=( + "neovim" + "tree-sitter-cli" +) -installnodegentoo() { - echo "Printing current node status..." - emerge -pqv net-libs/nodejs - echo "Make sure the npm USE flag is enabled for net-libs/nodejs" - echo "If it isn't enabled, would you like to enable it with flaggie? (Y/N)" - read -r answer - [ "$answer" != "${answer#[Yy]}" ] && sudo flaggie net-libs/nodejs +npm - sudo emerge -avnN net-libs/nodejs -} +declare -a __pip_deps=( + "pynvim" +) -installnode() { - echo "Installing node..." - [ "$(uname)" = "Darwin" ] && installnodemac - grep -q Ubuntu /etc/os-release && installnodeubuntu - [ -f "/etc/arch-release" ] && installnodearch - [ -f "/etc/artix-release" ] && installnodearch - [ -f "/etc/fedora-release" ] && installnodefedora - [ -f "/etc/gentoo-release" ] && installnodegentoo - [ -d "/data/data/com.termux" ] && installnodetermux - [ "$(uname -s | cut -c 1-10)" = "MINGW64_NT" ] && echo "Windows not currently supported" - sudo npm i -g neovim -} +function main() { + cat <<'EOF' -installpiponmac() { - sudo curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py - python3 get-pip.py - rm get-pip.py -} + 88\ 88\ + 88 | \__| + 88 |88\ 88\ 888888$\ 888888\ 888888\ 88\ 88\ 88\ 888888\8888\ + 88 |88 | 88 |88 __88\ \____88\ 88 __88\\88\ 88 |88 |88 _88 _88\ + 88 |88 | 88 |88 | 88 | 888888$ |88 | \__|\88\88 / 88 |88 / 88 / 88 | + 88 |88 | 88 |88 | 88 |88 __88 |88 | \88$ / 88 |88 | 88 | 88 | + 88 |\888888 |88 | 88 |\888888$ |88 | \$ / 88 |88 | 88 | 88 | + \__| \______/ \__| \__| \_______|\__| \_/ \__|\__| \__| \__| -installpiponubuntu() { - sudo apt install python3-pip >/dev/null -} +EOF -installpipontermux() { - apt install python -} + __add_separator "80" -installpiponarch() { - sudo pacman -S python-pip -} + echo "Detecting platform for managing any additional neovim dependencies" + detect_platform -installpiponfedora() { - sudo dnf install -y pip >/dev/null -} + # skip this in a Github workflow + if [ -z "$GITHUB_ACTIONS" ]; then + check_system_deps -installpipongentoo() { - sudo emerge -avn dev-python/pip -} + __add_separator "80" -installpip() { - echo "Installing pip..." - [ "$(uname)" = "Darwin" ] && installpiponmac - grep -q Ubuntu /etc/os-release && installpiponubuntu - [ -f "/etc/arch-release" ] && installpiponarch - [ -f "/etc/fedora-release" ] && installpiponfedora - [ -f "/etc/gentoo-release" ] && installpipongentoo - [ -d "/data/data/com.termux" ] && installpipontermux - [ "$(uname -s | cut -c 1-10)" = "MINGW64_NT" ] && echo "Windows not currently supported" -} + echo "Would you like to check lunarvim's NodeJS dependencies?" + read -p "[y]es or [n]o (default: no) : " -r answer + [ "$answer" != "${answer#[Yy]}" ] && install_nodejs_deps + + echo "Would you like to check lunarvim's Python dependencies?" + read -p "[y]es or [n]o (default: no) : " -r answer + [ "$answer" != "${answer#[Yy]}" ] && install_python_deps + + echo "Would you like to check lunarvim's Rust dependencies?" + read -p "[y]es or [n]o (default: no) : " -r answer + [ "$answer" != "${answer#[Yy]}" ] && install_rust_deps + + __add_separator "80" + + echo "Backing up old LunarVim configuration" + backup_old_config + + __add_separator "80" -installpynvim() { - echo "Installing pynvim..." - if [ -f "/etc/gentoo-release" ]; then - echo "Installing using Portage" - sudo emerge -avn dev-python/pynvim - else - pip3 install pynvim --user fi -} -installpacker() { - git clone https://github.com/wbthomason/packer.nvim ~/.local/share/lunarvim/site/pack/packer/start/packer.nvim -} - -cloneconfig() { - if [ -d "/data/data/com.termux" ]; then - sudo() { - eval "$@" - } - USER_BIN_DIR="$HOME/../usr/bin" - fi - echo "Cloning LunarVim configuration" - mkdir -p ~/.local/share/lunarvim case "$@" in - - *--testing*) - cp -r "$(pwd)" ~/.local/share/lunarvim/lvim - ;; - *) - git clone --branch "$LVBRANCH" https://github.com/lunarvim/lunarvim.git ~/.local/share/lunarvim/lvim + *--overwrite*) + echo "!!Warning!! -> Removing all lunarvim related config \ + because of the --overwrite flag" + read -p "Would you like to continue? [y]es or [n]o : " -r answer + [ "$answer" == "${answer#[Yy]}" ] && exit 1 + for dir in "${__lvim_dirs[@]}"; do + [ -d "$dir" ] && rm -rf "$dir" + done ;; esac - mkdir -p "$HOME/.config/lvim" - sudo cp "$HOME/.local/share/lunarvim/lvim/utils/bin/lvim" "$USER_BIN_DIR" - sudo chmod a+rx "$USER_BIN_DIR"/lvim - cp "$HOME/.local/share/lunarvim/lvim/utils/installer/config.example-no-ts.lua" "$HOME/.config/lvim/config.lua" - nvim -u ~/.local/share/lunarvim/lvim/init.lua --cmd "set runtimepath+=~/.local/share/lunarvim/lvim" --headless \ + if [ -e "$LUNARVIM_RUNTIME_DIR/site/pack/packer/start/packer.nvim" ]; then + echo "Packer already installed" + else + install_packer + fi + + __add_separator "80" + + if [ -e "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" ]; then + echo "Updating LunarVim" + update_lvim + else + clone_lvim + setup_lvim + fi + + __add_separator "80" + +} + +function detect_platform() { + OS="$(uname -s)" + case "$OS" in + Linux) + if [ -f "/etc/arch-release" ] || [ -f "/etc/artix-release" ]; then + RECOMMEND_INSTALL="sudo pacman -S" + elif [ -f "/etc/fedora-release" ] || [ -f "/etc/redhat-release" ]; then + RECOMMEND_INSTALL="sudo dnf install -y" + elif [ -f "/etc/gentoo-release" ]; then + RECOMMEND_INSTALL="emerge install -y" + else # assume debian based + RECOMMEND_INSTALL="sudo apt install -y" + fi + ;; + Darwin) + RECOMMEND_INSTALL="brew install" + ;; + *) + echo "OS $OS is not currently supported." + exit 1 + ;; + esac +} + +function print_missing_dep_msg() { + echo "[ERROR]: Unable to find dependency [$1]" + echo "Please install it first and re-run the installer. Try: $RECOMMEND_INSTALL $1" +} + +function check_dep() { + if ! command -v "$1" &>/dev/null; then + print_missing_dep_msg "$1" + exit 1 + fi +} + +function check_system_deps() { + if ! command -v git &>/dev/null; then + print_missing_dep_msg "git" + exit 1 + fi + if ! command -v nvim &>/dev/null; then + print_missing_dep_msg "neovim" + exit 1 + fi +} + +function install_nodejs_deps() { + check_dep "npm" + echo "Installing node modules with npm.." + for dep in "${__npm_deps[@]}"; do + if ! npm ls -g "$dep" &>/dev/null; then + printf "installing %s .." "$dep" + npm install -g "$dep" + fi + done + echo "All NodeJS dependencies are succesfully installed" +} + +function install_python_deps() { + echo "Verifying that pip is available.." + if ! python3 -m ensurepip &>/dev/null; then + print_missing_dep_msg "pip" + exit 1 + fi + echo "Installing with pip.." + for dep in "${__pip_deps[@]}"; do + pip3 install --user "$dep" + done + echo "All Python dependencies are succesfully installed" +} + +function __attempt_to_install_with_cargo() { + if ! command -v cargo &>/dev/null; then + echo "Installing missing Rust dependency with cargo" + cargo install "$1" + else + echo "[WARN]: Unable to find fd. Make sure to install it to avoid any problems" + fi +} + +# we try to install the missing one with cargo even though it's unlikely to be found +function install_rust_deps() { + if ! command -v fd &>/dev/null; then + __attempt_to_install_with_cargo "fd-find" + fi + if ! command -v rg &>/dev/null; then + __attempt_to_install_with_cargo "ripgrep" + fi + echo "All Rust dependencies are succesfully installed" +} + +function backup_old_config() { + for dir in "${__lvim_dirs[@]}"; do + # we create an empty folder for subsequent commands \ + # that require an existing directory + mkdir -p "$dir" "$dir.bak" + if command -v rsync &>/dev/null; then + rsync --archive -hh --partial --info=stats1 --info=progress2 \ + --modify-window=1 "$dir" "$dir.bak" + else + cp -R "$dir/*" "$dir.bak/." + fi + done + echo "Backup operation complete" +} + +function install_packer() { + git clone --progress --depth 1 https://github.com/wbthomason/packer.nvim \ + "$LUNARVIM_RUNTIME_DIR/site/pack/packer/start/packer.nvim" +} + +function clone_lvim() { + echo "Cloning LunarVim configuration" + if ! git clone --progress --branch "$LV_BRANCH" \ + --depth 1 "https://github.com/${LV_REMOTE}" "$LUNARVIM_RUNTIME_DIR/lvim"; then + echo "Failed to clone repository. Installation failed." + exit 1 + fi +} + +function setup_shim() { + if [ ! -d "$INSTALL_PREFIX/bin" ]; then + mkdir -p "$INSTALL_PREFIX/bin" + fi + cat >"$INSTALL_PREFIX/bin/lvim" </dev/null; then + git -C "$LUNARVIM_RUNTIME_DIR/lvim" pull --ff-only --progress || + echo "Unable to guarantee data integrity while updating. Please do that manually instead." && exit 1 fi - + echo "Your LunarVim installation is now up to date!" } -asktoinstallnode() { - echo "node not found" - printf "Would you like to install node now (y/n)? " - read -r answer - [ "$answer" != "${answer#[Yy]}" ] && installnode +function __add_separator() { + local DIV_WIDTH="$1" + printf "%${DIV_WIDTH}s\n" ' ' | tr ' ' - } -asktoinstallgit() { - echo "git not found, please install git" - exit -} - -asktoinstallpip() { - # echo "pip not found" - # echo -n "Would you like to install pip now (y/n)? " - # read answer - # [ "$answer" != "${answer#[Yy]}" ] && installpip - echo "Please install pip3 before continuing with install" - exit -} - -installonmac() { - brew install ripgrep fzf - npm install -g tree-sitter-cli -} - -installonubuntu() { - sudo apt install ripgrep fzf - sudo apt install libjpeg8-dev zlib1g-dev python-dev python3-dev libxtst-dev - pip3 install neovim-remote - npm install -g tree-sitter-cli -} - -installtermux() { - apt install ripgrep fzf - pip install neovim-remote - npm install -g tree-sitter-cli -} - -installonarch() { - sudo pacman -S ripgrep fzf - pip3 install neovim-remote - npm install -g tree-sitter-cli -} - -installonfedora() { - sudo dnf groupinstall "X Software Development" - sudo dnf install -y fzf ripgrep -} - -installongentoo() { - sudo emerge -avn sys-apps/ripgrep app-shells/fzf dev-python/neovim-remote virtual/jpeg sys-libs/zlib - npm install -g tree-sitter-cli -} - -installextrapackages() { - [ "$(uname)" = "Darwin" ] && installonmac - grep -q Ubuntu /etc/os-release && installonubuntu - [ -f "/etc/arch-release" ] && installonarch - [ -f "/etc/artix-release" ] && installonarch - [ -f "/etc/fedora-release" ] && installonfedora - [ -f "/etc/gentoo-release" ] && installongentoo - [ -d "/data/data/com.termux" ] && installtermux - [ "$(uname -s | cut -c 1-10)" = "MINGW64_NT" ] && echo "Windows not currently supported" -} - -# Welcome -echo 'Installing LunarVim' - -case "$@" in - *--overwrite*) - echo '!!Warning!! -> Removing all lunarvim related config because of the --overwrite flag' - rm -rf "$HOME/.local/share/lunarvim" - rm -rf "$HOME/.cache/nvim" - rm -rf "$HOME/.config/lvim" - ;; -esac - -# move old lvim directory if it exists -[ -d "$HOME/.local/share/lunarvim" ] && moveoldlvim - -# install node and neovim support -(command -v git >/dev/null && echo "git installed, moving on...") || asktoinstallgit - -# install pip -(command -v pip3 >/dev/null && echo "pip installed, moving on...") || asktoinstallpip - -# install node and neovim support -(command -v node >/dev/null && echo "node installed, moving on...") || asktoinstallnode - -# install pynvim -(pip3 list | grep pynvim >/dev/null && echo "pynvim installed, moving on...") || installpynvim - -if [ -e "$HOME/.local/share/lunarvim/site/pack/packer/start/packer.nvim" ]; then - echo 'packer already installed' -else - installpacker -fi - -if [ -e "$HOME/.local/share/lunarvim/lvim/init.lua" ]; then - echo 'LunarVim already installed' -else - # clone config down - cloneconfig "$@" - # echo 'export PATH=$HOME/.config/nvim/utils/bin:$PATH' >>~/.zshrc - # echo 'export PATH=$HOME/.config/lunarvim/utils/bin:$PATH' >>~/.bashrc -fi - -if [ "$(uname)" != "Darwin" ]; then - if [ -e "$HOME/.local/share/applications/lvim.desktop" ]; then - echo 'Desktop file already available' - else - mkdir -p "$HOME/.local/share/applications" - cp "$HOME/.local/share/lunarvim/lvim/utils/desktop/lvim.desktop" "$HOME/.local/share/applications/lvim.desktop" - fi -fi - -echo "I recommend you also install and activate a font from here: https://github.com/ryanoasis/nerd-fonts" -# echo 'export PATH=/home/$USER/.config/lunarvim/utils/bin:$PATH appending to zshrc/bashrc' +main "$@" From 378c1c3eb5f32da7057371fedda405250ccb67c8 Mon Sep 17 00:00:00 2001 From: chaeing Date: Mon, 23 Aug 2021 23:49:18 -0700 Subject: [PATCH 46/64] [Feature] enhance lualine config (#1372) --- lua/core/lualine/components.lua | 36 ++++++++++++++++++------ lua/core/lualine/init.lua | 2 +- lua/core/lualine/styles.lua | 50 ++++++--------------------------- lua/core/lualine/utils.lua | 3 ++ 4 files changed, 40 insertions(+), 51 deletions(-) diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua index b9211a79..042f6b6d 100644 --- a/lua/core/lualine/components.lua +++ b/lua/core/lualine/components.lua @@ -2,13 +2,16 @@ local conditions = require "core.lualine.conditions" local colors = require "core.lualine.colors" return { - vi_mode = { + mode = { function() return " " end, left_padding = 0, right_padding = 0, - condition = conditions.hide_in_width, + condition = function() + return true + end, + color = {}, }, branch = { "branch", @@ -16,6 +19,14 @@ return { condition = function() return conditions.hide_in_width() and conditions.check_git_workspace() end, + color = { gui = "bold" }, + }, + filename = { + "filename", + condition = function() + return true + end, + color = {}, }, diff = { "diff", @@ -24,6 +35,7 @@ return { color_modified = { fg = colors.yellow }, color_removed = { fg = colors.red }, condition = conditions.hide_in_width, + color = {}, }, python_env = { function() @@ -41,14 +53,15 @@ return { end return "" end, - color = { fg = colors.green }, condition = conditions.hide_in_width, + color = { fg = colors.green }, }, diagnostics = { "diagnostics", sources = { "nvim_lsp" }, symbols = { error = " ", warn = " ", info = " ", hint = " " }, condition = conditions.hide_in_width, + color = {}, }, treesitter = { function() @@ -57,8 +70,8 @@ return { end return "" end, - color = { fg = colors.green }, condition = conditions.hide_in_width, + color = { fg = colors.green }, }, lsp = { function(msg) @@ -92,12 +105,12 @@ return { return table.concat(buf_client_names, ", ") end, - condition = conditions.hide_in_width, icon = " ", + condition = conditions.hide_in_width, color = { gui = "bold" }, }, - location = { "location", condition = conditions.hide_in_width }, - progress = { "progress", condition = conditions.hide_in_width }, + location = { "location", condition = conditions.hide_in_width, color = {} }, + progress = { "progress", condition = conditions.hide_in_width, color = {} }, spaces = { function() local label = "Spaces: " @@ -107,13 +120,15 @@ return { return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " end, condition = conditions.hide_in_width, + color = {}, }, encoding = { "o:encoding", upper = true, condition = conditions.hide_in_width, + color = {}, }, - filetype = { "filetype", condition = conditions.hide_in_width }, + filetype = { "filetype", condition = conditions.hide_in_width, color = {} }, scrollbar = { function() local current_line = vim.fn.line "." @@ -123,8 +138,11 @@ return { local index = math.ceil(line_ratio * #chars) return chars[index] end, - color = { fg = colors.yellow, bg = colors.bg }, left_padding = 0, right_padding = 0, + condition = function() + return true + end, + color = { fg = colors.yellow, bg = colors.bg }, }, } diff --git a/lua/core/lualine/init.lua b/lua/core/lualine/init.lua index 5b3ce2a1..aa6fe098 100644 --- a/lua/core/lualine/init.lua +++ b/lua/core/lualine/init.lua @@ -40,7 +40,7 @@ M.setup = function() lualine.setup(lvim.builtin.lualine) if lvim.builtin.lualine.on_config_done then - lvim.builtin.lualine.on_config_done(lualine, lvim.builtin.lualine) + lvim.builtin.lualine.on_config_done(lualine) end end diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua index e35f66fe..876d7fa3 100644 --- a/lua/core/lualine/styles.lua +++ b/lua/core/lualine/styles.lua @@ -69,14 +69,15 @@ styles.lvim = { icons_enabled = true, component_separators = "", section_separators = "", - disabled_filetypes = { "dashboard", "" }, + disabled_filetypes = { "dashboard" }, }, sections = { lualine_a = { - components.vi_mode, + components.mode, }, lualine_b = { components.branch, + components.filename, }, lualine_c = { components.diff, @@ -86,15 +87,9 @@ styles.lvim = { components.diagnostics, components.treesitter, components.lsp, - -- components.location, - -- components.progress, - -- components.spaces, - -- components.encoding, components.filetype, }, - lualine_y = { - -- components.filetype, - }, + lualine_y = {}, lualine_z = { components.scrollbar, }, @@ -132,39 +127,12 @@ function M.get_style(style) end function M.update() - local config = lvim.builtin.lualine - local style = M.get_style(config.style) + local style = M.get_style(lvim.builtin.lualine.style) + if lvim.builtin.lualine.options.theme == nil then + lvim.builtin.lualine.options.theme = lvim.colorscheme + end - lvim.builtin.lualine = { - active = true, - style = style.style, - options = { - icons_enabled = config.options.icons_enabled or style.options.icons_enabled, - component_separators = config.options.component_separators or style.options.component_separators, - section_separators = config.options.section_separators or style.options.section_separators, - theme = config.options.theme or lvim.colorscheme or "auto", - disabled_filetypes = config.options.disabled_filetypes or style.options.disabled_filetypes, - }, - sections = { - lualine_a = config.sections.lualine_a or style.sections.lualine_a, - lualine_b = config.sections.lualine_b or style.sections.lualine_b, - lualine_c = config.sections.lualine_c or style.sections.lualine_c, - lualine_x = config.sections.lualine_x or style.sections.lualine_x, - lualine_y = config.sections.lualine_y or style.sections.lualine_y, - lualine_z = config.sections.lualine_z or style.sections.lualine_z, - }, - inactive_sections = { - lualine_a = config.inactive_sections.lualine_a or style.inactive_sections.lualine_a, - lualine_b = config.inactive_sections.lualine_b or style.inactive_sections.lualine_b, - lualine_c = config.inactive_sections.lualine_c or style.inactive_sections.lualine_c, - lualine_x = config.inactive_sections.lualine_x or style.inactive_sections.lualine_x, - lualine_y = config.inactive_sections.lualine_y or style.inactive_sections.lualine_y, - lualine_z = config.inactive_sections.lualine_z or style.inactive_sections.lualine_z, - }, - tabline = config.tabline or style.tabline, - extensions = config.extensions or style.extensions, - on_config_done = config.on_config_done, - } + lvim.builtin.lualine = vim.tbl_deep_extend("keep", lvim.builtin.lualine, style) end return M diff --git a/lua/core/lualine/utils.lua b/lua/core/lualine/utils.lua index f2f29592..cf80a99e 100644 --- a/lua/core/lualine/utils.lua +++ b/lua/core/lualine/utils.lua @@ -2,6 +2,9 @@ local M = {} function M.validate_theme() local theme = lvim.builtin.lualine.options.theme + if type(theme) == "table" then + return + end local lualine_loader = require "lualine.utils.loader" local ok = pcall(lualine_loader.load_theme, theme) From f6c706ac0c346491cc79bdea46a52ee7a8694e0d Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Tue, 24 Aug 2021 09:05:39 +0200 Subject: [PATCH 47/64] fix unrecognized rsync flag on osx --- utils/installer/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/installer/install.sh b/utils/installer/install.sh index 989f5595..28ed990c 100755 --- a/utils/installer/install.sh +++ b/utils/installer/install.sh @@ -207,8 +207,8 @@ function backup_old_config() { # that require an existing directory mkdir -p "$dir" "$dir.bak" if command -v rsync &>/dev/null; then - rsync --archive -hh --partial --info=stats1 --info=progress2 \ - --modify-window=1 "$dir" "$dir.bak" + rsync --archive -hh --partial --progress \ + --modify-window=1 "$dir"/ "$dir.bak" else cp -R "$dir/*" "$dir.bak/." fi From 00b895d9e9577f084cf577a07f9d6d6e1f7a4cac Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Wed, 25 Aug 2021 07:47:48 +0200 Subject: [PATCH 48/64] [Feature] Encapsulate config logic (#1338) * Define core/builtins, streamline status_color interface * Encapsulate configuration in its own module * Add fallback to lv-config.lua * Rectify settings loading order to allow overriding vim options * Move default-config into config/ module * replace uv.fs_stat with utils.is_file --- init.lua | 29 ++---------- .../defaults.lua} | 18 -------- lua/config/init.lua | 44 +++++++++++++++++++ lua/{ => config}/settings.lua | 4 +- lua/core/autocmds.lua | 3 +- lua/core/builtins/init.lua | 29 ++++++++++++ lua/core/dashboard.lua | 4 +- lua/core/info.lua | 6 ++- lua/utils/init.lua | 6 ++- 9 files changed, 89 insertions(+), 54 deletions(-) rename lua/{default-config.lua => config/defaults.lua} (97%) create mode 100644 lua/config/init.lua rename lua/{ => config}/settings.lua (98%) create mode 100644 lua/core/builtins/init.lua diff --git a/init.lua b/init.lua index 1d6cdc0f..9724c2cc 100644 --- a/init.lua +++ b/init.lua @@ -17,34 +17,11 @@ vim.opt.rtp:append(home_dir .. "/.local/share/lunarvim/site/after") vim.cmd [[let &packpath = &runtimepath]] -- }}} -local function file_exists(name) - local f = io.open(name, "r") - if f ~= nil then - io.close(f) - return true - else - return false - end -end +local config = require "config" +config:init() +config:load() -local lvim_path = os.getenv "HOME" .. "/.config/lvim/" -USER_CONFIG_PATH = lvim_path .. "config.lua" -local config_exist = file_exists(USER_CONFIG_PATH) -if not config_exist then - USER_CONFIG_PATH = lvim_path .. "lv-config.lua" - print "Rename ~/.config/lvim/lv-config.lua to config.lua" -end - -require "default-config" local autocmds = require "core.autocmds" -require("settings").load_options() - -local status_ok, error = pcall(vim.cmd, "luafile " .. USER_CONFIG_PATH) -if not status_ok then - print("something is wrong with your " .. USER_CONFIG_PATH) - print(error) -end -require("settings").load_commands() autocmds.define_augroups(lvim.autocommands) local plugins = require "plugins" diff --git a/lua/default-config.lua b/lua/config/defaults.lua similarity index 97% rename from lua/default-config.lua rename to lua/config/defaults.lua index 9d84efaa..5dc98698 100644 --- a/lua/default-config.lua +++ b/lua/config/defaults.lua @@ -1160,21 +1160,3 @@ lvim.lang = { }, }, } - --- NOTE: which-key should be first because it defines lvim.builtin.which_key.mappings -require("keymappings").config() -require("core.which-key").config() -require("core.gitsigns").config() -require("core.compe").config() -require("core.dashboard").config() -require("core.dap").config() -require("core.terminal").config() -require("core.telescope").config() -require("core.treesitter").config() -require("core.nvimtree").config() -require("core.project").config() -require("core.bufferline").config() -require("core.autopairs").config() -require("core.comment").config() -require("core.lspinstall").config() -require("core.lualine").config() diff --git a/lua/config/init.lua b/lua/config/init.lua new file mode 100644 index 00000000..9833fe6b --- /dev/null +++ b/lua/config/init.lua @@ -0,0 +1,44 @@ +local M = { + path = string.format("%s/.config/lvim/config.lua", os.getenv "HOME"), +} + +--- Initialize lvim default configuration +-- Define lvim global variable +function M:init() + local utils = require "utils" + + require "config.defaults" + + local builtins = require "core.builtins" + builtins.config(self) + + local settings = require "config.settings" + settings.load_options() + + -- Fallback config.lua to lv-config.lua + if not utils.is_file(self.path) then + local lv_config = self.path:gsub("config.lua$", "lv-config.lua") + print(self.path, "not found, falling back to", lv_config) + + self.path = lv_config + end +end + +--- Override the configuration with a user provided one +-- @param config_path The path to the configuration overrides +function M:load(config_path) + config_path = config_path or self.path + local ok, err = pcall(vim.cmd, "luafile " .. config_path) + if not ok then + print("Invalid configuration", config_path) + print(err) + return + end + + self.path = config_path + + local settings = require "config.settings" + settings.load_commands() +end + +return M diff --git a/lua/settings.lua b/lua/config/settings.lua similarity index 98% rename from lua/settings.lua rename to lua/config/settings.lua index d96c1338..ba71a922 100644 --- a/lua/settings.lua +++ b/lua/config/settings.lua @@ -1,8 +1,6 @@ local M = {} M.load_options = function() - local opt = vim.opt - local default_options = { backup = false, -- creates a backup file clipboard = "unnamedplus", -- allows neovim to access the system clipboard @@ -51,7 +49,7 @@ M.load_options = function() --- SETTINGS --- - opt.shortmess:append "c" + vim.opt.shortmess:append "c" for k, v in pairs(default_options) do vim.opt[k] = v diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua index 91278544..91ec70b5 100644 --- a/lua/core/autocmds.lua +++ b/lua/core/autocmds.lua @@ -1,4 +1,5 @@ local autocommands = {} +local config = require "config" lvim.autocommands = { _general_settings = { @@ -32,7 +33,7 @@ lvim.autocommands = { "*", "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", }, - { "BufWritePost", USER_CONFIG_PATH, "lua require('utils').reload_lv_config()" }, + { "BufWritePost", config.path, "lua require('utils').reload_lv_config()" }, { "FileType", "qf", diff --git a/lua/core/builtins/init.lua b/lua/core/builtins/init.lua new file mode 100644 index 00000000..32f96af5 --- /dev/null +++ b/lua/core/builtins/init.lua @@ -0,0 +1,29 @@ +local M = {} + +local builtins = { + "keymappings", + "core.which-key", + "core.gitsigns", + "core.compe", + "core.dashboard", + "core.dap", + "core.terminal", + "core.telescope", + "core.treesitter", + "core.nvimtree", + "core.project", + "core.bufferline", + "core.autopairs", + "core.comment", + "core.lspinstall", + "core.lualine", +} + +function M.config(config) + for _, builtin_path in ipairs(builtins) do + local builtin = require(builtin_path) + builtin.config(config) + end +end + +return M diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index c76d55c9..ac6ee013 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -1,6 +1,6 @@ local M = {} -M.config = function() +M.config = function(config) lvim.builtin.dashboard = { active = false, on_config_done = nil, @@ -47,7 +47,7 @@ M.config = function() }, e = { description = { " Configuration " }, - command = ":e " .. USER_CONFIG_PATH, + command = ":e " .. config.path, }, }, diff --git a/lua/core/info.lua b/lua/core/info.lua index d9b348b5..67e45d1c 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -16,6 +16,7 @@ local function str_list(list) end local function get_formatter_suggestion_msg(ft) + local config = require "config" local null_formatters = require "lsp.null-ls.formatters" local supported_formatters = null_formatters.list_available(ft) local section = { @@ -27,7 +28,7 @@ local function get_formatter_suggestion_msg(ft) if not vim.tbl_isempty(supported_formatters) then vim.list_extend(section, { "* Configured formatter needs to be installed and executable.", - fmt("* Enable installed formatter(s) with following config in %s", USER_CONFIG_PATH), + fmt("* Enable installed formatter(s) with following config in %s", config.path), "", fmt(" lvim.lang.%s.formatters = { { exe = '%s' } }", ft, table.concat(supported_formatters, "│")), }) @@ -37,6 +38,7 @@ local function get_formatter_suggestion_msg(ft) end local function get_linter_suggestion_msg(ft) + local config = require "config" local null_linters = require "lsp.null-ls.linters" local supported_linters = null_linters.list_available(ft) local section = { @@ -48,7 +50,7 @@ local function get_linter_suggestion_msg(ft) if not vim.tbl_isempty(supported_linters) then vim.list_extend(section, { "* Configured linter needs to be installed and executable.", - fmt("* Enable installed linter(s) with following config in %s", USER_CONFIG_PATH), + fmt("* Enable installed linter(s) with following config in %s", config.path), "", fmt(" lvim.lang.%s.linters = { { exe = '%s' } }", ft, table.concat(supported_linters, "│")), }) diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 446a1509..80a2dbe6 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -89,8 +89,10 @@ end function utils.reload_lv_config() require("core.lualine").config() - vim.cmd "source ~/.local/share/lunarvim/lvim/lua/settings.lua" - vim.cmd("source " .. USER_CONFIG_PATH) + + local config = require "config" + config:load() + require("keymappings").setup() -- this should be done before loading the plugins vim.cmd "source ~/.local/share/lunarvim/lvim/lua/plugins.lua" local plugins = require "plugins" From a83fffdc80bbd50b9a797adcab8ce29f0fdfacc2 Mon Sep 17 00:00:00 2001 From: chaeing Date: Wed, 25 Aug 2021 23:40:25 -0700 Subject: [PATCH 49/64] [Bugfix] Load user's autocmd custom_groups (#1393) * Require core.autocmds before sourcing user config * Define augroups after sourcing user config --- init.lua | 3 --- lua/config/init.lua | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index 9724c2cc..a3662a58 100644 --- a/init.lua +++ b/init.lua @@ -21,9 +21,6 @@ local config = require "config" config:init() config:load() -local autocmds = require "core.autocmds" -autocmds.define_augroups(lvim.autocommands) - local plugins = require "plugins" local plugin_loader = require("plugin-loader").init() plugin_loader:load { plugins, lvim.plugins } diff --git a/lua/config/init.lua b/lua/config/init.lua index 9833fe6b..8c5387cd 100644 --- a/lua/config/init.lua +++ b/lua/config/init.lua @@ -27,6 +27,8 @@ end --- Override the configuration with a user provided one -- @param config_path The path to the configuration overrides function M:load(config_path) + local autocmds = require "core.autocmds" + config_path = config_path or self.path local ok, err = pcall(vim.cmd, "luafile " .. config_path) if not ok then @@ -37,6 +39,8 @@ function M:load(config_path) self.path = config_path + autocmds.define_augroups(lvim.autocommands) + local settings = require "config.settings" settings.load_commands() end From 291c8bb5bd894b4da7c9e684915348a094a13aae Mon Sep 17 00:00:00 2001 From: chaeing Date: Thu, 26 Aug 2021 00:20:04 -0700 Subject: [PATCH 50/64] [Refactor] Lualine component conditions (#1394) --- lua/core/lualine/components.lua | 42 ++++++++++++++++++--------------- lua/core/lualine/conditions.lua | 10 ++++---- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua index 042f6b6d..894d9e9b 100644 --- a/lua/core/lualine/components.lua +++ b/lua/core/lualine/components.lua @@ -1,6 +1,17 @@ local conditions = require "core.lualine.conditions" local colors = require "core.lualine.colors" +local function diff_source() + local gitsigns = vim.b.gitsigns_status_dict + if gitsigns then + return { + added = gitsigns.added, + modified = gitsigns.changed, + removed = gitsigns.removed, + } + end +end + return { mode = { function() @@ -8,34 +19,29 @@ return { end, left_padding = 0, right_padding = 0, - condition = function() - return true - end, color = {}, + condition = nil, }, branch = { - "branch", + "b:gitsigns_head", icon = " ", - condition = function() - return conditions.hide_in_width() and conditions.check_git_workspace() - end, color = { gui = "bold" }, + condition = conditions.hide_in_width, }, filename = { "filename", - condition = function() - return true - end, color = {}, + condition = nil, }, diff = { "diff", + source = diff_source, symbols = { added = "  ", modified = "柳", removed = " " }, color_added = { fg = colors.green }, color_modified = { fg = colors.yellow }, color_removed = { fg = colors.red }, - condition = conditions.hide_in_width, color = {}, + condition = nil, }, python_env = { function() @@ -53,15 +59,15 @@ return { end return "" end, - condition = conditions.hide_in_width, color = { fg = colors.green }, + condition = conditions.hide_in_width, }, diagnostics = { "diagnostics", sources = { "nvim_lsp" }, symbols = { error = " ", warn = " ", info = " ", hint = " " }, - condition = conditions.hide_in_width, color = {}, + condition = conditions.hide_in_width, }, treesitter = { function() @@ -70,8 +76,8 @@ return { end return "" end, - condition = conditions.hide_in_width, color = { fg = colors.green }, + condition = conditions.hide_in_width, }, lsp = { function(msg) @@ -106,8 +112,8 @@ return { return table.concat(buf_client_names, ", ") end, icon = " ", - condition = conditions.hide_in_width, color = { gui = "bold" }, + condition = conditions.hide_in_width, }, location = { "location", condition = conditions.hide_in_width, color = {} }, progress = { "progress", condition = conditions.hide_in_width, color = {} }, @@ -125,8 +131,8 @@ return { encoding = { "o:encoding", upper = true, - condition = conditions.hide_in_width, color = {}, + condition = conditions.hide_in_width, }, filetype = { "filetype", condition = conditions.hide_in_width, color = {} }, scrollbar = { @@ -140,9 +146,7 @@ return { end, left_padding = 0, right_padding = 0, - condition = function() - return true - end, color = { fg = colors.yellow, bg = colors.bg }, + condition = nil, }, } diff --git a/lua/core/lualine/conditions.lua b/lua/core/lualine/conditions.lua index 2d2d81ef..3ee4fbb8 100644 --- a/lua/core/lualine/conditions.lua +++ b/lua/core/lualine/conditions.lua @@ -7,11 +7,11 @@ local conditions = { hide_in_width = function() return vim.fn.winwidth(0) > window_width_limit end, - check_git_workspace = function() - local filepath = vim.fn.expand "%:p:h" - local gitdir = vim.fn.finddir(".git", filepath .. ";") - return gitdir and #gitdir > 0 and #gitdir < #filepath - end, + -- check_git_workspace = function() + -- local filepath = vim.fn.expand "%:p:h" + -- local gitdir = vim.fn.finddir(".git", filepath .. ";") + -- return gitdir and #gitdir > 0 and #gitdir < #filepath + -- end, } return conditions From cfefddde9e9376e68ad8fcad3b1cf8cf139456e6 Mon Sep 17 00:00:00 2001 From: Chris Deligeorgis <59939524+chrisdlg@users.noreply.github.com> Date: Thu, 26 Aug 2021 12:08:48 +0200 Subject: [PATCH 51/64] Add a fallback for "ensurepip" on Debian based distros (#1396) --- utils/installer/install.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils/installer/install.sh b/utils/installer/install.sh index 28ed990c..355b0ecc 100755 --- a/utils/installer/install.sh +++ b/utils/installer/install.sh @@ -171,8 +171,10 @@ function install_nodejs_deps() { function install_python_deps() { echo "Verifying that pip is available.." if ! python3 -m ensurepip &>/dev/null; then - print_missing_dep_msg "pip" - exit 1 + if ! command -v pip3 &>/dev/null; then + print_missing_dep_msg "pip" + exit 1 + fi fi echo "Installing with pip.." for dep in "${__pip_deps[@]}"; do From 5b94e3cee2c4405e98c9c0e8769670723a1f4bae Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 26 Aug 2021 12:49:29 +0200 Subject: [PATCH 52/64] fix logging when plenary is not available (#1390) --- init.lua | 4 ++++ lua/core/log.lua | 43 +++++++++++++++++++++++++++++----- lua/core/lualine/styles.lua | 5 ++-- lua/core/nvimtree.lua | 2 +- lua/core/terminal.lua | 4 ++-- lua/keymappings.lua | 4 +--- lua/lsp/init.lua | 6 ++--- lua/lsp/null-ls/formatters.lua | 8 +++---- lua/lsp/null-ls/init.lua | 2 +- lua/lsp/null-ls/linters.lua | 8 +++---- lua/utils/init.lua | 10 +++----- 11 files changed, 61 insertions(+), 35 deletions(-) diff --git a/init.lua b/init.lua index a3662a58..43c6d25d 100644 --- a/init.lua +++ b/init.lua @@ -24,6 +24,10 @@ config:load() local plugins = require "plugins" local plugin_loader = require("plugin-loader").init() plugin_loader:load { plugins, lvim.plugins } + +local Log = require("core.log").new_default() +Log:info "Starting LunarVim" + vim.g.colors_name = lvim.colorscheme -- Colorscheme must get called after plugins are loaded or it will break new installs. vim.cmd("colorscheme " .. lvim.colorscheme) diff --git a/lua/core/log.lua b/lua/core/log.lua index 5dd5622e..54620625 100644 --- a/lua/core/log.lua +++ b/lua/core/log.lua @@ -4,26 +4,57 @@ local Log = {} ---@param opts these are passed verbatim to Plenary.log ---@return log handle function Log:new(opts) - local status_ok, _ = pcall(require, "plenary.log") + local status_ok, handle = pcall(require, "plenary.log") if not status_ok then - return nil + vim.notify("Plenary.log is not available. Logging to console only", vim.log.levels.DEBUG) end - local obj = require("plenary.log").new(opts) + self.__handle = handle + local path = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), opts.plugin) - obj.get_path = function() + self.get_path = function() return path end - return obj + setmetatable({}, Log) + return self +end + +function Log:add_entry(msg, level) + local status_ok, _ = pcall(require, "plenary.log") + if not status_ok then + return vim.notify(msg, vim.log.levels[level]) + end + -- plenary uses lower-case log levels + return self.__handle[level:lower()](msg) end --- Creates or retrieves a log handle for the default logfile --- based on Plenary.log ---@return log handle -function Log:get_default() +function Log:new_default() return Log:new { plugin = "lunarvim", level = lvim.log.level } end +function Log:trace(msg) + self:add_entry(msg, "TRACE") +end + +function Log:debug(msg) + self:add_entry(msg, "DEBUG") +end + +function Log:info(msg) + self:add_entry(msg, "INFO") +end + +function Log:warn(msg) + self:add_entry(msg, "TRACE") +end + +function Log:error(msg) + self:add_entry(msg, "TRACE") +end + return Log diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua index 876d7fa3..53b0691e 100644 --- a/lua/core/lualine/styles.lua +++ b/lua/core/lualine/styles.lua @@ -112,14 +112,13 @@ function M.get_style(style) local style_keys = vim.tbl_keys(styles) if not vim.tbl_contains(style_keys, style) then local Log = require "core.log" - local logger = Log:get_default() - logger.error( + Log:error( "Invalid lualine style", string.format('"%s"', style), "options are: ", string.format('"%s"', table.concat(style_keys, '", "')) ) - logger.info '"lvim" style is applied.' + Log:info '"lvim" style is applied.' style = "lvim" end diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index bea1add4..b5a6cc8d 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -52,7 +52,7 @@ end function M.setup() local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") if not status_ok then - Log:get_default().error "Failed to load nvim-tree.config" + Log:error "Failed to load nvim-tree.config" return end local g = vim.g diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index 4fced26e..f9be8734 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -82,7 +82,7 @@ M._exec_toggle = function(exec) local binary = M._split(exec)[1] if vim.fn.executable(binary) ~= 1 then local Log = require "core.log" - Log:get_default().error("Unable to run executable " .. binary .. ". Please make sure it is installed properly.") + Log:error("Unable to run executable " .. binary .. ". Please make sure it is installed properly.") return end local Terminal = require("toggleterm.terminal").Terminal @@ -122,7 +122,7 @@ M.toggle_log_view = function(name) local Terminal = require("toggleterm.terminal").Terminal local log_view = Terminal:new(term_opts) - -- require("core.log"):get_default().debug("term", vim.inspect(term_opts)) + -- require("core.log"):debug("term", vim.inspect(term_opts)) log_view:toggle() end diff --git a/lua/keymappings.lua b/lua/keymappings.lua index 7d75e06b..fa1af1c4 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -159,9 +159,7 @@ function M.config() lvim.keys.normal_mode[""] = lvim.keys.normal_mode[""] lvim.keys.normal_mode[""] = lvim.keys.normal_mode[""] lvim.keys.normal_mode[""] = lvim.keys.normal_mode[""] - if Log:get_default() then - Log:get_default().info "Activated mac keymappings" - end + Log:info "Activated mac keymappings" end end diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 631f142a..94fcf550 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -99,16 +99,14 @@ end function M.common_on_init(client, bufnr) if lvim.lsp.on_init_callback then lvim.lsp.on_init_callback(client, bufnr) - Log:get_default().info "Called lsp.on_init_callback" + Log:info "Called lsp.on_init_callback" return end local formatters = lvim.lang[vim.bo.filetype].formatters if not vim.tbl_isempty(formatters) and formatters[1]["exe"] ~= nil and formatters[1].exe ~= "" then client.resolved_capabilities.document_formatting = false - Log:get_default().info( - string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe) - ) + Log:info(string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe)) end end diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index cae1fa7d..05e0ec62 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -3,7 +3,7 @@ local formatters_by_ft = {} local null_ls = require "null-ls" local services = require "lsp.null-ls.services" -local logger = require("core.log"):get_default() +local Log = require "core.log" local function list_names(formatters, options) options = options or {} @@ -45,15 +45,15 @@ function M.list_configured(formatter_configs) local formatter = null_ls.builtins.formatting[fmt_config.exe] if not formatter then - logger.error("Not a valid formatter:", fmt_config.exe) + Log:error("Not a valid formatter:", fmt_config.exe) errors[fmt_config.exe] = {} -- Add data here when necessary else local formatter_cmd = services.find_command(formatter._opts.command) if not formatter_cmd then - logger.warn("Not found:", formatter._opts.command) + Log:warn("Not found:", formatter._opts.command) errors[fmt_config.exe] = {} -- Add data here when necessary else - logger.info("Using formatter:", formatter_cmd) + Log:info("Using formatter:", formatter_cmd) formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args } end end diff --git a/lua/lsp/null-ls/init.lua b/lua/lsp/null-ls/init.lua index 8691982e..ce4c07d9 100644 --- a/lua/lsp/null-ls/init.lua +++ b/lua/lsp/null-ls/init.lua @@ -30,7 +30,7 @@ function M.setup(filetype, options) local ok, _ = pcall(require, "null-ls") if not ok then - require("core.log"):get_default().error "Missing null-ls dependency" + require("core.log"):error "Missing null-ls dependency" return end diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index b449a4f2..70c59974 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -3,7 +3,7 @@ local linters_by_ft = {} local null_ls = require "null-ls" local services = require "lsp.null-ls.services" -local logger = require("core.log"):get_default() +local Log = require "core.log" local function list_names(linters, options) options = options or {} @@ -45,15 +45,15 @@ function M.list_configured(linter_configs) local linter = null_ls.builtins.diagnostics[lnt_config.exe] if not linter then - logger.error("Not a valid linter:", lnt_config.exe) + Log:error("Not a valid linter:", lnt_config.exe) errors[lnt_config.exe] = {} -- Add data here when necessary else local linter_cmd = services.find_command(linter._opts.command) if not linter_cmd then - logger.warn("Not found:", linter._opts.command) + Log:warn("Not found:", linter._opts.command) errors[lnt_config.exe] = {} -- Add data here when necessary else - logger.info("Using linter:", linter_cmd) + Log:info("Using linter:", linter_cmd) linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args } end end diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 80a2dbe6..322a961f 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -70,9 +70,7 @@ function utils.toggle_autoformat() }, }, } - if Log:get_default() then - Log:get_default().info "Format on save active" - end + Log:info "Format on save active" end if not lvim.format_on_save then @@ -81,9 +79,7 @@ function utils.toggle_autoformat() :autocmd! autoformat endif ]] - if Log:get_default() then - Log:get_default().info "Format on save off" - end + Log:info "Format on save off" end end @@ -104,7 +100,7 @@ function utils.reload_lv_config() -- vim.cmd ":PackerClean" local null_ls = require "lsp.null-ls" null_ls.setup(vim.bo.filetype, { force_reload = true }) - Log:get_default().info "Reloaded configuration" + Log:info "Reloaded configuration" end function utils.unrequire(m) From 14f129cf26a9814dc8f5fa46f483a588b5a813b0 Mon Sep 17 00:00:00 2001 From: Chris Deligeorgis <59939524+chrisdlg@users.noreply.github.com> Date: Thu, 26 Aug 2021 12:53:29 +0200 Subject: [PATCH 53/64] [Refactor]: use "python3 -m pip" in the install script (#1398) --- utils/installer/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/installer/install.sh b/utils/installer/install.sh index 355b0ecc..beef47fd 100755 --- a/utils/installer/install.sh +++ b/utils/installer/install.sh @@ -171,14 +171,14 @@ function install_nodejs_deps() { function install_python_deps() { echo "Verifying that pip is available.." if ! python3 -m ensurepip &>/dev/null; then - if ! command -v pip3 &>/dev/null; then + if ! python3 -m pip --version &>/dev/null; then print_missing_dep_msg "pip" exit 1 fi fi echo "Installing with pip.." for dep in "${__pip_deps[@]}"; do - pip3 install --user "$dep" + python3 -m pip install --user "$dep" done echo "All Python dependencies are succesfully installed" } From 27679f988fe187f9831ba7895c9c3a7ce2dd14f4 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 26 Aug 2021 20:32:16 +0200 Subject: [PATCH 54/64] [Refactor]: only allow a single logger (#1405) --- .github/workflows/install.yaml | 5 +-- init.lua | 2 +- lua/core/log.lua | 65 +++++++++++++++++----------------- lua/core/lualine/styles.lua | 2 +- lua/keymappings.lua | 2 +- lua/lsp/init.lua | 8 +++-- lua/lsp/null-ls/formatters.lua | 2 +- lua/lsp/null-ls/linters.lua | 2 +- lua/plugin-loader.lua | 9 ++--- lua/utils/init.lua | 4 +-- utils/installer/install.sh | 64 ++++++++++++++++----------------- 11 files changed, 81 insertions(+), 84 deletions(-) diff --git a/.github/workflows/install.yaml b/.github/workflows/install.yaml index f7d9da01..fa8bf0e3 100644 --- a/.github/workflows/install.yaml +++ b/.github/workflows/install.yaml @@ -38,8 +38,9 @@ jobs: - name: Install LunarVim timeout-minutes: 4 run: | - mkdir -p "$HOME/.local/share/lunarvim" - mkdir -p "$HOME/.config/lvim" + mkdir -p "$HOME"/.local/share/lunarvim/lvim + mkdir -p "$HOME"/.config/lvim + ln -s "$PWD"/* "$HOME"/.local/share/lunarvim/lvim/. bash ./utils/installer/install.sh - name: Test LunarVim PackerCompile diff --git a/init.lua b/init.lua index 43c6d25d..d253191e 100644 --- a/init.lua +++ b/init.lua @@ -25,7 +25,7 @@ local plugins = require "plugins" local plugin_loader = require("plugin-loader").init() plugin_loader:load { plugins, lvim.plugins } -local Log = require("core.log").new_default() +local Log = require "core.log" Log:info "Starting LunarVim" vim.g.colors_name = lvim.colorscheme -- Colorscheme must get called after plugins are loaded or it will break new installs. diff --git a/lua/core/log.lua b/lua/core/log.lua index 54620625..1eb786ba 100644 --- a/lua/core/log.lua +++ b/lua/core/log.lua @@ -1,60 +1,59 @@ local Log = {} ---- Creates a log handle based on Plenary.log ----@param opts these are passed verbatim to Plenary.log ----@return log handle -function Log:new(opts) - local status_ok, handle = pcall(require, "plenary.log") - if not status_ok then - vim.notify("Plenary.log is not available. Logging to console only", vim.log.levels.DEBUG) - end - - self.__handle = handle - - local path = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), opts.plugin) - - self.get_path = function() - return path - end - - setmetatable({}, Log) - return self -end - +--- Adds a log entry using Plenary.log +---@param msg any +---@param level string [same as vim.log.log_levels] function Log:add_entry(msg, level) - local status_ok, _ = pcall(require, "plenary.log") - if not status_ok then - return vim.notify(msg, vim.log.levels[level]) + assert(type(level) == "string") + if self.__handle then + -- plenary uses lower-case log levels + self.__handle[level:lower()](msg) end - -- plenary uses lower-case log levels - return self.__handle[level:lower()](msg) + local status_ok, plenary = pcall(require, "plenary") + if status_ok then + local default_opts = { plugin = "lunarvim", level = lvim.log.level } + local handle = plenary.log.new(default_opts) + handle[level:lower()](msg) + self.__handle = handle + end + -- don't do anything if plenary is not available end ---- Creates or retrieves a log handle for the default logfile ---- based on Plenary.log ----@return log handle -function Log:new_default() - return Log:new { plugin = "lunarvim", level = lvim.log.level } +---Retrieves the path of the logfile +---@return string path of the logfile +function Log:get_path() + return string.format("%s/%s.log", vim.fn.stdpath "cache", "lunarvim") end +---Add a log entry at TRACE level +---@param msg any function Log:trace(msg) self:add_entry(msg, "TRACE") end +---Add a log entry at DEBUG level +---@param msg any function Log:debug(msg) self:add_entry(msg, "DEBUG") end +---Add a log entry at INFO level +---@param msg any function Log:info(msg) self:add_entry(msg, "INFO") end +---Add a log entry at WARN level +---@param msg any function Log:warn(msg) - self:add_entry(msg, "TRACE") + self:add_entry(msg, "WARN") end +---Add a log entry at ERROR level +---@param msg any function Log:error(msg) - self:add_entry(msg, "TRACE") + self:add_entry(msg, "ERROR") end +setmetatable({}, Log) return Log diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua index 53b0691e..84e8123d 100644 --- a/lua/core/lualine/styles.lua +++ b/lua/core/lualine/styles.lua @@ -118,7 +118,7 @@ function M.get_style(style) "options are: ", string.format('"%s"', table.concat(style_keys, '", "')) ) - Log:info '"lvim" style is applied.' + Log:debug '"lvim" style is applied.' style = "lvim" end diff --git a/lua/keymappings.lua b/lua/keymappings.lua index fa1af1c4..557e0bde 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -159,7 +159,7 @@ function M.config() lvim.keys.normal_mode[""] = lvim.keys.normal_mode[""] lvim.keys.normal_mode[""] = lvim.keys.normal_mode[""] lvim.keys.normal_mode[""] = lvim.keys.normal_mode[""] - Log:info "Activated mac keymappings" + Log:debug "Activated mac keymappings" end end diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 94fcf550..f3b019aa 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -99,21 +99,23 @@ end function M.common_on_init(client, bufnr) if lvim.lsp.on_init_callback then lvim.lsp.on_init_callback(client, bufnr) - Log:info "Called lsp.on_init_callback" + Log:debug "Called lsp.on_init_callback" return end local formatters = lvim.lang[vim.bo.filetype].formatters if not vim.tbl_isempty(formatters) and formatters[1]["exe"] ~= nil and formatters[1].exe ~= "" then client.resolved_capabilities.document_formatting = false - Log:info(string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe)) + Log:debug( + string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe) + ) end end function M.common_on_attach(client, bufnr) if lvim.lsp.on_attach_callback then lvim.lsp.on_attach_callback(client, bufnr) - Log:get_default().info "Called lsp.on_init_callback" + Log:debug "Called lsp.on_init_callback" end lsp_highlight_document(client) add_lsp_buffer_keybindings(bufnr) diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index 05e0ec62..26be00da 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -53,7 +53,7 @@ function M.list_configured(formatter_configs) Log:warn("Not found:", formatter._opts.command) errors[fmt_config.exe] = {} -- Add data here when necessary else - Log:info("Using formatter:", formatter_cmd) + Log:debug("Using formatter:", formatter_cmd) formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args } end end diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index 70c59974..bc191d7e 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -53,7 +53,7 @@ function M.list_configured(linter_configs) Log:warn("Not found:", linter._opts.command) errors[lnt_config.exe] = {} -- Add data here when necessary else - Log:info("Using linter:", linter_cmd) + Log:debug("Using linter:", linter_cmd) linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args } end end diff --git a/lua/plugin-loader.lua b/lua/plugin-loader.lua index e238b193..aa1e888d 100644 --- a/lua/plugin-loader.lua +++ b/lua/plugin-loader.lua @@ -1,13 +1,10 @@ local plugin_loader = {} function plugin_loader:init() - local execute = vim.api.nvim_command - local fn = vim.fn - local install_path = "~/.local/share/lunarvim/site/pack/packer/start/packer.nvim" - if fn.empty(fn.glob(install_path)) > 0 then - execute("!git clone https://github.com/wbthomason/packer.nvim " .. install_path) - execute "packadd packer.nvim" + if vim.fn.empty(vim.fn.glob(install_path)) > 0 then + vim.fn.system { "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path } + vim.cmd "packadd packer.nvim" end local packer_ok, packer = pcall(require, "packer") diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 322a961f..8ea842ca 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -70,7 +70,7 @@ function utils.toggle_autoformat() }, }, } - Log:info "Format on save active" + Log:debug "Format on save active" end if not lvim.format_on_save then @@ -79,7 +79,7 @@ function utils.toggle_autoformat() :autocmd! autoformat endif ]] - Log:info "Format on save off" + Log:debug "Format on save off" end end diff --git a/utils/installer/install.sh b/utils/installer/install.sh index beef47fd..4392635d 100755 --- a/utils/installer/install.sh +++ b/utils/installer/install.sh @@ -50,33 +50,35 @@ EOF echo "Detecting platform for managing any additional neovim dependencies" detect_platform - # skip this in a Github workflow - if [ -z "$GITHUB_ACTIONS" ]; then - check_system_deps - - __add_separator "80" - - echo "Would you like to check lunarvim's NodeJS dependencies?" - read -p "[y]es or [n]o (default: no) : " -r answer - [ "$answer" != "${answer#[Yy]}" ] && install_nodejs_deps - - echo "Would you like to check lunarvim's Python dependencies?" - read -p "[y]es or [n]o (default: no) : " -r answer - [ "$answer" != "${answer#[Yy]}" ] && install_python_deps - - echo "Would you like to check lunarvim's Rust dependencies?" - read -p "[y]es or [n]o (default: no) : " -r answer - [ "$answer" != "${answer#[Yy]}" ] && install_rust_deps - - __add_separator "80" - - echo "Backing up old LunarVim configuration" - backup_old_config - - __add_separator "80" - + if [ -n "$GITHUB_ACTIONS" ]; then + install_packer + setup_lvim + exit 0 fi + check_system_deps + + __add_separator "80" + + echo "Would you like to check lunarvim's NodeJS dependencies?" + read -p "[y]es or [n]o (default: no) : " -r answer + [ "$answer" != "${answer#[Yy]}" ] && install_nodejs_deps + + echo "Would you like to check lunarvim's Python dependencies?" + read -p "[y]es or [n]o (default: no) : " -r answer + [ "$answer" != "${answer#[Yy]}" ] && install_python_deps + + echo "Would you like to check lunarvim's Rust dependencies?" + read -p "[y]es or [n]o (default: no) : " -r answer + [ "$answer" != "${answer#[Yy]}" ] && install_rust_deps + + __add_separator "80" + + echo "Backing up old LunarVim configuration" + backup_old_config + + __add_separator "80" + case "$@" in *--overwrite*) echo "!!Warning!! -> Removing all lunarvim related config \ @@ -219,13 +221,13 @@ function backup_old_config() { } function install_packer() { - git clone --progress --depth 1 https://github.com/wbthomason/packer.nvim \ + git clone --depth 1 https://github.com/wbthomason/packer.nvim \ "$LUNARVIM_RUNTIME_DIR/site/pack/packer/start/packer.nvim" } function clone_lvim() { echo "Cloning LunarVim configuration" - if ! git clone --progress --branch "$LV_BRANCH" \ + if ! git clone --branch "$LV_BRANCH" \ --depth 1 "https://github.com/${LV_REMOTE}" "$LUNARVIM_RUNTIME_DIR/lvim"; then echo "Failed to clone repository. Installation failed." exit 1 @@ -258,12 +260,8 @@ function setup_lvim() { "$LUNARVIM_CONFIG_DIR/config.lua" nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" --headless \ - +'autocmd User PackerComplete sleep 100m | qall' \ - +PackerInstall - - nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" --headless \ - +'autocmd User PackerComplete sleep 100m | qall' \ - +PackerSync + -c 'autocmd User PackerComplete quitall' \ + -c 'PackerSync' echo "Packer setup complete" From 7aa079d74a11f53f90e3b30371f530e85eb63b93 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Thu, 26 Aug 2021 22:40:24 -0400 Subject: [PATCH 55/64] disable nvimtree and outline for lualine --- lua/core/lualine/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/core/lualine/init.lua b/lua/core/lualine/init.lua index aa6fe098..9bf4f831 100644 --- a/lua/core/lualine/init.lua +++ b/lua/core/lualine/init.lua @@ -8,7 +8,7 @@ M.config = function() component_separators = nil, section_separators = nil, theme = nil, - disabled_filetypes = nil, + disabled_filetypes = {'NvimTree', 'Outline'} }, sections = { lualine_a = nil, From a0fd11ea0875e663b396dcdbce446072bcc1005e Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Thu, 26 Aug 2021 22:54:15 -0400 Subject: [PATCH 56/64] use styles.lua rather instead of editing options directly --- lua/core/lualine/init.lua | 2 +- lua/core/lualine/styles.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/core/lualine/init.lua b/lua/core/lualine/init.lua index 9bf4f831..30b6a6a6 100644 --- a/lua/core/lualine/init.lua +++ b/lua/core/lualine/init.lua @@ -8,7 +8,7 @@ M.config = function() component_separators = nil, section_separators = nil, theme = nil, - disabled_filetypes = {'NvimTree', 'Outline'} + disabled_filetypes = nil }, sections = { lualine_a = nil, diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua index 84e8123d..3595e5e3 100644 --- a/lua/core/lualine/styles.lua +++ b/lua/core/lualine/styles.lua @@ -69,7 +69,7 @@ styles.lvim = { icons_enabled = true, component_separators = "", section_separators = "", - disabled_filetypes = { "dashboard" }, + disabled_filetypes = { "dashboard", "NvimTree", "Outline" }, }, sections = { lualine_a = { From d0083e488d8b0d4e38ca71558787a427688b1cb2 Mon Sep 17 00:00:00 2001 From: Chae SM Date: Thu, 26 Aug 2021 21:05:47 -0700 Subject: [PATCH 57/64] Remap 'Goto implementation' binding from gi to gI --- lua/lsp/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index f3b019aa..9c948803 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -44,7 +44,7 @@ local function add_lsp_buffer_keybindings(bufnr) ["gd"] = { "lua vim.lsp.buf.definition()", "Goto Definition" }, ["gD"] = { "lua vim.lsp.buf.declaration()", "Goto declaration" }, ["gr"] = { "lua vim.lsp.buf.references()", "Goto references" }, - ["gi"] = { "lua vim.lsp.buf.implementation()", "Goto implementation" }, + ["gI"] = { "lua vim.lsp.buf.implementation()", "Goto Implementation" }, ["gs"] = { "lua vim.lsp.buf.signature_help()", "show signature help" }, ["gp"] = { "lua require'lsp.peek'.Peek('definition')", "Peek definition" }, ["gl"] = { From 33af0668baf2df2a27782e2db8c6dd72cdf914b4 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Fri, 27 Aug 2021 00:10:45 -0400 Subject: [PATCH 58/64] format --- lua/core/lualine/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/core/lualine/init.lua b/lua/core/lualine/init.lua index 30b6a6a6..aa6fe098 100644 --- a/lua/core/lualine/init.lua +++ b/lua/core/lualine/init.lua @@ -8,7 +8,7 @@ M.config = function() component_separators = nil, section_separators = nil, theme = nil, - disabled_filetypes = nil + disabled_filetypes = nil, }, sections = { lualine_a = nil, From df7c3cb8f0512042bd24c10e744718991ae6a9a2 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Fri, 27 Aug 2021 00:11:01 -0400 Subject: [PATCH 59/64] q to quit quickfix when focused --- lua/core/autocmds.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua index 91ec70b5..041926e5 100644 --- a/lua/core/autocmds.lua +++ b/lua/core/autocmds.lua @@ -8,6 +8,11 @@ lvim.autocommands = { "*", "lua require('utils.ft').do_filetype(vim.fn.expand(\"\"))", }, + { + "FileType", + "qf", + "nnoremap q :q", + }, { "TextYankPost", "*", From 23952f14437be39056b1e89436e8aea76dfbb61d Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 27 Aug 2021 18:47:31 +0200 Subject: [PATCH 60/64] Fix missing "HOME" variable errors (#1415) Co-authored-by: MarcSchaetz --- init.lua | 2 +- lua/config/defaults.lua | 5 +++-- lua/config/init.lua | 3 ++- lua/core/dashboard.lua | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index d253191e..3ed7d231 100644 --- a/init.lua +++ b/init.lua @@ -47,7 +47,7 @@ end local lsp_settings_status_ok, lsp_settings = pcall(require, "nlspsettings") if lsp_settings_status_ok then lsp_settings.setup { - config_home = os.getenv "HOME" .. "/.config/lvim/lsp-settings", + config_home = home_dir .. "/.config/lvim/lsp-settings", } end diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index 5dc98698..9bd1bdd8 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -1,4 +1,5 @@ -CONFIG_PATH = os.getenv "HOME" .. "/.local/share/lunarvim/lvim" +local home_dir = vim.loop.os_homedir() +CONFIG_PATH = home_dir .. "/.local/share/lunarvim/lvim" DATA_PATH = vim.fn.stdpath "data" CACHE_PATH = vim.fn.stdpath "cache" TERMINAL = vim.fn.expand "$TERMINAL" @@ -11,7 +12,7 @@ lvim = { line_wrap_cursor_movement = true, transparent_window = false, format_on_save = true, - vsnip_dir = os.getenv "HOME" .. "/.config/snippets", + vsnip_dir = home_dir .. "/.config/snippets", database = { save_location = "~/.config/lunarvim_db", auto_execute = 1 }, keys = {}, diff --git a/lua/config/init.lua b/lua/config/init.lua index 8c5387cd..332460d3 100644 --- a/lua/config/init.lua +++ b/lua/config/init.lua @@ -1,5 +1,6 @@ +local home_dir = vim.loop.os_homedir() local M = { - path = string.format("%s/.config/lvim/config.lua", os.getenv "HOME"), + path = string.format("%s/.config/lvim/config.lua", home_dir), } --- Initialize lvim default configuration diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index ac6ee013..a613921f 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -1,4 +1,5 @@ local M = {} +local home_dir = vim.loop.os_homedir() M.config = function(config) lvim.builtin.dashboard = { @@ -6,7 +7,7 @@ M.config = function(config) on_config_done = nil, search_handler = "telescope", disable_at_vim_enter = 0, - session_directory = os.getenv "HOME" .. "/.cache/lvim/sessions", + session_directory = home_dir .. "/.cache/lvim/sessions", custom_header = { "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣶⣾⠿⠿⠟⠛⠛⠛⠛⠿⠿⣿⣷⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", From 21d04257a8c306fbb0c17486791bc46d6212e611 Mon Sep 17 00:00:00 2001 From: Lee Marlow Date: Fri, 27 Aug 2021 13:46:11 -0600 Subject: [PATCH 61/64] [Feature] Fetch from git before update in install script (#1409) --- utils/installer/install.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils/installer/install.sh b/utils/installer/install.sh index 4392635d..9e198274 100755 --- a/utils/installer/install.sh +++ b/utils/installer/install.sh @@ -211,7 +211,7 @@ function backup_old_config() { # that require an existing directory mkdir -p "$dir" "$dir.bak" if command -v rsync &>/dev/null; then - rsync --archive -hh --partial --progress \ + rsync --archive -hh --partial --progress --cvs-exclude \ --modify-window=1 "$dir"/ "$dir.bak" else cp -R "$dir/*" "$dir.bak/." @@ -273,8 +273,9 @@ function setup_lvim() { } function update_lvim() { - if ! git -C "$LUNARVIM_RUNTIME_DIR/lvim" status -uno &>/dev/null; then - git -C "$LUNARVIM_RUNTIME_DIR/lvim" pull --ff-only --progress || + git -C "$LUNARVIM_RUNTIME_DIR/lvim" fetch --quiet + if ! git -C "$LUNARVIM_RUNTIME_DIR/lvim" diff --quiet "@{upstream}"; then + git -C "$LUNARVIM_RUNTIME_DIR/lvim" merge --ff-only --progress || echo "Unable to guarantee data integrity while updating. Please do that manually instead." && exit 1 fi echo "Your LunarVim installation is now up to date!" From 17e65a99fea6a61ae55f181432be3ce30d082283 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Sat, 28 Aug 2021 09:45:42 -0400 Subject: [PATCH 62/64] use netrw when opening directory --- lua/core/nvimtree.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index b5a6cc8d..6aa5401d 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -15,7 +15,7 @@ function M.config() tree_width = 30, }, ignore = { ".git", "node_modules", ".cache" }, - auto_open = 1, + auto_open = 0, auto_close = 1, quit_on_open = 0, follow = 1, @@ -65,6 +65,9 @@ function M.setup() if lvim.builtin.project.active then vim.g.nvim_tree_update_cwd = 1 vim.g.nvim_tree_respect_buf_cwd = 1 + vim.g.nvim_tree_disable_netrw = 0 + vim.g.nvim_tree_hijack_netrw = 0 + vim.g.netrw_banner = 0 end local tree_cb = nvim_tree_config.nvim_tree_callback From 8bd731a8f7fd53595d6e90509e2e23c957cf171b Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Sat, 28 Aug 2021 10:26:15 -0400 Subject: [PATCH 63/64] netrw ftplugin --- ftplugin/netrw.lua | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 ftplugin/netrw.lua diff --git a/ftplugin/netrw.lua b/ftplugin/netrw.lua new file mode 100644 index 00000000..b2292870 --- /dev/null +++ b/ftplugin/netrw.lua @@ -0,0 +1,2 @@ +vim.cmd [[nmap h -]] +vim.cmd [[nmap l ]] From c7a5122fe2c14dba0f28f1c077f838f957884afc Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Sun, 29 Aug 2021 14:11:04 -0400 Subject: [PATCH 64/64] fix: Cursorhold Event not firing after entering lunarvim from dashboard->telescope closes #1413 --- lua/plugins.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/plugins.lua b/lua/plugins.lua index 5aaac3ce..8a0692f2 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -4,6 +4,7 @@ return { { "neovim/nvim-lspconfig" }, { "tamago324/nlsp-settings.nvim" }, { "jose-elias-alvarez/null-ls.nvim" }, + { "antoinemadec/FixCursorHold.nvim" }, -- Needed while issue https://github.com/neovim/neovim/issues/12587 is still open { "kabouzeid/nvim-lspinstall", event = "VimEnter",