From 71e0266b4b67a8924abbadfce4a4ee1c123b39a2 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 18 Jul 2021 03:41:26 +0430 Subject: [PATCH 01/12] added support for svelte (#1008) --- ftplugin/svelte.lua | 4 ++++ lua/default-config.lua | 1 + lua/lang/svelte.lua | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 ftplugin/svelte.lua create mode 100644 lua/lang/svelte.lua diff --git a/ftplugin/svelte.lua b/ftplugin/svelte.lua new file mode 100644 index 00000000..108a0fc3 --- /dev/null +++ b/ftplugin/svelte.lua @@ -0,0 +1,4 @@ +require("lang.svelte").format() +require("lang.svelte").lint() +require("lang.svelte").lsp() +require("lang.svelte").dap() diff --git a/lua/default-config.lua b/lua/default-config.lua index 408ba038..58df41d1 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -181,6 +181,7 @@ require("lang.ruby").config() require("lang.rust").config() require("lang.scala").config() require("lang.sh").config() +require("lang.svelte").config() require("lang.terraform").config() require("lang.tex").config() require("lang.vim").config() diff --git a/lua/lang/svelte.lua b/lua/lang/svelte.lua new file mode 100644 index 00000000..220c2c18 --- /dev/null +++ b/lua/lang/svelte.lua @@ -0,0 +1,35 @@ +local M = {} + +M.config = function() + O.lang.svelte = {} +end + +M.format = function() + -- TODO: implement formatter (if applicable) + return "No formatter configured!" +end + +M.lint = function() + -- TODO: implement linters (if applicable) + return "No linters configured!" +end + +M.lsp = function() + if require("lv-utils").check_lsp_client_active "svelte" then + return + end + + require("lspconfig").svelte.setup { + cmd = { DATA_PATH .. "/lspinstall/svelte/node_modules/.bin/svelteserver", "--stdio" }, + filetypes = { "svelte" }, + root_dir = require("lspconfig.util").root_pattern("package.json", ".git"), + on_attach = require("lsp").common_on_attach, + } +end + +M.dap = function() + -- TODO: implement dap + return "No DAP configured!" +end + +return M From 5d21a1dbd8e7c4eb8b82f85df75433dcff86d930 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 18 Jul 2021 03:41:57 +0430 Subject: [PATCH 02/12] a better path_display default for telescope (#1009) --- lua/core/telescope.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index 5a067d67..4456d65e 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -33,7 +33,7 @@ M.config = function() file_sorter = require("telescope.sorters").get_fzy_sorter, file_ignore_patterns = {}, generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, - path_display = { "shorten" }, + path_display = { shorten = 5 }, winblend = 0, border = {}, borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, From 6e6a4a96e07fd5621e9ee0a76bfb907589f89bf6 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 18 Jul 2021 15:57:06 +0430 Subject: [PATCH 03/12] fixing broken nvimtree (#1012) --- lua/core/nvimtree.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index e3df9afb..7ecbe8c2 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -1,8 +1,4 @@ local M = {} -local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") -if not status_ok then - return -end -- M.config = function() O.plugin.nvimtree = { @@ -50,6 +46,10 @@ M.config = function() end -- M.setup = function() + local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") + if not status_ok then + return + end local g = vim.g for opt, val in pairs(O.plugin.nvimtree) do @@ -65,12 +65,12 @@ M.setup = function() } end -- -local view_status_ok, view = pcall(require, "nvim-tree.view") -if not view_status_ok then - return -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 From 5fb24d2bd86083fb1bf067542f0c7a52e66a7121 Mon Sep 17 00:00:00 2001 From: Kai Date: Sun, 18 Jul 2021 14:06:43 +0200 Subject: [PATCH 04/12] remove ranger and ueberzug (#1014) --- utils/installer/install.sh | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/utils/installer/install.sh b/utils/installer/install.sh index 0473bbab..36178ae5 100755 --- a/utils/installer/install.sh +++ b/utils/installer/install.sh @@ -134,38 +134,30 @@ asktoinstallpip() { } installonmac() { - brew install ripgrep fzf ranger + brew install ripgrep fzf npm install -g tree-sitter-cli } -pipinstallueberzug() { - which pip3 >/dev/null && pip3 install ueberzug || echo "Not installing ueberzug pip not found" -} - installonubuntu() { - sudo apt install ripgrep fzf ranger + sudo apt install ripgrep fzf sudo apt install libjpeg8-dev zlib1g-dev python-dev python3-dev libxtst-dev - pip3 install ueberzug pip3 install neovim-remote npm install -g tree-sitter-cli } installonarch() { - sudo pacman -S ripgrep fzf ranger - which yay >/dev/null && yay -S python-ueberzug-git || pipinstallueberzug + 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 ranger - pip3 install wheel ueberzug + sudo dnf install -y fzf ripgrep } installongentoo() { - sudo emerge -avn sys-apps/ripgrep app-shells/fzf app-misc/ranger dev-python/neovim-remote virtual/jpeg sys-libs/zlib - pipinstallueberzug + sudo emerge -avn sys-apps/ripgrep app-shells/fzf dev-python/neovim-remote virtual/jpeg sys-libs/zlib npm install -g tree-sitter-cli } @@ -217,7 +209,4 @@ else fi echo "I recommend you also install and activate a font from here: https://github.com/ryanoasis/nerd-fonts" - -# echo "I also recommend you add 'set preview_images_method ueberzug' to ~/.config/ranger/rc.conf" - # echo 'export PATH=/home/$USER/.config/lunarvim/utils/bin:$PATH appending to zshrc/bashrc' From f0d22b299f2a49272454f657b32dacadceeb0096 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 18 Jul 2021 16:39:26 +0430 Subject: [PATCH 05/12] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e11e9267..309e8ebe 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,13 @@ LVBRANCH=rolling bash <(curl -s https://raw.githubusercontent.com/ChristianChiar ``` If your installation is stuck on `Ok to remove? [y/N]`, it means there are some leftovers, \ -you can run the script with `--overwrite` but be warned this will remove the following folder: +you can run the script with `--overwrite` but be warned this will remove the following folders: - `~/.config/nvim` - `~/.cache/nvim` - `~/.local/share/nvim/site/pack/packer` ```bash curl -s https://raw.githubusercontent.com/ChristianChiarulli/lunarvim/rolling/utils/installer/install.sh | LVBRANCH=rolling bash -s -- --overwrite +# then run nvim and wait for treesitter to finish the installation ``` From 59106e860edde09107d2628a81eee816871eb065 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 18 Jul 2021 19:49:41 +0200 Subject: [PATCH 06/12] [Refactor] Make default keybindings configurable (#988) --- README.md | 22 +++- init.lua | 2 +- lua/default-config.lua | 4 +- lua/keymappings.lua | 109 +++++++++++--------- lua/lv-utils/init.lua | 26 +++++ lua/settings.lua | 6 -- utils/installer/lv-config.example-no-ts.lua | 20 +++- utils/installer/lv-config.example.lua | 20 +++- 8 files changed, 148 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 309e8ebe..99440bff 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,27 @@ O.completion.autocomplete = true O.default_options.relativenumber = true O.colorscheme = 'spacegray' O.default_options.timeoutlen = 100 -O.leader_key = ' ' + +-- keymappings +O.keys.leader_key = "space" +-- overwrite the key-mappings provided by LunarVim for any mode, or leave it empty to keep them +O.keys.normal_mode = { + -- Page down/up + {'[d', ''}, + {']d', ''}, + + -- Navigate buffers + {'', ':bnext'}, + {'', ':bprevious'}, +} +-- if you just want to augment the existing ones then use the utility function +require("lv-utils").add_keymap_insert_mode({ silent = true }, { + { "", ":w" }, + { "", "" } +}) + +-- you can also use the native vim way directly +vim.api.nvim_set_keymap("i", "", "compe#complete()", { noremap = true, silent = true, expr = true }) -- After changing plugin config it is recommended to run :PackerCompile O.plugin.dashboard.active = true diff --git a/init.lua b/init.lua index c8088523..b159b0ed 100644 --- a/init.lua +++ b/init.lua @@ -1,10 +1,10 @@ require "default-config" -require "keymappings" local status_ok, error = pcall(vim.cmd, "luafile " .. CONFIG_PATH .. "/lv-config.lua") if not status_ok then print "something is wrong with your lv-config" print(error) end +require "keymappings" require "plugins" vim.g.colors_name = O.colorscheme -- Colorscheme must get called after plugins are loaded or it will break new installs. require "settings" diff --git a/lua/default-config.lua b/lua/default-config.lua index 58df41d1..95549b53 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -5,7 +5,9 @@ TERMINAL = vim.fn.expand "$TERMINAL" USER = vim.fn.expand "$USER" O = { - leader_key = "space", + keys = { + leader_key = "space", + }, colorscheme = "spacegray", line_wrap_cursor_movement = true, transparent_window = false, diff --git a/lua/keymappings.lua b/lua/keymappings.lua index fed362aa..03a1618c 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -1,42 +1,41 @@ -local function register_mappings(mappings, default_options) - for mode, mode_mappings in pairs(mappings) do - for _, mapping in pairs(mode_mappings) do - local options = #mapping == 3 and table.remove(mapping) or default_options - local prefix, cmd = unpack(mapping) - pcall(vim.api.nvim_set_keymap, mode, prefix, cmd, options) - end - end -end +local lv_utils = require "lv-utils" -local mappings = { - i = { -- Insert mode +local opts = { + nnoremap = { noremap = true, silent = true }, + inoremap = { noremap = true, silent = true }, + vnoremap = { noremap = true, silent = true }, + xnoremap = { noremap = true, silent = true }, + generic = { silent = true }, +} + +local default_keys = { + insert_mode = { -- I hate escape { "jk", "" }, { "kj", "" }, { "jj", "" }, - -- Move current line / block with Alt-j/k ala vscode. { "", ":m .+1==gi" }, { "", ":m .-2==gi" }, - - -- Terminal window navigation - { "", "h" }, - { "", "j" }, - { "", "k" }, - { "", "l" }, + -- navigation + { "", "h" }, + { "", "j" }, + { "", "k" }, + { "", "l" }, }, - n = { -- Normal mode + + normal_mode = { -- Better window movement - { "", "h", { silent = true } }, - { "", "j", { silent = true } }, - { "", "k", { silent = true } }, - { "", "l", { silent = true } }, + { "", "h" }, + { "", "j" }, + { "", "k" }, + { "", "l" }, -- Resize with arrows - { "", ":resize -2", { silent = true } }, - { "", ":resize +2", { silent = true } }, - { "", ":vertical resize -2", { silent = true } }, - { "", ":vertical resize +2", { silent = true } }, + { "", ":resize -2" }, + { "", ":resize +2" }, + { "", ":vertical resize -2" }, + { "", ":vertical resize +2" }, -- Tab switch buffer -- { "", ":bnext" }, @@ -49,17 +48,20 @@ local mappings = { -- QuickFix { "]q", ":cnext" }, { "[q", ":cprev" }, + { "", ":call QuickFixToggle()" }, -- {'', 'compe#complete()', {noremap = true, silent = true, expr = true}}, }, - t = { -- Terminal mode + + term_mode = { -- Terminal window navigation { "", "h" }, { "", "j" }, { "", "k" }, { "", "l" }, }, - v = { -- Visual/Select mode + + visual_mode = { -- Better indenting { "<", "", ">gv" }, @@ -67,7 +69,8 @@ local mappings = { -- { "p", '"0p', { silent = true } }, -- { "P", '"0P', { silent = true } }, }, - x = { -- Visual mode + + visual_block_mode = { -- Move selected line / block of text in visual mode { "K", ":move '<-2gv-gv" }, { "J", ":move '>+1gv-gv" }, @@ -76,31 +79,37 @@ local mappings = { { "", ":m '>+1gv-gv" }, { "", ":m '<-2gv-gv" }, }, - [""] = { - -- Toggle the QuickFix window - { "", ":call QuickFixToggle()" }, - }, } --- TODO: fix this if vim.fn.has "mac" == 1 then - mappings["n"][5][1] = "" - mappings["n"][6][1] = "" - mappings["n"][7][1] = "" - mappings["n"][8][1] = "" + -- TODO: fix this + default_keys.insert_mode["n"][5][1] = "" + default_keys.insert_mode["n"][6][1] = "" + default_keys.insert_mode["n"][7][1] = "" + default_keys.insert_mode["n"][8][1] = "" end -register_mappings(mappings, { silent = true, noremap = true }) +if O.keys.leader_key == " " or O.keys.leader_key == "space" then + vim.g.mapleader = " " +else + vim.g.mapleader = O.keys.leader_key +end -vim.cmd 'inoremap ("\\")' -vim.cmd 'inoremap ("\\")' +local function get_user_keys(mode) + if O.keys[mode] == nil then + return default_keys[mode] + else + return O.keys[mode] + end +end --- vim.cmd('inoremap (\"\\\")') --- vim.cmd('inoremap (\"\\\")') +lv_utils.add_keymap_normal_mode(opts.nnoremap, get_user_keys "normal_mode") +lv_utils.add_keymap_insert_mode(opts.inoremap, get_user_keys "insert_mode") +lv_utils.add_keymap_visual_mode(opts.vnoremap, get_user_keys "visual_mode") +lv_utils.add_keymap_visual_block_mode(opts.xnoremap, get_user_keys "visual_block_mode") +lv_utils.add_keymap_term_mode(opts.generic, get_user_keys "visual_block_mode") --- vim.cmd([[ --- map p (miniyank-autoput) --- map P (miniyank-autoPut) --- map n (miniyank-cycle) --- map N (miniyank-cycleback) --- ]]) +-- navigate tab completion with and +-- runs conditionally +vim.cmd 'inoremap pumvisible() ? "\\" : "\\"' +vim.cmd 'inoremap pumvisible() ? "\\" : "\\"' diff --git a/lua/lv-utils/init.lua b/lua/lv-utils/init.lua index bc2b51b7..f26324b2 100644 --- a/lua/lv-utils/init.lua +++ b/lua/lv-utils/init.lua @@ -21,6 +21,32 @@ function lv_utils.check_lsp_client_active(name) return false end +function lv_utils.add_keymap(mode, opts, keymaps) + for _, keymap in ipairs(keymaps) do + vim.api.nvim_set_keymap(mode, keymap[1], keymap[2], opts) + end +end + +function lv_utils.add_keymap_normal_mode(opts, keymaps) + lv_utils.add_keymap("n", opts, keymaps) +end + +function lv_utils.add_keymap_visual_mode(opts, keymaps) + lv_utils.add_keymap("v", opts, keymaps) +end + +function lv_utils.add_keymap_visual_block_mode(opts, keymaps) + lv_utils.add_keymap("x", opts, keymaps) +end + +function lv_utils.add_keymap_insert_mode(opts, keymaps) + lv_utils.add_keymap("i", opts, keymaps) +end + +function lv_utils.add_keymap_term_mode(opts, keymaps) + lv_utils.add_keymap("t", opts, keymaps) +end + function lv_utils.define_augroups(definitions) -- {{{1 -- Create autocommand groups based on the passed definitions -- diff --git a/lua/settings.lua b/lua/settings.lua index 3ac94476..aa2bdd8d 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -28,12 +28,6 @@ end opt.shortmess:append "c" -if O.leader_key == " " or O.leader_key == "space" then - vim.g.mapleader = " " -else - vim.g.mapleader = O.leader_key -end - for _, plugin in pairs(O.disabled_built_ins) do vim.g["loaded_" .. plugin] = 1 end diff --git a/utils/installer/lv-config.example-no-ts.lua b/utils/installer/lv-config.example-no-ts.lua index ab544a35..d52c61bc 100644 --- a/utils/installer/lv-config.example-no-ts.lua +++ b/utils/installer/lv-config.example-no-ts.lua @@ -16,7 +16,25 @@ O.completion.autocomplete = true O.colorscheme = "spacegray" O.default_options.wrap = true O.default_options.timeoutlen = 100 -O.leader_key = " " +-- keymappings +O.keys.leader_key = "space" +-- overwrite the key-mappings provided by LunarVim for any mode, or leave it empty to keep them +-- O.keys.normal_mode = { +-- Page down/up +-- {'[d', ''}, +-- {']d', ''}, +-- +-- Navigate buffers +-- {'', ':bnext'}, +-- {'', ':bprevious'}, +-- } +-- if you just want to augment the existing ones then use the utility function +-- require("lv-utils").add_keymap_insert_mode({ silent = true }, { +-- { "", ":w" }, +-- { "", "" }, +-- }) +-- you can also use the native vim way directly +-- vim.api.nvim_set_keymap("i", "", "compe#complete()", { noremap = true, silent = true, expr = true }) -- TODO: User Config for predefined plugins -- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile diff --git a/utils/installer/lv-config.example.lua b/utils/installer/lv-config.example.lua index 1ca556b2..0e1a4a26 100644 --- a/utils/installer/lv-config.example.lua +++ b/utils/installer/lv-config.example.lua @@ -16,7 +16,25 @@ O.completion.autocomplete = true O.colorscheme = "spacegray" O.default_options.wrap = true O.default_options.timeoutlen = 100 -O.leader_key = " " +-- keymappings +O.keys.leader_key = "space" +-- overwrite the key-mappings provided by LunarVim for any mode, or leave it empty to keep them +-- O.keys.normal_mode = { +-- Page down/up +-- {'[d', ''}, +-- {']d', ''}, +-- +-- Navigate buffers +-- {'', ':bnext'}, +-- {'', ':bprevious'}, +-- } +-- if you just want to augment the existing ones then use the utility function +-- require("lv-utils").add_keymap_insert_mode({ silent = true }, { +-- { "", ":w" }, +-- { "", "" }, +-- }) +-- you can also use the native vim way directly +-- vim.api.nvim_set_keymap("i", "", "compe#complete()", { noremap = true, silent = true, expr = true }) -- TODO: User Config for predefined plugins -- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile From 176417d1dc0cf3a50ee089f63b4316988072d903 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 18 Jul 2021 17:50:17 +0000 Subject: [PATCH 07/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 99440bff..29f4e75e 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,8 @@ you can run the script with `--overwrite` but be warned this will remove the fol - `~/.local/share/nvim/site/pack/packer` ```bash curl -s https://raw.githubusercontent.com/ChristianChiarulli/lunarvim/rolling/utils/installer/install.sh | LVBRANCH=rolling bash -s -- --overwrite -# then run nvim and wait for treesitter to finish the installation ``` +then run nvim and wait for treesitter to finish the installation ## Installing LSP for your language From 1ebdb38d7c8bf795621cc447be92e007e058e6ed Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 18 Jul 2021 17:52:12 +0000 Subject: [PATCH 08/12] fix keymappings issue --- lua/keymappings.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/keymappings.lua b/lua/keymappings.lua index 03a1618c..16c91b3e 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -83,10 +83,10 @@ local default_keys = { if vim.fn.has "mac" == 1 then -- TODO: fix this - default_keys.insert_mode["n"][5][1] = "" - default_keys.insert_mode["n"][6][1] = "" - default_keys.insert_mode["n"][7][1] = "" - default_keys.insert_mode["n"][8][1] = "" + default_keys.normal_mode[5][1] = "" + default_keys.normal_mode[6][1] = "" + default_keys.normal_mode[7][1] = "" + default_keys.normal_mode[8][1] = "" end if O.keys.leader_key == " " or O.keys.leader_key == "space" then From 0e8f69f339156fd8ccd2ae85de95637859b3da76 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 18 Jul 2021 22:26:31 +0430 Subject: [PATCH 09/12] [Feature] Add swift support (#1002) --- ftplugin/swift.lua | 4 ++++ lua/default-config.lua | 3 ++- lua/lang/swift.lua | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 ftplugin/swift.lua create mode 100644 lua/lang/swift.lua diff --git a/ftplugin/swift.lua b/ftplugin/swift.lua new file mode 100644 index 00000000..64d87e1c --- /dev/null +++ b/ftplugin/swift.lua @@ -0,0 +1,4 @@ +require("lang.swift").format() +require("lang.swift").lint() +require("lang.swift").lsp() +require("lang.swift").dap() diff --git a/lua/default-config.lua b/lua/default-config.lua index 95549b53..3246787a 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -181,9 +181,10 @@ require("lang.php").config() require("lang.python").config() require("lang.ruby").config() require("lang.rust").config() -require("lang.scala").config() require("lang.sh").config() +require("lang.scala").config() require("lang.svelte").config() +require("lang.swift").config() require("lang.terraform").config() require("lang.tex").config() require("lang.vim").config() diff --git a/lua/lang/swift.lua b/lua/lang/swift.lua new file mode 100644 index 00000000..69254caa --- /dev/null +++ b/lua/lang/swift.lua @@ -0,0 +1,52 @@ +local M = {} + +M.config = function() + O.lang.swift = { + formatter = { + exe = "swiftformat", + args = {}, + stdin = true, + }, + } +end + +M.format = function() + -- TODO: implement formatter (if applicable) + return "No formatter configured!" +end + +M.lint = function() + O.formatters.filetype["swift"] = { + function() + return { + exe = O.lang.swift.formatter.exe, + args = O.lang.swift.formatter.args, + stdin = O.lang.swift.formatter.stdin, + } + end, + } + + require("formatter.config").set_defaults { + logging = false, + filetype = O.formatters.filetype, + } +end + +M.lsp = function() + if require("lv-utils").check_lsp_client_active "sourcekit" then + return + end + + require("lspconfig").sourcekit.setup { + cmd = { "xcrun", "sourcekit-lsp" }, + on_attach = require("lsp").common_on_attach, + filetypes = { "swift" }, + } +end + +M.dap = function() + -- TODO: implement dap + return "No DAP configured!" +end + +return M From 113f69c447dd09bf3b99732c6e8a957df0cf6c82 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 18 Jul 2021 22:26:51 +0430 Subject: [PATCH 10/12] [Feature] Add R support (#965) --- ftplugin/r.lua | 4 +++ ftplugin/rmd.lua | 1 + lua/default-config.lua | 1 + lua/lang/r.lua | 56 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 ftplugin/r.lua create mode 120000 ftplugin/rmd.lua create mode 100644 lua/lang/r.lua diff --git a/ftplugin/r.lua b/ftplugin/r.lua new file mode 100644 index 00000000..6de40bda --- /dev/null +++ b/ftplugin/r.lua @@ -0,0 +1,4 @@ +require("lang.r").format() +require("lang.r").lint() +require("lang.r").lsp() +require("lang.r").dap() diff --git a/ftplugin/rmd.lua b/ftplugin/rmd.lua new file mode 120000 index 00000000..401cef17 --- /dev/null +++ b/ftplugin/rmd.lua @@ -0,0 +1 @@ +r.lua \ No newline at end of file diff --git a/lua/default-config.lua b/lua/default-config.lua index 3246787a..70c5f070 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -179,6 +179,7 @@ require("lang.kotlin").config() require("lang.lua").config() require("lang.php").config() require("lang.python").config() +require("lang.r").config() require("lang.ruby").config() require("lang.rust").config() require("lang.sh").config() diff --git a/lua/lang/r.lua b/lua/lang/r.lua new file mode 100644 index 00000000..b05e6ee6 --- /dev/null +++ b/lua/lang/r.lua @@ -0,0 +1,56 @@ +local M = {} + +M.config = function() + -- R -e 'install.packages("formatR",repos = "http://cran.us.r-project.org")' + -- R -e 'install.packages("readr",repos = "http://cran.us.r-project.org")' + O.lang.r = { + formatter = { + exe = "R", + args = { + "--slave", + "--no-restore", + "--no-save", + '-e "formatR::tidy_source(text=readr::read_file(file(\\"stdin\\")), arrow=FALSE)"', + }, + stdin = true, + }, + } +end + +M.format = function() + O.formatters.filetype["r"] = { + function() + return { + exe = O.lang.r.formatter.exe, + args = O.lang.r.formatter.args, + stdin = O.lang.r.formatter.stdin, + } + end, + } + O.formatters.filetype["rmd"] = O.formatters.filetype["r"] + + require("formatter.config").set_defaults { + logging = false, + filetype = O.formatters.filetype, + } +end + +M.lint = function() + -- TODO: implement linters (if applicable) + return "No linters configured!" +end + +M.lsp = function() + if require("lv-utils").check_lsp_client_active "r_language_server" then + return + end + -- R -e 'install.packages("languageserver",repos = "http://cran.us.r-project.org")' + require("lspconfig").r_language_server.setup {} +end + +M.dap = function() + -- TODO: implement dap + return "No DAP configured!" +end + +return M From 56f17cebd4520e37c4c8a96e96e008bb5870178b Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 18 Jul 2021 22:27:05 +0430 Subject: [PATCH 11/12] [Feature] Allow users to inspect all settings inside LV (#984) --- README.md | 8 +++++++ lua/lv-utils/init.lua | 56 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/README.md b/README.md index 29f4e75e..8edae597 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,14 @@ O.lang.python.analysis.use_library_code_types = true -- vim.cmd('source ' .. CONFIG_PATH .. '/lua/lv-user/init.vim') ``` +In case you want to see all the settings inside LunarVim, run the following: + +```bash +cd ~/.config/nvim +nvim --headless +'lua require("lv-utils").generate_settings()' +qa && sort -o lv-settings.lua{,} +``` +and then inspect `~/.config/nvim/lv-settings.lua` file + ## Updating LunarVim In order to update you should be aware of three things `Plugins`, `LunarVim` and `Neovim` diff --git a/lua/lv-utils/init.lua b/lua/lv-utils/init.lua index f26324b2..c88c106d 100644 --- a/lua/lv-utils/init.lua +++ b/lua/lv-utils/init.lua @@ -1,5 +1,61 @@ local lv_utils = {} +-- recursive Print (structure, limit, separator) +local function r_inspect_settings(structure, limit, separator) + limit = limit or 100 -- default item limit + separator = separator or "." -- indent string + if limit < 1 then + print "ERROR: Item limit reached." + return limit - 1 + end + if structure == nil then + io.write("-- O", separator:sub(2), " = nil\n") + return limit - 1 + end + local ts = type(structure) + + if ts == "table" then + for k, v in pairs(structure) do + -- replace non alpha keys wih ["key"] + if tostring(k):match "[^%a_]" then + k = '["' .. tostring(k) .. '"]' + end + limit = r_inspect_settings(v, limit, separator .. "." .. tostring(k)) + if limit < 0 then + break + end + end + return limit + end + + if ts == "string" then + -- escape sequences + structure = string.format("%q", structure) + end + separator = separator:gsub("%.%[", "%[") + if type(structure) == "function" then + -- don't print functions + io.write("-- O", separator:sub(2), " = function ()\n") + else + io.write("O", separator:sub(2), " = ", tostring(structure), "\n") + end + return limit - 1 +end + +function lv_utils.generate_settings() + -- Opens a file in append mode + local file = io.open("lv-settings.lua", "w") + + -- sets the default output file as test.lua + io.output(file) + + -- write all `O` related settings to `lv-settings.lua` file + r_inspect_settings(O, 10000, ".") + + -- closes the open file + io.close(file) +end + function lv_utils.reload_lv_config() vim.cmd "source ~/.config/nvim/lua/keymappings.lua" vim.cmd "source ~/.config/nvim/lv-config.lua" From 6f9c521e227b1c4d3741cb73ee0a9598be73ef10 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Sun, 18 Jul 2021 20:08:14 +0200 Subject: [PATCH 12/12] Split plugin loading logic from the configuration (#796) --- init.lua | 7 +- lua/plugin-loader.lua | 46 +++++++++++++ lua/plugins.lua | 152 +++++++++++++++++------------------------- 3 files changed, 113 insertions(+), 92 deletions(-) create mode 100644 lua/plugin-loader.lua diff --git a/init.lua b/init.lua index b159b0ed..6a09c909 100644 --- a/init.lua +++ b/init.lua @@ -4,9 +4,14 @@ if not status_ok then print "something is wrong with your lv-config" print(error) end + require "keymappings" -require "plugins" + +local plugins = require "plugins" +local plugin_loader = require("plugin-loader").init() +plugin_loader:load { plugins, O.user_plugins } vim.g.colors_name = O.colorscheme -- Colorscheme must get called after plugins are loaded or it will break new installs. + require "settings" require "lv-utils" diff --git a/lua/plugin-loader.lua b/lua/plugin-loader.lua new file mode 100644 index 00000000..25a41111 --- /dev/null +++ b/lua/plugin-loader.lua @@ -0,0 +1,46 @@ +local plugin_loader = {} + +function plugin_loader:init() + local execute = vim.api.nvim_command + local fn = vim.fn + + local install_path = fn.stdpath "data" .. "/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" + end + + local packer_ok, packer = pcall(require, "packer") + if not packer_ok then + return + end + + packer.init { + -- package_root = require("packer.util").join_paths(vim.fn.stdpath "data", "lvim", "pack"), + git = { clone_timeout = 300 }, + display = { + open_fn = function() + return require("packer.util").float { border = "single" } + end, + }, + } + + self.packer = packer + return self +end + +function plugin_loader:load(configurations) + return self.packer.startup(function(use) + for _, plugins in ipairs(configurations) do + for _, plugin in ipairs(plugins) do + use(plugin) + end + end + end) +end + +return { + init = function() + return plugin_loader:init() + end, +} diff --git a/lua/plugins.lua b/lua/plugins.lua index 2f1ad333..f880cc1f 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,101 +1,76 @@ -local execute = vim.api.nvim_command -local fn = vim.fn - -local install_path = fn.stdpath "data" .. "/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" -end - -local packer_ok, packer = pcall(require, "packer") -if not packer_ok then - return -end - -packer.init { - -- package_root = require("packer.util").join_paths(vim.fn.stdpath "data", "lvim", "pack"), - git = { clone_timeout = 300 }, - display = { - open_fn = function() - return require("packer.util").float { border = "single" } - end, - }, -} - -return require("packer").startup(function(use) +return { -- Packer can manage itself as an optional plugin - use "wbthomason/packer.nvim" + { "wbthomason/packer.nvim" }, -- TODO: refactor all of this (for now it works, but yes I know it could be wrapped in a simpler function) - use { "neovim/nvim-lspconfig" } - use { + { "neovim/nvim-lspconfig" }, + { "kabouzeid/nvim-lspinstall", event = "VimEnter", config = function() require("lspinstall").setup() end, - } + }, - use { "nvim-lua/popup.nvim" } - use { "nvim-lua/plenary.nvim" } - use { "tjdevries/astronauta.nvim" } + { "nvim-lua/popup.nvim" }, + { "nvim-lua/plenary.nvim" }, + { "tjdevries/astronauta.nvim" }, -- Telescope - use { + { "nvim-telescope/telescope.nvim", config = [[require('core.telescope').setup()]], - } + }, -- Autocomplete - use { + { "hrsh7th/nvim-compe", -- event = "InsertEnter", config = function() require("core.compe").setup() end, - } + }, -- Autopairs - use { + { "windwp/nvim-autopairs", -- event = "InsertEnter", config = function() require "core.autopairs" end, - } + }, -- Snippets - use { "hrsh7th/vim-vsnip", event = "InsertEnter" } - use { "rafamadriz/friendly-snippets", event = "InsertEnter" } + { "hrsh7th/vim-vsnip", event = "InsertEnter" }, + { "rafamadriz/friendly-snippets", event = "InsertEnter" }, -- Treesitter - use { + { "nvim-treesitter/nvim-treesitter", config = function() require("core.treesitter").setup() end, - } + }, -- Formatter.nvim - use { + { "mhartington/formatter.nvim", config = function() require "core.formatter" end, - } + }, -- Linter - use { + { "mfussenegger/nvim-lint", config = function() require("core.linter").setup() end, - } + }, -- NvimTree - use { + { "kyazdani42/nvim-tree.lua", -- event = "BufWinOpen", -- cmd = "NvimTreeToggle", @@ -103,28 +78,28 @@ return require("packer").startup(function(use) config = function() require("core.nvimtree").setup() end, - } + }, - use { + { "lewis6991/gitsigns.nvim", config = function() require("core.gitsigns").setup() end, event = "BufRead", - } + }, -- whichkey - use { + { "folke/which-key.nvim", config = function() require("core.which-key").setup() end, event = "BufWinEnter", - } + }, -- Comments - use { + { "terrortylor/nvim-comment", event = "BufRead", config = function() @@ -134,89 +109,89 @@ return require("packer").startup(function(use) end nvim_comment.setup() end, - } + }, -- vim-rooter - use { + { "airblade/vim-rooter", config = function() vim.g.rooter_silent_chdir = 1 end, - } + }, -- Icons - use { "kyazdani42/nvim-web-devicons" } + { "kyazdani42/nvim-web-devicons" }, -- Status Line and Bufferline - use { + { "glepnir/galaxyline.nvim", config = function() require "core.galaxyline" end, event = "BufWinEnter", disable = not O.plugin.galaxyline.active, - } + }, - use { + { "romgrk/barbar.nvim", config = function() require "core.bufferline" end, event = "BufWinEnter", - } + }, -- Debugging - use { + { "mfussenegger/nvim-dap", -- event = "BufWinEnter", config = function() require("core.dap").setup() end, disable = not O.plugin.dap.active, - } + }, -- Debugger management - use { + { "Pocco81/DAPInstall.nvim", -- event = "BufWinEnter", -- event = "BufRead", disable = not O.plugin.dap.active, - } + }, -- Builtins, these do not load by default -- Dashboard - use { + { "ChristianChiarulli/dashboard-nvim", event = "BufWinEnter", config = function() require("core.dashboard").setup() end, disable = not O.plugin.dashboard.active, - } + }, -- TODO: remove in favor of akinsho/nvim-toggleterm.lua -- Floating terminal - -- use { + -- { -- "numToStr/FTerm.nvim", -- event = "BufWinEnter", -- config = function() -- require("core.floatterm").setup() -- end, -- disable = not O.plugin.floatterm.active, - -- } + -- }, - use { + { "akinsho/nvim-toggleterm.lua", event = "BufWinEnter", config = function() require("core.terminal").setup() end, disable = not O.plugin.terminal.active, - } + }, -- Zen Mode - use { + { "folke/zen-mode.nvim", cmd = "ZenMode", event = "BufRead", @@ -224,28 +199,28 @@ return require("packer").startup(function(use) require("core.zen").setup() end, disable = not O.plugin.zen.active, - } + }, --------------------------------------------------------------------------------- -- LANGUAGE SPECIFIC GOES HERE - use { + { "lervag/vimtex", ft = "tex", - } + }, -- Rust tools -- TODO: use lazy loading maybe? - use { + { "simrat39/rust-tools.nvim", disable = not O.lang.rust.rust_tools.active, - } + }, -- Elixir - use { "elixir-editors/vim-elixir", ft = { "elixir", "eelixir", "euphoria3" } } + { "elixir-editors/vim-elixir", ft = { "elixir", "eelixir", "euphoria3" } }, -- Javascript / Typescript - use { + { "jose-elias-alvarez/nvim-lsp-ts-utils", ft = { "javascript", @@ -255,23 +230,18 @@ return require("packer").startup(function(use) "typescriptreact", "typescript.tsx", }, - } + }, -- Java - use { + { "mfussenegger/nvim-jdtls", -- ft = { "java" }, disable = not O.lang.java.java_tools.active, - } + }, -- Scala - use { + { "scalameta/nvim-metals", disable = not O.lang.scala.metals.active, - } - - -- Install user plugins - for _, plugin in pairs(O.user_plugins) do - packer.use(plugin) - end -end) + }, +}