summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkylo252 <[email protected]>2021-10-03 16:13:46 +0200
committerGitHub <[email protected]>2021-10-03 16:13:46 +0200
commitd01ba08eaec1640ac2d038893525b3ba0af25813 (patch)
tree5edf2f5a12cedacb32f0c5d45ec2d999dacb99cd
parent3e1cd1ec235404ae96ed2d0756729cf44ae48f3e (diff)
refactor: auto-generate language configuration (#1584)
Refactor the monolithic `lvim.lang` design into a more modular approach. IMPORTANT: run `:LvimUpdate` in order to generate the new ftplugin template files.
-rw-r--r--ftplugin/asm.lua1
-rw-r--r--ftplugin/beancount.lua1
-rw-r--r--ftplugin/bicep.lua1
-rw-r--r--ftplugin/c.lua4
-rw-r--r--ftplugin/clojure.lua1
-rw-r--r--ftplugin/cmake.lua1
-rw-r--r--ftplugin/cpp.lua1
-rw-r--r--ftplugin/crystal.lua1
-rw-r--r--ftplugin/cs.lua1
-rw-r--r--ftplugin/css.lua1
-rw-r--r--ftplugin/d.lua1
-rw-r--r--ftplugin/dart.lua1
-rw-r--r--ftplugin/dockerfile.lua1
-rw-r--r--ftplugin/elixir.lua10
-rw-r--r--ftplugin/elm.lua1
-rw-r--r--ftplugin/erlang.lua1
-rw-r--r--ftplugin/euphoria3.lua9
-rw-r--r--ftplugin/fish.lua1
-rw-r--r--ftplugin/fortran.lua1
-rw-r--r--ftplugin/gdscript.lua1
-rw-r--r--ftplugin/go.lua1
-rw-r--r--ftplugin/graphql.lua1
-rw-r--r--ftplugin/haskell.lua1
-rw-r--r--ftplugin/html.lua2
-rw-r--r--ftplugin/java.lua1
-rw-r--r--ftplugin/javascript.lua1
-rw-r--r--ftplugin/javascriptreact.lua2
-rw-r--r--ftplugin/json.lua1
-rw-r--r--ftplugin/julia.lua1
-rw-r--r--ftplugin/kotlin.lua1
l---------ftplugin/less.lua1
-rw-r--r--ftplugin/lua.lua1
-rw-r--r--ftplugin/netrw.lua2
-rw-r--r--ftplugin/nix.lua1
-rw-r--r--ftplugin/perl.lua1
-rw-r--r--ftplugin/php.lua1
-rw-r--r--ftplugin/ps1.lua3
-rw-r--r--ftplugin/puppet.lua1
-rw-r--r--ftplugin/python.lua3
-rw-r--r--ftplugin/r.lua2
l---------ftplugin/rmd.lua1
-rw-r--r--ftplugin/ruby.lua2
-rw-r--r--ftplugin/rust.lua4
l---------ftplugin/sass.lua1
l---------ftplugin/sbt.lua1
-rw-r--r--ftplugin/scala.lua1
l---------ftplugin/scss.lua1
-rw-r--r--ftplugin/sh.lua1
-rw-r--r--ftplugin/solidity.lua1
-rw-r--r--ftplugin/sql.lua1
-rw-r--r--ftplugin/svelte.lua2
-rw-r--r--ftplugin/swift.lua1
-rw-r--r--ftplugin/terraform.lua1
-rw-r--r--ftplugin/tex.lua1
-rw-r--r--ftplugin/thing.pp0
-rw-r--r--ftplugin/toml.lua1
-rw-r--r--ftplugin/typescript.lua1
-rw-r--r--ftplugin/typescriptreact.lua2
-rw-r--r--ftplugin/vim.lua1
-rw-r--r--ftplugin/vue.lua2
-rw-r--r--ftplugin/yaml.lua1
-rw-r--r--ftplugin/zig.lua1
-rw-r--r--ftplugin/zsh.lua1
-rw-r--r--init.lua5
-rw-r--r--lua/bootstrap.lua4
-rw-r--r--lua/config/defaults.lua1164
-rw-r--r--lua/config/init.lua100
-rw-r--r--lua/core/builtins/init.lua1
-rw-r--r--lua/core/cmp.lua30
-rw-r--r--lua/core/info.lua87
-rw-r--r--lua/core/log.lua1
-rw-r--r--lua/core/lspinstall.lua19
-rw-r--r--lua/core/lualine/components.lua3
-rw-r--r--lua/core/which-key.lua2
-rw-r--r--lua/lsp/config.lua27
-rw-r--r--lua/lsp/init.lua102
-rw-r--r--lua/lsp/kind.lua31
-rw-r--r--lua/lsp/manager.lua82
-rw-r--r--lua/lsp/null-ls/formatters.lua30
-rw-r--r--lua/lsp/null-ls/init.lua54
-rw-r--r--lua/lsp/null-ls/linters.lua30
-rw-r--r--lua/lsp/null-ls/services.lua15
-rw-r--r--lua/lsp/providers/jsonls.lua30
-rw-r--r--lua/lsp/providers/sumneko_lua.lua19
-rw-r--r--lua/lsp/providers/vuels.lua26
-rw-r--r--lua/lsp/templates.lua98
-rw-r--r--lua/lsp/utils.lua57
-rw-r--r--lua/plugins.lua7
-rw-r--r--lua/utils/init.lua100
-rw-r--r--tests/bootstrap_spec.lua13
-rw-r--r--tests/lsp_spec.lua98
-rw-r--r--tests/minimal_init.lua9
-rw-r--r--tests/plugins_load_spec.lua34
-rw-r--r--utils/bin/lvim.ps19
-rw-r--r--utils/bin/test_runner.sh4
-rw-r--r--utils/installer/config.example.lua15
-rw-r--r--utils/installer/install.ps1280
-rw-r--r--utils/installer/uninstall.ps11
98 files changed, 1122 insertions, 1562 deletions
diff --git a/ftplugin/asm.lua b/ftplugin/asm.lua
deleted file mode 100644
index 4f135295..00000000
--- a/ftplugin/asm.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "asm"
diff --git a/ftplugin/beancount.lua b/ftplugin/beancount.lua
deleted file mode 100644
index ac8aff33..00000000
--- a/ftplugin/beancount.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "beancount"
diff --git a/ftplugin/bicep.lua b/ftplugin/bicep.lua
deleted file mode 100644
index 8ed9ca23..00000000
--- a/ftplugin/bicep.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "bicep"
diff --git a/ftplugin/c.lua b/ftplugin/c.lua
deleted file mode 100644
index 3f931e4a..00000000
--- a/ftplugin/c.lua
+++ /dev/null
@@ -1,4 +0,0 @@
-require("lsp").setup "c"
-
--- TODO get from dap
--- require("lang.c").dap()
diff --git a/ftplugin/clojure.lua b/ftplugin/clojure.lua
deleted file mode 100644
index 683720a5..00000000
--- a/ftplugin/clojure.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "clojure"
diff --git a/ftplugin/cmake.lua b/ftplugin/cmake.lua
deleted file mode 100644
index 56d30106..00000000
--- a/ftplugin/cmake.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "cmake"
diff --git a/ftplugin/cpp.lua b/ftplugin/cpp.lua
deleted file mode 100644
index 6028ea49..00000000
--- a/ftplugin/cpp.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "cpp"
diff --git a/ftplugin/crystal.lua b/ftplugin/crystal.lua
deleted file mode 100644
index 38605db8..00000000
--- a/ftplugin/crystal.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "crystal"
diff --git a/ftplugin/cs.lua b/ftplugin/cs.lua
deleted file mode 100644
index 6c349494..00000000
--- a/ftplugin/cs.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "cs"
diff --git a/ftplugin/css.lua b/ftplugin/css.lua
deleted file mode 100644
index 094ed2a3..00000000
--- a/ftplugin/css.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "css"
diff --git a/ftplugin/d.lua b/ftplugin/d.lua
deleted file mode 100644
index 41a6433b..00000000
--- a/ftplugin/d.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "d"
diff --git a/ftplugin/dart.lua b/ftplugin/dart.lua
deleted file mode 100644
index 9f0ccfa0..00000000
--- a/ftplugin/dart.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "dart"
diff --git a/ftplugin/dockerfile.lua b/ftplugin/dockerfile.lua
deleted file mode 100644
index 98fa7101..00000000
--- a/ftplugin/dockerfile.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "dockerfile"
diff --git a/ftplugin/elixir.lua b/ftplugin/elixir.lua
deleted file mode 100644
index 2d4c90e2..00000000
--- a/ftplugin/elixir.lua
+++ /dev/null
@@ -1,10 +0,0 @@
-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)
--- vim.cmd [[
--- au BufRead,BufNewFile *.ex,*.exs set filetype=elixir
--- au BufRead,BufNewFile *.eex,*.leex,*.sface set filetype=eelixir
--- au BufRead,BufNewFile mix.lock set filetype=elixir
--- ]]
diff --git a/ftplugin/elm.lua b/ftplugin/elm.lua
deleted file mode 100644
index 38fda314..00000000
--- a/ftplugin/elm.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "elm"
diff --git a/ftplugin/erlang.lua b/ftplugin/erlang.lua
deleted file mode 100644
index c6426dba..00000000
--- a/ftplugin/erlang.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "erlang"
diff --git a/ftplugin/euphoria3.lua b/ftplugin/euphoria3.lua
deleted file mode 100644
index 168af22b..00000000
--- a/ftplugin/euphoria3.lua
+++ /dev/null
@@ -1,9 +0,0 @@
-require("lsp").setup "erlang"
-
--- TODO: do we need this?
--- needed for the LSP to recognize elixir files (alternatively just use elixir-editors/vim-elixir)
--- vim.cmd [[
--- au BufRead,BufNewFile *.ex,*.exs set filetype=elixir
--- au BufRead,BufNewFile *.eex,*.leex,*.sface set filetype=eelixir
--- au BufRead,BufNewFile mix.lock set filetype=elixir
--- ]]
diff --git a/ftplugin/fish.lua b/ftplugin/fish.lua
deleted file mode 100644
index 575ec434..00000000
--- a/ftplugin/fish.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "fish"
diff --git a/ftplugin/fortran.lua b/ftplugin/fortran.lua
deleted file mode 100644
index 36f4f484..00000000
--- a/ftplugin/fortran.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "fortran"
diff --git a/ftplugin/gdscript.lua b/ftplugin/gdscript.lua
deleted file mode 100644
index b23a20e2..00000000
--- a/ftplugin/gdscript.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "gdscript"
diff --git a/ftplugin/go.lua b/ftplugin/go.lua
deleted file mode 100644
index 218b634c..00000000
--- a/ftplugin/go.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "go"
diff --git a/ftplugin/graphql.lua b/ftplugin/graphql.lua
deleted file mode 100644
index 83e8878d..00000000
--- a/ftplugin/graphql.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "graphql"
diff --git a/ftplugin/haskell.lua b/ftplugin/haskell.lua
deleted file mode 100644
index 374bed1a..00000000
--- a/ftplugin/haskell.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "haskell"
diff --git a/ftplugin/html.lua b/ftplugin/html.lua
deleted file mode 100644
index c85374dd..00000000
--- a/ftplugin/html.lua
+++ /dev/null
@@ -1,2 +0,0 @@
-require("lsp").setup "html"
-require("lsp").setup "tailwindcss"
diff --git a/ftplugin/java.lua b/ftplugin/java.lua
deleted file mode 100644
index dcb46ca2..00000000
--- a/ftplugin/java.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "java"
diff --git a/ftplugin/javascript.lua b/ftplugin/javascript.lua
deleted file mode 100644
index 37b95c71..00000000
--- a/ftplugin/javascript.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "javascript"
diff --git a/ftplugin/javascriptreact.lua b/ftplugin/javascriptreact.lua
deleted file mode 100644
index 370b09ba..00000000
--- a/ftplugin/javascriptreact.lua
+++ /dev/null
@@ -1,2 +0,0 @@
-require("lsp").setup "javascriptreact"
-require("lsp").setup "tailwindcss"
diff --git a/ftplugin/json.lua b/ftplugin/json.lua
deleted file mode 100644
index 18368cf9..00000000
--- a/ftplugin/json.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "json"
diff --git a/ftplugin/julia.lua b/ftplugin/julia.lua
deleted file mode 100644
index 9840be1f..00000000
--- a/ftplugin/julia.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "julia"
diff --git a/ftplugin/kotlin.lua b/ftplugin/kotlin.lua
deleted file mode 100644
index a0e6d5d6..00000000
--- a/ftplugin/kotlin.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "kotlin"
diff --git a/ftplugin/less.lua b/ftplugin/less.lua
deleted file mode 120000
index 6b9e5a8d..00000000
--- a/ftplugin/less.lua
+++ /dev/null
@@ -1 +0,0 @@
-css.lua \ No newline at end of file
diff --git a/ftplugin/lua.lua b/ftplugin/lua.lua
deleted file mode 100644
index 2ed88315..00000000
--- a/ftplugin/lua.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "lua"
diff --git a/ftplugin/netrw.lua b/ftplugin/netrw.lua
deleted file mode 100644
index b2292870..00000000
--- a/ftplugin/netrw.lua
+++ /dev/null
@@ -1,2 +0,0 @@
-vim.cmd [[nmap <buffer> h -]]
-vim.cmd [[nmap <buffer> l <cr>]]
diff --git a/ftplugin/nix.lua b/ftplugin/nix.lua
deleted file mode 100644
index 41152a75..00000000
--- a/ftplugin/nix.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "nix"
diff --git a/ftplugin/perl.lua b/ftplugin/perl.lua
deleted file mode 100644
index f1d3b772..00000000
--- a/ftplugin/perl.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "perl"
diff --git a/ftplugin/php.lua b/ftplugin/php.lua
deleted file mode 100644
index 4eabcf71..00000000
--- a/ftplugin/php.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "php"
diff --git a/ftplugin/ps1.lua b/ftplugin/ps1.lua
deleted file mode 100644
index 6d388496..00000000
--- a/ftplugin/ps1.lua
+++ /dev/null
@@ -1,3 +0,0 @@
-require("lsp").setup "ps1"
-
-vim.cmd [[setlocal ts=4 sw=4]]
diff --git a/ftplugin/puppet.lua b/ftplugin/puppet.lua
deleted file mode 100644
index f8521762..00000000
--- a/ftplugin/puppet.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "puppet"
diff --git a/ftplugin/python.lua b/ftplugin/python.lua
deleted file mode 100644
index 3e79e6bc..00000000
--- a/ftplugin/python.lua
+++ /dev/null
@@ -1,3 +0,0 @@
-require("lsp").setup "python"
--- TODO get from dap
--- require("lang.python").dap()
diff --git a/ftplugin/r.lua b/ftplugin/r.lua
deleted file mode 100644
index 296d3c86..00000000
--- a/ftplugin/r.lua
+++ /dev/null
@@ -1,2 +0,0 @@
--- R -e 'install.packages("languageserver",repos = "http://cran.us.r-project.org")'
-require("lsp").setup "r"
diff --git a/ftplugin/rmd.lua b/ftplugin/rmd.lua
deleted file mode 120000
index 401cef17..00000000
--- a/ftplugin/rmd.lua
+++ /dev/null
@@ -1 +0,0 @@
-r.lua \ No newline at end of file
diff --git a/ftplugin/ruby.lua b/ftplugin/ruby.lua
deleted file mode 100644
index 7e968917..00000000
--- a/ftplugin/ruby.lua
+++ /dev/null
@@ -1,2 +0,0 @@
--- also support sorbet
-require("lsp").setup "ruby"
diff --git a/ftplugin/rust.lua b/ftplugin/rust.lua
deleted file mode 100644
index f1623f25..00000000
--- a/ftplugin/rust.lua
+++ /dev/null
@@ -1,4 +0,0 @@
-require("lsp").setup "rust"
-
--- TODO get from dap
--- require("lang.rust").dap()
diff --git a/ftplugin/sass.lua b/ftplugin/sass.lua
deleted file mode 120000
index 6b9e5a8d..00000000
--- a/ftplugin/sass.lua
+++ /dev/null
@@ -1 +0,0 @@
-css.lua \ No newline at end of file
diff --git a/ftplugin/sbt.lua b/ftplugin/sbt.lua
deleted file mode 120000
index d0d6ce5b..00000000
--- a/ftplugin/sbt.lua
+++ /dev/null
@@ -1 +0,0 @@
-scala.lua \ No newline at end of file
diff --git a/ftplugin/scala.lua b/ftplugin/scala.lua
deleted file mode 100644
index 169e36ad..00000000
--- a/ftplugin/scala.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "scala"
diff --git a/ftplugin/scss.lua b/ftplugin/scss.lua
deleted file mode 120000
index 6b9e5a8d..00000000
--- a/ftplugin/scss.lua
+++ /dev/null
@@ -1 +0,0 @@
-css.lua \ No newline at end of file
diff --git a/ftplugin/sh.lua b/ftplugin/sh.lua
deleted file mode 100644
index 4f18fbca..00000000
--- a/ftplugin/sh.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "sh"
diff --git a/ftplugin/solidity.lua b/ftplugin/solidity.lua
deleted file mode 100644
index 29144da7..00000000
--- a/ftplugin/solidity.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "solidity"
diff --git a/ftplugin/sql.lua b/ftplugin/sql.lua
deleted file mode 100644
index b4658023..00000000
--- a/ftplugin/sql.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "sql"
diff --git a/ftplugin/svelte.lua b/ftplugin/svelte.lua
deleted file mode 100644
index a8a8a8d1..00000000
--- a/ftplugin/svelte.lua
+++ /dev/null
@@ -1,2 +0,0 @@
-require("lsp").setup "svelte"
-require("lsp").setup "tailwindcss"
diff --git a/ftplugin/swift.lua b/ftplugin/swift.lua
deleted file mode 100644
index 1ae7554a..00000000
--- a/ftplugin/swift.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "swift"
diff --git a/ftplugin/terraform.lua b/ftplugin/terraform.lua
deleted file mode 100644
index 3486663d..00000000
--- a/ftplugin/terraform.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "terraform"
diff --git a/ftplugin/tex.lua b/ftplugin/tex.lua
deleted file mode 100644
index e9a98ec5..00000000
--- a/ftplugin/tex.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "tex"
diff --git a/ftplugin/thing.pp b/ftplugin/thing.pp
deleted file mode 100644
index e69de29b..00000000
--- a/ftplugin/thing.pp
+++ /dev/null
diff --git a/ftplugin/toml.lua b/ftplugin/toml.lua
deleted file mode 100644
index 701685a4..00000000
--- a/ftplugin/toml.lua
+++ /dev/null
@@ -1 +0,0 @@
-vim.cmd [[setlocal commentstring=#%s]]
diff --git a/ftplugin/typescript.lua b/ftplugin/typescript.lua
deleted file mode 100644
index 2f6219df..00000000
--- a/ftplugin/typescript.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "typescript"
diff --git a/ftplugin/typescriptreact.lua b/ftplugin/typescriptreact.lua
deleted file mode 100644
index 6c65ddc5..00000000
--- a/ftplugin/typescriptreact.lua
+++ /dev/null
@@ -1,2 +0,0 @@
-require("lsp").setup "typescript"
-require("lsp").setup "tailwindcss"
diff --git a/ftplugin/vim.lua b/ftplugin/vim.lua
deleted file mode 100644
index 88c00c1c..00000000
--- a/ftplugin/vim.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "vim"
diff --git a/ftplugin/vue.lua b/ftplugin/vue.lua
deleted file mode 100644
index b2a560d9..00000000
--- a/ftplugin/vue.lua
+++ /dev/null
@@ -1,2 +0,0 @@
-require("lsp").setup "vue"
-require("lsp").setup "tailwindcss"
diff --git a/ftplugin/yaml.lua b/ftplugin/yaml.lua
deleted file mode 100644
index d21f9785..00000000
--- a/ftplugin/yaml.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "yaml"
diff --git a/ftplugin/zig.lua b/ftplugin/zig.lua
deleted file mode 100644
index ef3d64d4..00000000
--- a/ftplugin/zig.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "zig"
diff --git a/ftplugin/zsh.lua b/ftplugin/zsh.lua
deleted file mode 100644
index 4f18fbca..00000000
--- a/ftplugin/zsh.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("lsp").setup "sh"
diff --git a/init.lua b/init.lua
index f0edfcc7..c4fa5d35 100644
--- a/init.lua
+++ b/init.lua
@@ -18,10 +18,9 @@ Log:debug "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)
-require("utils").toggle_autoformat()
local commands = require "core.commands"
commands.load(commands.defaults)
-require("lsp").global_setup()
-
require("keymappings").setup()
+
+require("lsp").setup()
diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua
index 7f8f97ed..fb2099ce 100644
--- a/lua/bootstrap.lua
+++ b/lua/bootstrap.lua
@@ -85,9 +85,10 @@ function M:init()
vim.cmd("set spellfile=" .. join_paths(self.config_dir, "spell", "en.utf-8.add"))
end
+ vim.fn.mkdir(vim.fn.stdpath "cache", "p")
+
-- FIXME: currently unreliable in unit-tests
if not os.getenv "LVIM_TEST_ENV" then
- vim.fn.mkdir(vim.fn.stdpath "cache", "p")
require("impatient").setup {
path = vim.fn.stdpath "cache" .. "/lvim_cache",
enable_profiling = true,
@@ -112,6 +113,7 @@ end
function M:update()
M:update_repo()
M:reset_cache()
+ require("lsp.templates").generate_templates()
vim.schedule(function()
-- TODO: add a changelog
vim.notify("Update complete", vim.log.levels.INFO)
diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua
index a67a9c53..f030234d 100644
--- a/lua/config/defaults.lua
+++ b/lua/config/defaults.lua
@@ -1,7 +1,5 @@
local home_dir = vim.loop.os_homedir()
local utils = require "utils"
--- FIXME: stop using hard-coded paths for LspInstall
-local ls_install_prefix = vim.fn.stdpath "data" .. "/lspinstall"
lvim = {
leader = "space",
@@ -30,1170 +28,10 @@ lvim = {
},
},
},
-
- lsp = {
- completion = {
- item_kind = {
- "  (Text) ",
- "  (Method)",
- "  (Function)",
- "  (Constructor)",
- "  (Field)",
- "  (Variable)",
- "  (Class)",
- " ﰮ (Interface)",
- "  (Module)",
- "  (Property)",
- " 塞 (Unit)",
- "  (Value)",
- " 練 (Enum)",
- "  (Keyword)",
- "  (Snippet)",
- "  (Color)",
- "  (File)",
- "  (Reference)",
- "  (Folder)",
- "  (EnumMember)",
- " ﲀ (Constant)",
- "  (Struct)",
- "  (Event)",
- "  (Operator)",
- "  (TypeParameter)",
- },
- },
- diagnostics = {
- signs = {
- active = true,
- values = {
- { name = "LspDiagnosticsSignError", text = "" },
- { name = "LspDiagnosticsSignWarning", text = "" },
- { name = "LspDiagnosticsSignHint", text = "" },
- { name = "LspDiagnosticsSignInformation", text = "" },
- },
- },
- virtual_text = {
- prefix = "",
- spacing = 0,
- },
- update_in_insert = false,
- underline = true,
- severity_sort = true,
- },
- override = {},
- document_highlight = true,
- popup_border = "single",
- on_attach_callback = nil,
- on_init_callback = nil,
- null_ls = {
- setup = {},
- },
- },
-
plugins = {
-- use config.lua for this not put here
},
autocommands = {},
-}
-
-local schemas = nil
-local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls")
-if status_ok then
- schemas = jsonls_settings.get_default_schemas()
-end
-
--- TODO move all of this into lang specific files, only require when using
-lvim.lang = {
- asm = {
- formatters = {
- -- {
- -- exe = "asmfmt",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "",
- setup = {},
- },
- },
- beancount = {
- formatters = {
- -- {
- -- exe = "bean_format",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "beancount",
- setup = {
- cmd = { "beancount-langserver" },
- },
- },
- },
- bicep = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "bicep",
- setup = {
- cmd = {
- "dotnet",
- ls_install_prefix .. "/bicep/Bicep.LangServer.dll",
- },
- filetypes = { "bicep" },
- },
- },
- },
- c = {
- formatters = {
- -- {
- -- exe = "clang_format",
- -- args = {},
- -- },
- -- {
- -- exe = "uncrustify",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "clangd",
- setup = {
- cmd = {
- ls_install_prefix .. "/cpp/clangd/bin/clangd",
- "--background-index",
- "--header-insertion=never",
- "--cross-file-rename",
- "--clang-tidy",
- "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*",
- },
- },
- },
- },
- cpp = {
- formatters = {
- -- {
- -- exe = "clang_format",
- -- args = {},
- -- },
- -- {
- -- exe = "uncrustify",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "clangd",
- setup = {
- cmd = {
- ls_install_prefix .. "/cpp/clangd/bin/clangd",
- "--background-index",
- "--header-insertion=never",
- "--cross-file-rename",
- "--clang-tidy",
- "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*",
- },
- },
- },
- },
- crystal = {
- formatters = {
- -- {
- -- exe = "crystal_format",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "crystalline",
- setup = {
- cmd = { "crystalline" },
- },
- },
- },
- cs = {
- formatters = {
- -- {
- -- exe = "clang_format ",
- -- args = {},
- -- },
- -- {
- -- exe = "uncrustify",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "omnisharp",
- setup = {
- cmd = {
- ls_install_prefix .. "/csharp/omnisharp/run",
- "--languageserver",
- "--hostPID",
- tostring(vim.fn.getpid()),
- },
- },
- },
- },
- cmake = {
- formatters = {
- -- {
- -- exe = "cmake_format",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "cmake",
- setup = {
- cmd = {
- ls_install_prefix .. "/cmake/venv/bin/cmake-language-server",
- },
- },
- },
- },
- clojure = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "clojure_lsp",
- setup = {
- cmd = {
- ls_install_prefix .. "/clojure/clojure-lsp",
- },
- },
- },
- },
- css = {
- formatters = {
- -- {
- -- exe = "prettier",
- -- args = {},
- -- },
- -- {
- -- exe = "prettierd",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "cssls",
- setup = {
- cmd = {
- "node",
- ls_install_prefix .. "/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js",
- "--stdio",
- },
- },
- },
- },
- less = {
- formatters = {
- -- {
- -- exe = "prettier",
- -- args = {},
- -- },
- -- {
- -- exe = "prettierd",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "cssls",
- setup = {
- cmd = {
- "node",
- ls_install_prefix .. "/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js",
- "--stdio",
- },
- },
- },
- },
- d = {
- formatters = {
- -- {
- -- exe = "dfmt",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "serve_d",
- setup = {
- cmd = { "serve-d" },
- },
- },
- },
- dart = {
- formatters = {
- -- {
- -- exe = "dart_format",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "dartls",
- setup = {
- cmd = {
- "dart",
- "/usr/lib/dart/bin/snapshots/analysis_server.dart.snapshot",
- "--lsp",
- },
- },
- },
- },
- dockerfile = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "dockerls",
- setup = {
- cmd = {
- ls_install_prefix .. "/dockerfile/node_modules/.bin/docker-langserver",
- "--stdio",
- },
- },
- },
- },
- elixir = {
- formatters = {
- -- {
- -- exe = "mix",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "elixirls",
- setup = {
- cmd = {
- ls_install_prefix .. "/elixir/elixir-ls/language_server.sh",
- },
- },
- },
- },
- elm = {
- formatters = {
- -- {
- -- exe = "elm_format",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "elmls",
- setup = {
- cmd = {
- ls_install_prefix .. "/elm/node_modules/.bin/elm-language-server",
- },
- -- init_options = {
- -- elmAnalyseTrigger = "change",
- -- elmFormatPath = ls_install_prefix .. "/elm/node_modules/.bin/elm-format",
- -- elmPath = ls_install_prefix .. "/elm/node_modules/.bin/",
- -- elmTestPath = ls_install_prefix .. "/elm/node_modules/.bin/elm-test",
- -- },
- },
- },
- },
- erlang = {
- formatters = {
- -- {
- -- exe = "erlfmt",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "erlangls",
- setup = {
- cmd = {
- "erlang_ls",
- },
- },
- },
- },
- emmet = { active = false },
- fish = {
- formatters = {
- -- {
- -- exe = "fish_indent",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "",
- setup = {},
- },
- },
- fortran = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "fortls",
- setup = {
- cmd = {
- ls_install_prefix .. "/fortran/venv/bin/fortls",
- },
- },
- },
- },
- go = {
- formatters = {
- -- {
- -- exe = "gofmt",
- -- args = {},
- -- },
- -- {
- -- exe = "goimports",
- -- args = {},
- -- },
- -- {
- -- exe = "gofumpt",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "gopls",
- setup = {
- cmd = {
- ls_install_prefix .. "/go/gopls",
- },
- },
- },
- },
- graphql = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "graphql",
- setup = {
- cmd = {
- "graphql-lsp",
- "server",
- "-m",
- "stream",
- },
- },
- },
- },
- haskell = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "hls",
- setup = {
- cmd = { ls_install_prefix .. "/haskell/hls" },
- },
- },
- },
- html = {
- formatters = {
- -- {
- -- exe = "prettier",
- -- args = {},
- -- },
- -- {
- -- exe = "prettierd",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "html",
- setup = {
- cmd = {
- "node",
- ls_install_prefix .. "/html/vscode-html/html-language-features/server/dist/node/htmlServerMain.js",
- "--stdio",
- },
- },
- },
- },
- java = {
- formatters = {
- -- {
- -- exe = "clang_format",
- -- args = {},
- -- },
- -- {
- -- exe = "uncrustify",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "jdtls",
- setup = {
- cmd = { ls_install_prefix .. "/java/jdtls.sh" },
- },
- },
- },
- json = {
- formatters = {
- -- {
- -- exe = "json_tool",
- -- args = {},
- -- },
- -- {
- -- exe = "prettier",
- -- args = {},
- -- },
- -- {
- -- exe = "prettierd",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "jsonls",
- setup = {
- cmd = {
- "node",
- ls_install_prefix .. "/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js",
- "--stdio",
- },
- settings = {
- json = {
- schemas = schemas,
- -- = {
- -- {
- -- fileMatch = { "package.json" },
- -- url = "https://json.schemastore.org/package.json",
- -- },
- -- },
- },
- },
- commands = {
- Format = {
- function()
- vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 })
- end,
- },
- },
- },
- },
- },
- julia = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "julials",
- setup = {
- {
- "julia",
- "--startup-file=no",
- "--history-file=no",
- -- self.runtime_dir .. "lvim/utils/julia/run.jl",
- },
- },
- },
- },
- kotlin = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "kotlin_language_server",
- setup = {
- cmd = {
- ls_install_prefix .. "/kotlin/server/bin/kotlin-language-server",
- },
- root_dir = function(fname)
- local util = require "lspconfig/util"
-
- local root_files = {
- "settings.gradle", -- Gradle (multi-project)
- "settings.gradle.kts", -- Gradle (multi-project)
- "build.xml", -- Ant
- "pom.xml", -- Maven
- }
-
- local fallback_root_files = {
- "build.gradle", -- Gradle
- "build.gradle.kts", -- Gradle
- }
- return util.root_pattern(unpack(root_files))(fname) or util.root_pattern(unpack(fallback_root_files))(fname)
- end,
- },
- },
- },
- lua = {
- formatters = {
- -- {
- -- exe = "stylua",
- -- args = {},
- -- },
- -- {
- -- exe = "lua_format",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "sumneko_lua",
- setup = {
- cmd = {
- ls_install_prefix .. "/lua/sumneko-lua-language-server",
- "-E",
- ls_install_prefix .. "/lua/main.lua",
- },
- settings = {
- Lua = {
- diagnostics = {
- -- Get the language server to recognize the `vim` global
- globals = { "vim", "lvim" },
- },
- workspace = {
- -- Make the server aware of Neovim runtime files
- library = {
- [require("utils").join_paths(get_runtime_dir(), "lvim", "lua")] = true,
- [vim.fn.expand "$VIMRUNTIME/lua"] = true,
- [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
- },
- maxPreload = 100000,
- preloadFileSize = 10000,
- },
- },
- },
- },
- },
- },
- nginx = {
- formatters = {
- -- {
- -- exe = "nginx_beautifier",
- -- args = {
- -- provider = "",
- -- setup = {},
- -- },
- -- },
- },
- linters = {},
- lsp = {},
- },
- perl = {
- formatters = {
- -- {
- -- exe = "perltidy",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "",
- setup = {},
- },
- },
- solidity = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "solang",
- setup = {
- cmd = { "solang", "--language-server" },
- },
- },
- },
- sql = {
- formatters = {
- -- {
- -- exe = "sqlformat",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "sqls",
- setup = {
- cmd = { "sqls" },
- },
- },
- },
- php = {
- formatters = {
- -- {
- -- exe = "phpcbf",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "intelephense",
- setup = {
- cmd = {
- ls_install_prefix .. "/php/node_modules/.bin/intelephense",
- "--stdio",
- },
- filetypes = { "php", "phtml" },
- settings = {
- intelephense = {
- environment = {
- phpVersion = "7.4",
- },
- },
- },
- },
- },
- },
- puppet = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "puppet",
- setup = {
- cmd = {
- ls_install_prefix .. "/puppet/puppet-editor-services/puppet-languageserver",
- "--stdio",
- },
- },
- },
- },
- javascript = {
- formatters = {
- -- {
- -- exe = "prettier",
- -- args = {},
- -- },
- -- {
- -- exe = "prettier_d_slim",
- -- args = {},
- -- },
- -- {
- -- exe = "prettierd",
- -- args = {},
- -- },
- },
- -- @usage can be {"eslint"} or {"eslint_d"}
- linters = {},
- lsp = {
- provider = "tsserver",
- setup = {
- cmd = {
- -- TODO:
- ls_install_prefix .. "/typescript/node_modules/.bin/typescript-language-server",
- "--stdio",
- },
- },
- },
- },
- javascriptreact = {
- formatters = {
- -- {
- -- exe = "prettier",
- -- args = {},
- -- },
- -- {
- -- exe = "prettier_d_slim",
- -- args = {},
- -- },
- -- {
- -- exe = "prettierd",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "tsserver",
- setup = {
- cmd = {
- -- TODO:
- ls_install_prefix .. "/typescript/node_modules/.bin/typescript-language-server",
- "--stdio",
- },
- },
- },
- },
- python = {
- formatters = {
- -- {
- -- exe = "yapf",
- -- args = {},
- -- },
- -- {
- -- exe = "isort",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "pyright",
- setup = {
- cmd = {
- ls_install_prefix .. "/python/node_modules/.bin/pyright-langserver",
- "--stdio",
- },
- },
- },
- },
- -- R -e 'install.packages("formatR",repos = "http://cran.us.r-project.org")'
- -- R -e 'install.packages("readr",repos = "http://cran.us.r-project.org")'
- r = {
- formatters = {
- -- {
- -- exe = "format_r",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "r_language_server",
- setup = {
- cmd = {
- "R",
- "--slave",
- "-e",
- "languageserver::run()",
- },
- },
- },
- },
- ruby = {
- formatters = {
- -- {
- -- exe = "rufo",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "solargraph",
- setup = {
- cmd = {
- ls_install_prefix .. "/ruby/solargraph/solargraph",
- "stdio",
- },
- filetypes = { "ruby" },
- init_options = {
- formatting = true,
- },
- root_dir = function(fname)
- local util = require("lspconfig").util
- return util.root_pattern("Gemfile", ".git")(fname)
- end,
- settings = {
- solargraph = {
- diagnostics = true,
- },
- },
- },
- },
- },
- rust = {
- formatters = {
- -- {
- -- exe = "rustfmt",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "rust_analyzer",
- setup = {
- cmd = {
- ls_install_prefix .. "/rust/rust-analyzer",
- },
- },
- },
- },
- scala = {
- formatters = {
- -- {
- -- exe = "scalafmt",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "metals",
- setup = {},
- },
- },
- sh = {
- formatters = {
- -- {
- -- exe = "shfmt",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "bashls",
- setup = {
- cmd = {
- ls_install_prefix .. "/bash/node_modules/.bin/bash-language-server",
- "start",
- },
- },
- },
- },
- svelte = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "svelte",
- setup = {
- cmd = {
- ls_install_prefix .. "/svelte/node_modules/.bin/svelteserver",
- "--stdio",
- },
- },
- },
- },
- swift = {
- formatters = {
- -- {
- -- exe = "swiftformat",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "sourcekit",
- setup = {
- cmd = {
- "xcrun",
- "sourcekit-lsp",
- },
- },
- },
- },
- tailwindcss = {
- lsp = {
- active = false,
- provider = "tailwindcss",
- setup = {
- cmd = {
- ls_install_prefix .. "/tailwindcss/node_modules/.bin/tailwindcss-language-server",
- "--stdio",
- },
- },
- },
- },
- terraform = {
- formatters = {
- -- {
- -- exe = "terraform_fmt",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "terraformls",
- setup = {
- cmd = {
- ls_install_prefix .. "/terraform/terraform-ls",
- "serve",
- },
- },
- },
- },
- tex = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "texlab",
- setup = {
- cmd = { ls_install_prefix .. "/latex/texlab" },
- },
- },
- },
- typescript = {
- formatters = {
- -- {
- -- exe = "prettier",
- -- args = {},
- -- },
- -- {
- -- exe = "prettierd",
- -- args = {},
- -- },
- -- {
- -- exe = "prettier_d_slim",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "tsserver",
- setup = {
- cmd = {
- -- TODO:
- ls_install_prefix .. "/typescript/node_modules/.bin/typescript-language-server",
- "--stdio",
- },
- },
- },
- },
- typescriptreact = {
- formatters = {
- -- {
- -- exe = "prettier",
- -- args = {},
- -- },
- -- {
- -- exe = "prettierd",
- -- args = {},
- -- },
- -- {
- -- exe = "prettier_d_slim",
- -- args = {},
- -- },
- },
- -- @usage can be {"eslint"} or {"eslint_d"}
- linters = {},
- lsp = {
- provider = "tsserver",
- setup = {
- cmd = {
- -- TODO:
- ls_install_prefix .. "/typescript/node_modules/.bin/typescript-language-server",
- "--stdio",
- },
- },
- },
- },
- vim = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "vimls",
- setup = {
- cmd = {
- ls_install_prefix .. "/vim/node_modules/.bin/vim-language-server",
- "--stdio",
- },
- },
- },
- },
- vue = {
- formatters = {
- -- {
- -- exe = "prettier",
- -- args = {},
- -- },
- -- {
- -- exe = "prettierd",
- -- args = {},
- -- },
- -- {
- -- exe = "prettier_d_slim",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "vuels",
- setup = {
- cmd = {
- ls_install_prefix .. "/vue/node_modules/.bin/vls",
- },
- root_dir = function(fname)
- local util = require "lspconfig/util"
- return util.root_pattern "package.json"(fname) or util.root_pattern "vue.config.js"(fname) or vim.fn.getcwd()
- end,
- init_options = {
- config = {
- vetur = {
- completion = {
- autoImport = true,
- tagCasing = "kebab",
- useScaffoldSnippets = true,
- },
- useWorkspaceDependencies = true,
- validation = {
- script = true,
- style = true,
- template = true,
- },
- },
- },
- },
- },
- },
- },
- yaml = {
- formatters = {
- -- {
- -- exe = "prettier",
- -- args = {},
- -- },
- -- {
- -- exe = "prettierd",
- -- args = {},
- -- },
- },
- linters = {},
- lsp = {
- provider = "yamlls",
- setup = {
- cmd = {
- ls_install_prefix .. "/yaml/node_modules/.bin/yaml-language-server",
- "--stdio",
- },
- },
- },
- },
- zig = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "zls",
- setup = {
- cmd = {
- "zls",
- },
- },
- },
- },
- gdscript = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "gdscript",
- setup = {
- cmd = {
- "nc",
- "localhost",
- "6008",
- },
- },
- },
- },
- ps1 = {
- formatters = {},
- linters = {},
- lsp = {
- provider = "powershell_es",
- setup = {
- bundle_path = "",
- },
- },
- },
- 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,
- },
- },
- },
+ lang = {},
}
diff --git a/lua/config/init.lua b/lua/config/init.lua
index c09617bc..f0062560 100644
--- a/lua/config/init.lua
+++ b/lua/config/init.lua
@@ -22,6 +22,106 @@ function M:init(opts)
local settings = require "config.settings"
settings.load_options()
+
+ local lvim_lsp_config = require "lsp.config"
+ lvim.lsp = vim.deepcopy(lvim_lsp_config)
+
+ local supported_languages = {
+ "asm",
+ "bash",
+ "beancount",
+ "bibtex",
+ "bicep",
+ "c",
+ "c_sharp",
+ "clojure",
+ "cmake",
+ "comment",
+ "commonlisp",
+ "cpp",
+ "crystal",
+ "cs",
+ "css",
+ "cuda",
+ "d",
+ "dart",
+ "dockerfile",
+ "dot",
+ "elixir",
+ "elm",
+ "emmet",
+ "erlang",
+ "fennel",
+ "fish",
+ "fortran",
+ "gdscript",
+ "glimmer",
+ "go",
+ "gomod",
+ "graphql",
+ "haskell",
+ "hcl",
+ "heex",
+ "html",
+ "java",
+ "javascript",
+ "javascriptreact",
+ "jsdoc",
+ "json",
+ "json5",
+ "jsonc",
+ "julia",
+ "kotlin",
+ "latex",
+ "ledger",
+ "less",
+ "lua",
+ "markdown",
+ "nginx",
+ "nix",
+ "ocaml",
+ "ocaml_interface",
+ "perl",
+ "php",
+ "pioasm",
+ "ps1",
+ "puppet",
+ "python",
+ "ql",
+ "query",
+ "r",
+ "regex",
+ "rst",
+ "ruby",
+ "rust",
+ "scala",
+ "scss",
+ "sh",
+ "solidity",
+ "sparql",
+ "sql",
+ "supercollider",
+ "surface",
+ "svelte",
+ "swift",
+ "tailwindcss",
+ "terraform",
+ "tex",
+ "tlaplus",
+ "toml",
+ "tsx",
+ "turtle",
+ "typescript",
+ "typescriptreact",
+ "verilog",
+ "vim",
+ "vue",
+ "yaml",
+ "yang",
+ "zig",
+ }
+
+ require("lsp.manager").init_defaults(supported_languages)
end
--- Override the configuration with a user provided one
diff --git a/lua/core/builtins/init.lua b/lua/core/builtins/init.lua
index dc9b5ff5..c3b3618f 100644
--- a/lua/core/builtins/init.lua
+++ b/lua/core/builtins/init.lua
@@ -15,7 +15,6 @@ local builtins = {
"core.bufferline",
"core.autopairs",
"core.comment",
- "core.lspinstall",
"core.lualine",
}
diff --git a/lua/core/cmp.lua b/lua/core/cmp.lua
index 2bc724fb..965285c7 100644
--- a/lua/core/cmp.lua
+++ b/lua/core/cmp.lua
@@ -35,9 +35,35 @@ M.config = function()
select = true,
},
formatting = {
+ kind_icons = {
+ Class = " ",
+ Color = " ",
+ Constant = "ﲀ ",
+ Constructor = " ",
+ Enum = "練",
+ EnumMember = " ",
+ Event = " ",
+ Field = " ",
+ File = "",
+ Folder = " ",
+ Function = " ",
+ Interface = "ﰮ ",
+ Keyword = " ",
+ Method = " ",
+ Module = " ",
+ Operator = "",
+ Property = " ",
+ Reference = " ",
+ Snippet = " ",
+ Struct = " ",
+ Text = " ",
+ TypeParameter = " ",
+ Unit = "塞",
+ Value = " ",
+ Variable = " ",
+ },
format = function(entry, vim_item)
- local icons = require("lsp.kind").icons
- vim_item.kind = icons[vim_item.kind]
+ vim_item.kind = lvim.builtin.cmp.formatting.kind_icons[vim_item.kind]
vim_item.menu = ({
nvim_lsp = "(LSP)",
emoji = "(Emoji)",
diff --git a/lua/core/info.lua b/lua/core/info.lua
index b8d51a8c..ff024fa5 100644
--- a/lua/core/info.lua
+++ b/lua/core/info.lua
@@ -10,6 +10,7 @@ local M = {
}
local fmt = string.format
+local text = require "interface.text"
local function str_list(list)
return fmt("[ %s ]", table.concat(list, ", "))
@@ -65,44 +66,55 @@ local function tbl_set_highlight(terms, highlight_group)
end
end
+local function make_client_info(client)
+ local client_enabled_caps = require("lsp.utils").get_ls_capabilities(client.id)
+ local name = client.name
+ local id = client.id
+ local document_formatting = client.resolved_capabilities.document_formatting
+ local client_info = {
+ fmt("* Name: %s", name),
+ fmt("* Id: %s", tostring(id)),
+ fmt("* Supports formatting: %s", tostring(document_formatting)),
+ }
+ 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_right(enabled_caps, caps_text_len)
+ enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1))
+ vim.list_extend(client_info, enabled_caps)
+ end
+
+ return client_info
+end
+
function M.toggle_popup(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
- if client ~= nil then
- is_client_active = not client.is_stopped()
- client_enabled_caps = require("lsp").get_ls_capabilities(client.id)
- client_name = client.name
- client_id = client.id
- document_formatting = client.resolved_capabilities.document_formatting
- end
+ local clients = lsp_utils.get_active_client_by_ft(ft)
+ local client_names = {}
local header = {
fmt("Detected filetype: %s", ft),
fmt("Treesitter active: %s", tostring(next(vim.treesitter.highlighter.active) ~= nil)),
}
- local text = require "interface.text"
local lsp_info = {
"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)),
+ fmt "* Associated server(s):",
}
- 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_right(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)
+
+ for _, client in pairs(clients) do
+ vim.list_extend(lsp_info, make_client_info(client))
+ table.insert(client_names, client.name)
end
- local null_ls = require "lsp.null-ls"
- local registered_providers = null_ls.list_supported_provider_names(ft)
+
+ local null_formatters = require "lsp.null-ls.formatters"
+ local null_linters = require "lsp.null-ls.linters"
+ local registered_formatters = null_formatters.list_supported_names(ft)
+ local registered_linters = null_linters.list_supported_names(ft)
+ local registered_providers = {}
+ vim.list_extend(registered_providers, registered_formatters)
+ vim.list_extend(registered_providers, registered_linters)
local registered_count = vim.tbl_count(registered_providers)
local null_ls_info = {
"Formatters and linters",
@@ -113,24 +125,6 @@ function M.toggle_popup(ft)
),
}
- local null_formatters = require "lsp.null-ls.formatters"
- local missing_formatters = null_formatters.list_unsupported_names(ft)
- local missing_formatters_status = {}
- if not vim.tbl_isempty(missing_formatters) then
- missing_formatters_status = {
- fmt("* Missing formatters: %s", table.concat(missing_formatters, "  , ") .. "  "),
- }
- end
-
- local null_linters = require "lsp.null-ls.linters"
- local missing_linters = null_linters.list_unsupported_names(ft)
- local missing_linters_status = {}
- if not vim.tbl_isempty(missing_linters) then
- missing_linters_status = {
- fmt("* Missing linters: %s", table.concat(missing_linters, "  , ") .. "  "),
- }
- end
-
local content_provider = function(popup)
local content = {}
@@ -143,8 +137,6 @@ function M.toggle_popup(ft)
lsp_info,
{ "" },
null_ls_info,
- missing_formatters_status,
- missing_linters_status,
{ "" },
{ "" },
get_formatter_suggestion_msg(ft),
@@ -167,11 +159,8 @@ function M.toggle_popup(ft)
vim.cmd 'let m=matchadd("string", "true")'
vim.cmd 'let m=matchadd("error", "false")'
tbl_set_highlight(registered_providers, "LvimInfoIdentifier")
- tbl_set_highlight(missing_formatters, "LvimInfoIdentifier")
- tbl_set_highlight(missing_linters, "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
local Popup = require("interface.popup"):new {
diff --git a/lua/core/log.lua b/lua/core/log.lua
index 1eb786ba..fca1fcb4 100644
--- a/lua/core/log.lua
+++ b/lua/core/log.lua
@@ -8,6 +8,7 @@ function Log:add_entry(msg, level)
if self.__handle then
-- plenary uses lower-case log levels
self.__handle[level:lower()](msg)
+ return
end
local status_ok, plenary = pcall(require, "plenary")
if status_ok then
diff --git a/lua/core/lspinstall.lua b/lua/core/lspinstall.lua
deleted file mode 100644
index 0bb59e0e..00000000
--- a/lua/core/lspinstall.lua
+++ /dev/null
@@ -1,19 +0,0 @@
-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/lualine/components.lua b/lua/core/lualine/components.lua
index 21e25585..3ee2fdf8 100644
--- a/lua/core/lualine/components.lua
+++ b/lua/core/lualine/components.lua
@@ -96,14 +96,11 @@ return {
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"
diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua
index 27cec37c..a115bcc5 100644
--- a/lua/core/which-key.lua
+++ b/lua/core/which-key.lua
@@ -148,9 +148,9 @@ M.config = function()
"<cmd>Telescope lsp_workspace_diagnostics<cr>",
"Workspace Diagnostics",
},
- -- f = { "<cmd>silent FormatWrite<cr>", "Format" },
f = { "<cmd>lua vim.lsp.buf.formatting()<cr>", "Format" },
i = { "<cmd>LspInfo<cr>", "Info" },
+ I = { "<cmd>LspInstallInfo<cr>", "Installer Info" },
j = {
"<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<cr>",
"Next Diagnostic",
diff --git a/lua/lsp/config.lua b/lua/lsp/config.lua
new file mode 100644
index 00000000..146301c9
--- /dev/null
+++ b/lua/lsp/config.lua
@@ -0,0 +1,27 @@
+return {
+ templates_dir = join_paths(get_runtime_dir(), "site", "after", "ftplugin"),
+ diagnostics = {
+ signs = {
+ active = true,
+ values = {
+ { name = "LspDiagnosticsSignError", text = "" },
+ { name = "LspDiagnosticsSignWarning", text = "" },
+ { name = "LspDiagnosticsSignHint", text = "" },
+ { name = "LspDiagnosticsSignInformation", text = "" },
+ },
+ },
+ virtual_text = {
+ prefix = "",
+ spacing = 0,
+ },
+ update_in_insert = false,
+ underline = true,
+ severity_sort = true,
+ },
+ override = {},
+ document_highlight = true,
+ popup_border = "single",
+ on_attach_callback = nil,
+ on_init_callback = nil,
+ automatic_servers_installation = true,
+}
diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua
index 386be075..7f20a39d 100644
--- a/lua/lsp/init.lua
+++ b/lua/lsp/init.lua
@@ -1,5 +1,6 @@
local M = {}
local Log = require "core.log"
+local utils = require "utils"
local function lsp_highlight_document(client)
if lvim.lsp.document_highlight == false then
@@ -61,48 +62,12 @@ function M.common_capabilities()
return capabilities
end
-function M.get_ls_capabilities(client_id)
- local client
- if not client_id then
- local buf_clients = vim.lsp.buf_get_clients()
- for _, buf_client in ipairs(buf_clients) do
- if buf_client.name ~= "null-ls" then
- client_id = buf_client.id
- break
- end
- end
- end
- if not client_id then
- error "Unable to determine client_id"
- end
-
- client = vim.lsp.get_client_by_id(tonumber(client_id))
-
- local enabled_caps = {}
-
- for k, v in pairs(client.resolved_capabilities) do
- if v == true then
- table.insert(enabled_caps, k)
- end
- end
-
- return enabled_caps
-end
-
function M.common_on_init(client, bufnr)
if lvim.lsp.on_init_callback then
lvim.lsp.on_init_callback(client, bufnr)
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: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)
@@ -112,63 +77,46 @@ function M.common_on_attach(client, bufnr)
end
lsp_highlight_document(client)
add_lsp_buffer_keybindings(bufnr)
- require("lsp.null-ls").setup(vim.bo.filetype)
end
-function M.setup(lang)
- local lsp_utils = require "lsp.utils"
- local lsp = lvim.lang[lang].lsp
- if (lsp.active ~= nil and not lsp.active) or 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
- end
+local function bootstrap_nlsp(opts)
+ opts = opts or {}
+ local lsp_settings_status_ok, lsp_settings = pcall(require, "nlspsettings")
+ if lsp_settings_status_ok then
+ lsp_settings.setup(opts)
end
+end
- if lsp.provider ~= nil and lsp.provider ~= "" then
- local lspconfig = require "lspconfig"
+function M.get_common_opts()
+ return {
+ on_attach = M.common_on_attach,
+ on_init = M.common_on_init,
+ capabilities = M.common_capabilities(),
+ }
+end
- 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
+function M.setup()
+ Log:debug "Setting up LSP support"
- lspconfig[lsp.provider].setup(lsp.setup)
+ local lsp_status_ok, _ = pcall(require, "lspconfig")
+ if not lsp_status_ok then
+ return
end
-end
-
-function M.global_setup()
- vim.lsp.protocol.CompletionItemKind = lvim.lsp.completion.item_kind
for _, sign in ipairs(lvim.lsp.diagnostics.signs.values) do
vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name })
end
-
require("lsp.handlers").setup()
- local null_status_ok, null_ls = pcall(require, "null-ls")
- if null_status_ok then
- null_ls.config()
- require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup)
+ if not utils.is_directory(lvim.lsp.templates_dir) then
+ require("lsp.templates").generate_templates()
end
- local utils = require "utils"
+ bootstrap_nlsp { config_home = utils.join_paths(get_config_dir(), "lsp-settings") }
- local lsp_settings_status_ok, lsp_settings = pcall(require, "nlspsettings")
- if lsp_settings_status_ok then
- lsp_settings.setup {
- config_home = utils.join_paths(get_config_dir(), "lsp-settings"),
- }
- end
+ require("lsp.null-ls").setup()
+
+ require("utils").toggle_autoformat()
end
return M
diff --git a/lua/lsp/kind.lua b/lua/lsp/kind.lua
deleted file mode 100644
index b78fd318..00000000
--- a/lua/lsp/kind.lua
+++ /dev/null
@@ -1,31 +0,0 @@
-local M = {}
-
-M.icons = {
- Class = " ",
- Color = " ",
- Constant = "ﲀ ",
- Constructor = " ",
- Enum = "練",
- EnumMember = " ",
- Event = " ",
- Field = " ",
- File = "",
- Folder = " ",
- Function = " ",
- Interface = "ﰮ ",
- Keyword = " ",
- Method = " ",
- Module = " ",
- Operator = "",
- Property = " ",
- Reference = " ",
- Snippet = " ",
- Struct = " ",
- Text = " ",
- TypeParameter = " ",
- Unit = "塞",
- Value = " ",
- Variable = " ",
-}
-
-return M
diff --git a/lua/lsp/manager.lua b/lua/lsp/manager.lua
new file mode 100644
index 00000000..24d462ad
--- /dev/null
+++ b/lua/lsp/manager.lua
@@ -0,0 +1,82 @@
+local M = {}
+
+local Log = require "core.log"
+local lsp_utils = require "lsp.utils"
+
+function M.init_defaults(languages)
+ for _, entry in ipairs(languages) do
+ if not lvim.lang[entry] then
+ lvim.lang[entry] = {
+ formatters = {},
+ linters = {},
+ }
+ end
+ end
+end
+
+local function is_overridden(server)
+ local overrides = lvim.lsp.override
+ if type(overrides) == "table" then
+ if vim.tbl_contains(overrides, server) then
+ return
+ end
+ end
+end
+
+function M.setup_server(server_name)
+ vim.validate {
+ name = { server_name, "string" },
+ }
+
+ if lsp_utils.is_client_active(server_name) or is_overridden(server_name) then
+ return
+ end
+
+ local lsp_installer_servers = require "nvim-lsp-installer.servers"
+ local server_available, requested_server = lsp_installer_servers.get_server(server_name)
+ if server_available then
+ if not requested_server:is_installed() then
+ Log:debug(string.format("[%s] is not installed", server_name))
+ if lvim.lsp.automatic_servers_installation then
+ Log:debug(string.format("Installing [%s]", server_name))
+ requested_server:install()
+ else
+ return
+ end
+ end
+ end
+
+ local default_config = {
+ on_attach = require("lsp").common_on_attach,
+ on_init = require("lsp").common_on_init,
+ capabilities = require("lsp").common_capabilities(),
+ }
+
+ local status_ok, custom_config = pcall(require, "lsp/providers/" .. requested_server.name)
+ if status_ok then
+ local new_config = vim.tbl_deep_extend("force", default_config, custom_config)
+ Log:debug("Using custom configuration for requested server: " .. requested_server.name)
+ requested_server:setup(new_config)
+ else
+ Log:debug("Using the default configuration for requested server: " .. requested_server.name)
+ requested_server:setup(default_config)
+ end
+end
+
+function M.setup(servers)
+ local status_ok, _ = pcall(require, "nvim-lsp-installer")
+ if not status_ok then
+ return
+ end
+
+ --- allow using a single value
+ if type(servers) == "string" then
+ servers = { servers }
+ end
+
+ for _, server in ipairs(servers) do
+ M.setup_server(server)
+ end
+end
+
+return M
diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua
index 2c2a4f06..8199aca0 100644
--- a/lua/lsp/null-ls/formatters.lua
+++ b/lua/lsp/null-ls/formatters.lua
@@ -1,29 +1,14 @@
local M = {}
-local formatters_by_ft = {}
local null_ls = require "null-ls"
local services = require "lsp.null-ls.services"
local Log = require "core.log"
-local function list_names(formatters, options)
- options = options or {}
- local filter = options.filter or "supported"
-
- return vim.tbl_keys(formatters[filter])
-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" })
+ local null_ls_methods = require "null-ls.methods"
+ local formatter_method = null_ls_methods.internal["FORMATTING"]
+ local registered_providers = services.list_registered_providers_names(filetype)
+ return registered_providers[formatter_method] or {}
end
function M.list_available(filetype)
@@ -62,12 +47,13 @@ function M.list_configured(formatter_configs)
return { supported = formatters, unsupported = errors }
end
-function M.setup(filetype, options)
- if not lvim.lang[filetype] or (formatters_by_ft[filetype] and not options.force_reload) then
+function M.setup(formatter_configs, filetype)
+ if vim.tbl_isempty(formatter_configs) then
return
end
- formatters_by_ft[filetype] = M.list_configured(lvim.lang[filetype].formatters)
+ local formatters_by_ft = {}
+ formatters_by_ft[filetype] = M.list_configured(formatter_configs)
null_ls.register { sources = formatters_by_ft[filetype].supported }
end
diff --git a/lua/lsp/null-ls/init.lua b/lua/lsp/null-ls/init.lua
index ce4c07d9..0540fb48 100644
--- a/lua/lsp/null-ls/init.lua
+++ b/lua/lsp/null-ls/init.lua
@@ -1,44 +1,26 @@
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"):error "Missing null-ls dependency"
+local Log = require "core.log"
+local formatters = require "lsp.null-ls.formatters"
+local linters = require "lsp.null-ls.linters"
+
+function M:setup()
+ local status_ok, null_ls = pcall(require, "null-ls")
+ if not status_ok then
+ Log: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)
+ null_ls.config()
+ require("lspconfig")["null-ls"].setup {}
+ for _, filetype in pairs(lvim.lang) do
+ if filetype.formatters then
+ formatters.setup(filetype.formatters, filetype)
+ end
+ if filetype.linters then
+ linters.setup(filetype.linters, filetype)
+ end
+ end
end
return M
diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua
index d88a8b83..ea45fa87 100644
--- a/lua/lsp/null-ls/linters.lua
+++ b/lua/lsp/null-ls/linters.lua
@@ -1,29 +1,14 @@
local M = {}
-local linters_by_ft = {}
local null_ls = require "null-ls"
local services = require "lsp.null-ls.services"
local Log = require "core.log"
-local function list_names(linters, options)
- options = options or {}
- local filter = options.filter or "supported"
-
- return vim.tbl_keys(linters[filter])
-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" })
+ local null_ls_methods = require "null-ls.methods"
+ local linter_method = null_ls_methods.internal["DIAGNOSTICS"]
+ local registered_providers = services.list_registered_providers_names(filetype)
+ return registered_providers[linter_method] or {}
end
function M.list_available(filetype)
@@ -62,12 +47,13 @@ function M.list_configured(linter_configs)
return { supported = linters, unsupported = errors }
end
-function M.setup(filetype, options)
- if not lvim.lang[filetype] or (linters_by_ft[filetype] and not options.force_reload) then
+function M.setup(linter_configs, filetype)
+ if vim.tbl_isempty(linter_configs) then
return
end
- linters_by_ft[filetype] = M.list_configured(lvim.lang[filetype].linters)
+ local linters_by_ft = {}
+ linters_by_ft[filetype] = M.list_configured(linter_configs)
null_ls.register { sources = linters_by_ft[filetype].supported }
end
diff --git a/lua/lsp/null-ls/services.lua b/lua/lsp/null-ls/services.lua
index 1e76b40a..c62fc709 100644
--- a/lua/lsp/null-ls/services.lua
+++ b/lua/lsp/null-ls/services.lua
@@ -45,4 +45,19 @@ function M.find_command(command)
return nil
end
+function M.list_registered_providers_names(filetype)
+ local u = require "null-ls.utils"
+ local c = require "null-ls.config"
+ local registered = {}
+ for method, source in pairs(c.get()._methods) do
+ for name, filetypes in pairs(source) do
+ if u.filetype_matches(filetypes, filetype) then
+ registered[method] = registered[method] or {}
+ table.insert(registered[method], name)
+ end
+ end
+ end
+ return registered
+end
+
return M
diff --git a/lua/lsp/providers/jsonls.lua b/lua/lsp/providers/jsonls.lua
new file mode 100644
index 00000000..55bc1ea2
--- /dev/null
+++ b/lua/lsp/providers/jsonls.lua
@@ -0,0 +1,30 @@
+local schemas = nil
+local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls")
+if status_ok then
+ schemas = jsonls_settings.get_default_schemas()
+end
+
+local opts = {
+ setup = {
+ settings = {
+ json = {
+ schemas = schemas,
+ -- = {
+ -- {
+ -- fileMatch = { "package.json" },
+ -- url = "https://json.schemastore.org/package.json",
+ -- },
+ -- },
+ },
+ },
+ commands = {
+ Format = {
+ function()
+ vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 })
+ end,
+ },
+ },
+ },
+}
+
+return opts
diff --git a/lua/lsp/providers/sumneko_lua.lua b/lua/lsp/providers/sumneko_lua.lua
new file mode 100644
index 00000000..4fee1fd1
--- /dev/null
+++ b/lua/lsp/providers/sumneko_lua.lua
@@ -0,0 +1,19 @@
+local opts = {
+ settings = {
+ Lua = {
+ diagnostics = {
+ globals = { "vim", "lvim" },
+ },
+ workspace = {
+ library = {
+ [require("utils").join_paths(get_runtime_dir(), "lvim", "lua")] = true,
+ [vim.fn.expand "$VIMRUNTIME/lua"] = true,
+ [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
+ },
+ maxPreload = 100000,
+ preloadFileSize = 10000,
+ },
+ },
+ },
+}
+return opts
diff --git a/lua/lsp/providers/vuels.lua b/lua/lsp/providers/vuels.lua
new file mode 100644
index 00000000..3f44275d
--- /dev/null
+++ b/lua/lsp/providers/vuels.lua
@@ -0,0 +1,26 @@
+local opts = {
+ setup = {
+ root_dir = function(fname)
+ local util = require "lspconfig/util"
+ return util.root_pattern "package.json"(fname) or util.root_pattern "vue.config.js"(fname) or vim.fn.getcwd()
+ end,
+ init_options = {
+ config = {
+ vetur = {
+ completion = {
+ autoImport = true,
+ tagCasing = "kebab",
+ useScaffoldSnippets = true,
+ },
+ useWorkspaceDependencies = true,
+ validation = {
+ script = true,
+ style = true,
+ template = true,
+ },
+ },
+ },
+ },
+ },
+}
+return opts
diff --git a/lua/lsp/templates.lua b/lua/lsp/templates.lua
new file mode 100644
index 00000000..6ded636d
--- /dev/null
+++ b/lua/lsp/templates.lua
@@ -0,0 +1,98 @@
+local M = {}
+
+local Log = require "core.log"
+local utils = require "utils"
+local get_supported_filetypes = require("lsp.utils").get_supported_filetypes
+
+local ftplugin_dir = lvim.lsp.templates_dir
+
+local join_paths = _G.join_paths
+
+function M.remove_template_files()
+ -- remove any outdated files
+ for _, file in ipairs(vim.fn.glob(ftplugin_dir .. "/*.lua", 1, 1)) do
+ vim.fn.delete(file)
+ end
+end
+
+---Checks if a server is ignored by default because of a conflict
+---Only TSServer is enabled by default for the javascript-family
+---@param server_name string
+function M.is_ignored(server_name, filetypes)
+ --TODO: this is easy to be made configurable once stable
+ filetypes = filetypes or get_supported_filetypes(server_name)
+
+ if vim.tbl_contains(filetypes, "javascript") then
+ if server_name == "tsserver" or server_name == "tailwindcss" then
+ return false
+ else
+ return true
+ end
+ end
+
+ local blacklist = {
+ "jedi_language_server",
+ "pylsp",
+ "sqlls",
+ "sqls",
+ "angularls",
+ "ansiblels",
+ }
+ return vim.tbl_contains(blacklist, server_name)
+end
+
+---Generates an ftplugin file based on the server_name in the selected directory
+---@param server_name string name of a valid language server, e.g. pyright, gopls, tsserver, etc.
+---@param dir string the full path to the desired directory
+function M.generate_ftplugin(server_name, dir)
+ -- we need to go through lspconfig to get the corresponding filetypes currently
+ local filetypes = get_supported_filetypes(server_name) or {}
+ if not filetypes then
+ return
+ end
+
+ if M.is_ignored(server_name, filetypes) then
+ return
+ end
+
+ -- print("got associated filetypes: " .. vim.inspect(filetypes))
+
+ for _, filetype in ipairs(filetypes) do
+ local filename = join_paths(dir, filetype .. ".lua")
+ local setup_cmd = string.format([[require("lsp.manager").setup(%q)]], server_name)
+ -- print("using setup_cmd: " .. setup_cmd)
+ -- overwrite the file completely
+ utils.write_file(filename, setup_cmd .. "\n", "a")
+ end
+end
+
+---Generates ftplugin files based on a list of server_names
+---The files are generated to a runtimepath: "$LUNARVIM_RUNTIME_DIR/site/after/ftplugin/template.lua"
+---@param servers_names table list of servers to be enabled. Will add all by default
+function M.generate_templates(servers_names)
+ servers_names = servers_names or {}
+
+ Log:debug "Templates installation in progress"
+
+ M.remove_template_files()
+
+ if vim.tbl_isempty(servers_names) then
+ local available_servers = require("nvim-lsp-installer.servers").get_available_servers()
+
+ for _, server in pairs(available_servers) do
+ table.insert(servers_names, server.name)
+ end
+ end
+
+ -- create the directory if it didn't exist
+ if not utils.is_directory(lvim.lsp.templates_dir) then
+ vim.fn.mkdir(ftplugin_dir, "p")
+ end
+
+ for _, server in ipairs(servers_names) do
+ M.generate_ftplugin(server, ftplugin_dir)
+ end
+ Log:debug "Templates installation is complete"
+end
+
+return M
diff --git a/lua/lsp/utils.lua b/lua/lsp/utils.lua
index 17b9c3bc..1a5dd79d 100644
--- a/lua/lsp/utils.lua
+++ b/lua/lsp/utils.lua
@@ -10,19 +10,60 @@ function M.is_client_active(name)
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
- end
+function M.disable_formatting_capability(client)
+ -- FIXME: figure out a reasonable way to do this
+ client.resolved_capabilities.document_formatting = false
+ require("core.log"):debug(string.format("Turning off formatting capability for language server [%s] ", client.name))
+end
+function M.get_active_client_by_ft(filetype)
+ local matches = {}
local clients = vim.lsp.get_active_clients()
for _, client in pairs(clients) do
- if client.name == lvim.lang[filetype].lsp.provider then
- return client
+ local supported_filetypes = client.config.filetypes or {}
+ if client.name ~= "null-ls" and vim.tbl_contains(supported_filetypes, filetype) then
+ table.insert(matches, client)
+ end
+ end
+ return matches
+end
+
+function M.get_ls_capabilities(client_id)
+ if not client_id then
+ local buf_clients = vim.lsp.buf_get_clients()
+ for _, buf_client in ipairs(buf_clients) do
+ if buf_client.name ~= "null-ls" then
+ client_id = buf_client.id
+ break
+ end
+ end
+ end
+ if not client_id then
+ error "Unable to determine client_id"
+ return
+ end
+
+ local client = vim.lsp.get_client_by_id(tonumber(client_id))
+
+ local enabled_caps = {}
+ for capability, status in pairs(client.resolved_capabilities) do
+ if status == true then
+ table.insert(enabled_caps, capability)
+ end
+ end
+
+ return enabled_caps
+end
+
+function M.get_supported_filetypes(server_name)
+ -- print("got filetypes query request for: " .. server_name)
+ local configs = require "lspconfig/configs"
+ pcall(require, ("lspconfig/" .. server_name))
+ for _, config in pairs(configs) do
+ if config.name == server_name then
+ return config.document_config.default_config.filetypes or {}
end
end
- return nil
end
return M
diff --git a/lua/plugins.lua b/lua/plugins.lua
index 178fb99e..d7f47fcb 100644
--- a/lua/plugins.lua
+++ b/lua/plugins.lua
@@ -6,12 +6,7 @@ return {
{ "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",
- config = function()
- local lspinstall = require "core.lspinstall"
- lspinstall.setup()
- end,
+ "williamboman/nvim-lsp-installer",
},
{ "nvim-lua/popup.nvim" },
diff --git a/lua/utils/init.lua b/lua/utils/init.lua
index 7f8e1f77..eaac54f4 100644
--- a/lua/utils/init.lua
+++ b/lua/utils/init.lua
@@ -99,8 +99,7 @@ function utils.reload_lv_config()
vim.cmd ":PackerInstall"
vim.cmd ":PackerCompile"
-- vim.cmd ":PackerClean"
- local null_ls = require "lsp.null-ls"
- null_ls.setup(vim.bo.filetype, { force_reload = true })
+ require("lsp").setup()
Log:info "Reloaded configuration"
end
@@ -133,15 +132,106 @@ function utils.apply_defaults(config, default_config)
end
--- Checks whether a given path exists and is a file.
---@param filename (string) path to check
+--@param path (string) path to check
--@returns (bool)
-function utils.is_file(filename)
- local stat = uv.fs_stat(filename)
+function utils.is_file(path)
+ local stat = uv.fs_stat(path)
return stat and stat.type == "file" or false
end
+--- Checks whether a given path exists and is a directory
+--@param path (string) path to check
+--@returns (bool)
+function utils.is_directory(path)
+ local stat = uv.fs_stat(path)
+ return stat and stat.type == "directory" or false
+end
+
+function utils.write_file(path, txt, flag)
+ uv.fs_open(path, flag, 438, function(open_err, fd)
+ assert(not open_err, open_err)
+ uv.fs_write(fd, txt, -1, function(write_err)
+ assert(not write_err, write_err)
+ uv.fs_close(fd, function(close_err)
+ assert(not close_err, close_err)
+ end)
+ end)
+ end)
+end
+
utils.join_paths = _G.join_paths
+function utils.write_file(path, txt, flag)
+ uv.fs_open(path, flag, 438, function(open_err, fd)
+ assert(not open_err, open_err)
+ uv.fs_write(fd, txt, -1, function(write_err)
+ assert(not write_err, write_err)
+ uv.fs_close(fd, function(close_err)
+ assert(not close_err, close_err)
+ end)
+ end)
+ end)
+end
+
+function utils.debounce(ms, fn)
+ local timer = vim.loop.new_timer()
+ return function(...)
+ local argv = { ... }
+ timer:start(ms, 0, function()
+ timer:stop()
+ vim.schedule_wrap(fn)(unpack(argv))
+ end)
+ end
+end
+
+function utils.search_file(file, args)
+ local Job = require "plenary.job"
+ local stderr = {}
+ local stdout, ret = Job
+ :new({
+ command = "grep",
+ args = { args, file },
+ cwd = get_cache_dir(),
+ on_stderr = function(_, data)
+ table.insert(stderr, data)
+ end,
+ })
+ :sync()
+ return stdout, ret, stderr
+end
+
+function utils.file_contains(file, query)
+ local stdout, ret, stderr = utils.search_file(file, query)
+ if ret == 0 then
+ return true
+ end
+ if not vim.tbl_isempty(stderr) then
+ error(vim.inspect(stderr))
+ end
+ if not vim.tbl_isempty(stdout) then
+ error(vim.inspect(stdout))
+ end
+ return false
+end
+
+function utils.log_contains(query)
+ local logfile = require("core.log"):get_path()
+ local stdout, ret, stderr = utils.search_file(logfile, query)
+ if ret == 0 then
+ return true
+ end
+ if not vim.tbl_isempty(stderr) then
+ error(vim.inspect(stderr))
+ end
+ if not vim.tbl_isempty(stdout) then
+ error(vim.inspect(stdout))
+ end
+ if not vim.tbl_isempty(stderr) then
+ error(vim.inspect(stderr))
+ end
+ return false
+end
+
return utils
-- TODO: find a new home for these autocommands
diff --git a/tests/bootstrap_spec.lua b/tests/bootstrap_spec.lua
index 73e0a673..e5f7244d 100644
--- a/tests/bootstrap_spec.lua
+++ b/tests/bootstrap_spec.lua
@@ -25,17 +25,4 @@ a.describe("initial start", function()
a.it("should be able to run treesitter without errors", function()
assert.truthy(vim.treesitter.highlighter.active)
end)
-
- a.it("should be able to load default packages without errors", function()
- -- TODO: maybe there's a way to avoid hard-coding the names of the modules?
- local startup_plugins = {
- "packer",
- "lspconfig",
- "nlspsettings",
- "null-ls",
- }
- for _, plugin in pairs(startup_plugins) do
- assert.truthy(package.loaded[tostring(plugin)])
- end
- end)
end)
diff --git a/tests/lsp_spec.lua b/tests/lsp_spec.lua
new file mode 100644
index 00000000..1695bdb4
--- /dev/null
+++ b/tests/lsp_spec.lua
@@ -0,0 +1,98 @@
+local a = require "plenary.async_lib.tests"
+local utils = require "utils"
+lvim.lsp.templates_dir = join_paths(get_runtime_dir(), "lvim", "tests", "artifacts")
+
+a.describe("lsp workflow", function()
+ local Log = require "core.log"
+ local logfile = Log:get_path()
+
+ a.it("shoud be able to delete ftplugin templates", function()
+ if utils.is_directory(lvim.lsp.templates_dir) then
+ assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
+ end
+ assert.False(utils.is_directory(lvim.lsp.templates_dir))
+ end)
+
+ a.it("shoud be able to generate ftplugin templates", function()
+ if utils.is_directory(lvim.lsp.templates_dir) then
+ assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0)
+ end
+ require("lsp").setup()
+
+ -- we need to delay this check until the generation is completed
+ vim.schedule(function()
+ assert.True(utils.is_directory(lvim.lsp.templates_dir))
+ end)
+ end)
+
+ a.it("shoud not attempt to re-generate ftplugin templates", function()
+ lvim.log.level = "debug"
+
+ local plugins = require "plugins"
+ require("plugin-loader"):load { plugins, lvim.plugins }
+
+ if utils.is_file(logfile) then
+ assert.equal(vim.fn.delete(logfile), 0)
+ end
+
+ assert.True(utils.is_directory(lvim.lsp.templates_dir))
+ require("lsp").setup()
+
+ -- we need to delay this check until the log gets populated
+ vim.schedule(function()
+ assert.False(utils.log_contains "templates")
+ end)
+ end)
+
+ a.it("shoud retrieve supported filetypes correctly", function()
+ local ocaml = {
+ name = "ocamlls",
+ filetypes = { "ocaml", "reason" },
+ }
+ local ocaml_fts = require("lsp.utils").get_supported_filetypes(ocaml.name)
+ assert.True(vim.deep_equal(ocaml.filetypes, ocaml_fts))
+
+ local tsserver = {
+ name = "tsserver",
+ filetypes = {
+ "javascript",
+ "javascriptreact",
+ "javascript.jsx",
+ "typescript",
+ "typescriptreact",
+ "typescript.tsx",
+ },
+ }
+ local tsserver_fts = require("lsp.utils").get_supported_filetypes(tsserver.name)
+ assert.True(vim.deep_equal(tsserver.filetypes, tsserver_fts))
+ end)
+
+ a.it("shoud ignore all javascript servers except tsserver and tailwindcss when generating templates", function()
+ local test_server = { name = "denols", filetypes = {} }
+ test_server.filetypes = require("lsp.utils").get_supported_filetypes(test_server.name)
+
+ assert.True(vim.tbl_contains(test_server.filetypes, "javascript"))
+
+ local is_ignored = require("lsp.templates").is_ignored(test_server.name)
+ assert.True(is_ignored)
+
+ local ts_template = utils.join_paths(lvim.lsp.templates_dir, "typescript.lua")
+
+ assert.True(utils.file_contains(ts_template, "tsserver"))
+ assert.True(utils.file_contains(ts_template, "tailwindcss"))
+ assert.False(utils.file_contains(ts_template, test_server.name))
+ end)
+
+ a.it("shoud not include blacklisted servers in the generated templates", function()
+ assert.True(utils.is_directory(lvim.lsp.templates_dir))
+ require("lsp").setup()
+
+ local blacklisted = { "jedi_language_server", "pylsp", "sqlls", "sqls", "angularls", "ansiblels" }
+
+ for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do
+ for _, server in ipairs(blacklisted) do
+ assert.False(utils.file_contains(file, server))
+ end
+ end
+ end)
+end)
diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua
new file mode 100644
index 00000000..f495eba0
--- /dev/null
+++ b/tests/minimal_init.lua
@@ -0,0 +1,9 @@
+local path_sep = vim.loop.os_uname().version:match "Windows" and "\\" or "/"
+
+vim.opt.rtp:append(os.getenv "LUNARVIM_RUNTIME_DIR" .. path_sep .. "lvim")
+
+require("bootstrap"):init()
+
+local config = require "config"
+-- config:init()
+config:load()
diff --git a/tests/plugins_load_spec.lua b/tests/plugins_load_spec.lua
new file mode 100644
index 00000000..cf9ea3b6
--- /dev/null
+++ b/tests/plugins_load_spec.lua
@@ -0,0 +1,34 @@
+local a = require "plenary.async_lib.tests"
+
+a.describe("plugin-loader", function()
+ a.it("should be able to load default packages without errors", function()
+ local plugins = require "plugins"
+ require("plugin-loader"):load { plugins, lvim.plugins }
+
+ -- TODO: maybe there's a way to avoid hard-coding the names of the modules?
+ local startup_plugins = {
+ "packer",
+ }
+
+ for _, plugin in ipairs(startup_plugins) do
+ assert.truthy(package.loaded[plugin])
+ end
+ end)
+
+ a.it("should be able to load lsp packages without errors", function()
+ local plugins = require "plugins"
+ require("plugin-loader"):load { plugins, lvim.plugins }
+
+ require("lsp").setup()
+
+ local lsp_packages = {
+ "lspconfig",
+ "nlspsettings",
+ "null-ls",
+ }
+
+ for _, plugin in ipairs(lsp_packages) do
+ assert.truthy(package.loaded[plugin])
+ end
+ end)
+end)
diff --git a/utils/bin/lvim.ps1 b/utils/bin/lvim.ps1
new file mode 100644
index 00000000..e220e8ec
--- /dev/null
+++ b/utils/bin/lvim.ps1
@@ -0,0 +1,9 @@
+$env:XDG_DATA_HOME = ($env:XDG_DATA_HOME, "$env:APPDATA", 1 -ne $null)[0]
+$env:XDG_CONFIG_HOME = ($env:XDG_CONFIG_HOME, "$LOCALAPPDATA", 1 -ne $null)[0]
+$env:XDG_CACHE_HOME = ($env:XDG_CACHE_HOME, "$TEMP", 1 -ne $null)[0]
+
+$env:LUNARVIM_RUNTIME_DIR = ($env:LUNARVIM_RUNTIME_DIR, "$env:XDG_DATA_HOME\lunarvim", 1 -ne $null)[0]
+$env:LUNARVIM_CONFIG_DIR = ($env:LUNARVIM_CONFIG_DIR, "$env:XDG_CONFIG_HOME\lvim", 1 -ne $null)[0]
+$env:LUNARVIM_CACHE_DIR = ($env:LUNARVIM_CACHE_DIR, "$env:XDG_CACHE_HOME\lvim", 1 -ne $null)[0]
+
+nvim -u "$env:LUNARVIM_RUNTIME_DIR\lvim\init.lua"
diff --git a/utils/bin/test_runner.sh b/utils/bin/test_runner.sh
index 0dabd77f..ee138345 100644
--- a/utils/bin/test_runner.sh
+++ b/utils/bin/test_runner.sh
@@ -10,11 +10,11 @@ rm -f "$LUNARVIM_CONFIG_DIR/plugin/packer_compiled.lua"
lvim() {
# TODO: allow running with a minimal_init.lua
- nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" --cmd "set runtimepath+=$LUNARVIM_RUNTIME_DIR/lvim" "$@"
+ nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/tests/minimal_init.lua" --cmd "set runtimepath+=$LUNARVIM_RUNTIME_DIR/lvim" "$@"
}
if [ -n "$1" ]; then
lvim --headless -c "lua require('plenary.busted').run('$1')"
else
- lvim --headless -c "PlenaryBustedDirectory tests/ { minimal_init = './init.lua' }"
+ lvim --headless -c "PlenaryBustedDirectory tests/ { minimal_init = './tests/minimal_init.lua' }"
fi
diff --git a/utils/installer/config.example.lua b/utils/installer/config.example.lua
index 08a7f3ed..346fac98 100644
--- a/utils/installer/config.example.lua
+++ b/utils/installer/config.example.lua
@@ -55,7 +55,20 @@ lvim.builtin.nvimtree.setup.view.side = "left"
lvim.builtin.nvimtree.show_icons.git = 0
-- if you don't want all the parsers change this to a table of the ones you want
-lvim.builtin.treesitter.ensure_installed = "maintained"
+lvim.builtin.treesitter.ensure_installed = {
+ "bash",
+ "c",
+ "javascript",
+ "json",
+ "lua",
+ "python",
+ "typescript",
+ "css",
+ "rust",
+ "java",
+ "yaml",
+}
+
lvim.builtin.treesitter.ignore_install = { "haskell" }
lvim.builtin.treesitter.highlight.enabled = true
diff --git a/utils/installer/install.ps1 b/utils/installer/install.ps1
new file mode 100644
index 00000000..10adfece
--- /dev/null
+++ b/utils/installer/install.ps1
@@ -0,0 +1,280 @@
+$ErrorActionPreference = "Stop" # exit when command fails
+
+# set script variables
+# FIXME: temporarily set the branch to the new one
+$LV_BRANCH = ($LV_BRANCH, "lang-refactor", 1 -ne $null)[0]
+$LV_REMOTE = ($LV_REMOTE, "lunarvim/lunarvim.git", 1 -ne $null)[0]
+$INSTALL_PREFIX = ($INSTALL_PREFIX, "$HOME\.local", 1 -ne $null)[0]
+
+$env:XDG_DATA_HOME = ($env:XDG_DATA_HOME, "$env:APPDATA", 1 -ne $null)[0]
+$env:XDG_CONFIG_HOME = ($env:XDG_CONFIG_HOME, "$LOCALAPPDATA", 1 -ne $null)[0]
+$env:XDG_CACHE_HOME = ($env:XDG_CACHE_HOME, "$TEMP", 1 -ne $null)[0]
+$env:LUNARVIM_RUNTIME_DIR = ($env:LUNARVIM_RUNTIME_DIR, "$env:XDG_DATA_HOME\lunarvim", 1 -ne $null)[0]
+$env:LUNARVIM_CONFIG_DIR = ($env:LUNARVIM_CONFIG_DIR, "$env:XDG_CONFIG_HOME\lvim", 1 -ne $null)[0]
+$env:LUNARVIM_CACHE_DIR = ($env:LUNARVIM_CACHE_DIR, "$env:XDG_CACHE_HOME\lvim", 1 -ne $null)[0]
+
+
+$__lvim_dirs = (
+ "$env:LUNARVIM_CONFIG_DIR",
+ "$env:LUNARVIM_RUNTIME_DIR",
+ "$env:LUNARVIM_CACHE_DIR"
+)
+
+function main($cliargs) {
+ Write-Output "
+
+ 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 |
+ \__| \______/ \__| \__| \_______|\__| \_/ \__|\__| \__| \__|
+
+ "
+
+ __add_separator "80"
+
+ # skip this in a Github workflow
+ if ( $null -eq "$GITHUB_ACTIONS" ) {
+ install_packer
+ setup_shim
+ exit
+ }
+
+ __add_separator "80"
+
+ check_system_deps
+
+ Write-Output "Would you like to check lunarvim's NodeJS dependencies?"
+ $answer = Read-Host "[y]es or [n]o (default: no) "
+ if ("$answer" -eq "y" -or "$answer" -eq "Y") {
+ install_nodejs_deps
+ }
+
+ Write-Output "Would you like to check lunarvim's Python dependencies?"
+ $answer = Read-Host "[y]es or [n]o (default: no) "
+ if ("$answer" -eq "y" -or "$answer" -eq "Y") {
+ install_python_deps
+ }
+
+ __add_separator "80"
+
+ Write-Output "Backing up old LunarVim configuration"
+ backup_old_config
+
+ __add_separator "80"
+
+ if ($cliargs.Contains("--overwrite")) {
+ Write-Output "!!Warning!! -> Removing all lunarvim related config because of the --overwrite flag"
+ $answer = Read-Host "Would you like to continue? [y]es or [n]o "
+ if ("$answer" -ne "y" -and "$answer" -ne "Y") {
+ exit 1
+ }
+
+ foreach ($dir in $__lvim_dirs) {
+ if (Test-Path "$dir") {
+ Remove-Item -Force -Recurse "$dir"
+ }
+ }
+ }
+
+ if (Test-Path "$env:LUNARVIM_RUNTIME_DIR\site\pack\packer\start\packer.nvim") {
+ Write-Output "Packer already installed"
+ }
+ else {
+ install_packer
+ }
+
+ __add_separator "80"
+
+ if (Test-Path "$env:LUNARVIM_RUNTIME_DIR\lvim\init.lua" ) {
+ Write-Output "Updating LunarVim"
+ update_lvim
+ }
+ else {
+ if ($cliargs.Contains("--testing")) {
+ copy_local_lvim_repository
+ }
+ else {
+ clone_lvim
+ }
+ setup_lvim
+ }
+
+ __add_separator "80"
+}
+
+function print_missing_dep_msg($dep) {
+ Write-Output "[ERROR]: Unable to find dependency [$dep]"
+ Write-Output "Please install it first and re-run the installer. Try: $RECOMMEND_INSTALL $dep"
+}
+
+function install_system_package($dep) {
+ if (Get-Command -Name "winget" -ErrorAction SilentlyContinue) {
+ Write-Output "[INFO]: Attempting to install dependency [$dep] with winget"
+ $install_cmd = "winget install --interactive"
+ }
+ elseif (Get-Command -Name "scoop" -ErrorAction SilentlyContinue) {
+ Write-Output "[INFO]: Attempting to install dependency [$dep] with scoop"
+ # TODO: check if it's fine to not run it with --global
+ $install_cmd = "scoop install"
+ }
+ else {
+ print_missing_dep_msg "$dep"
+ exit 1
+ }
+
+ try {
+ Invoke-Command $install_cmd $dep -ErrorAction Stop
+ }
+ catch {
+ print_missing_dep_msg "$dep"
+ exit 1
+ }
+}
+
+function check_system_dep($dep) {
+ try {
+ Get-Command -Name $dep -ErrorAction Stop | Out-Null
+ }
+ catch {
+ install_system_package "$dep"
+ }
+}
+
+function check_system_deps() {
+ Write-Output "[INFO]: Checking dependencies.."
+ check_system_dep "git"
+ check_system_dep "nvim"
+
+}
+
+function install_nodejs_deps() {
+ try {
+ check_system_dep "node"
+ Invoke-Command npm install -g neovim tree-sitter-cli -ErrorAction Break
+ }
+ catch {
+ print_missing_dep_msg "$dep"
+ }
+}
+
+function install_python_deps() {
+ try {
+ check_system_dep "pip"
+ Invoke-Command python -m pip install --user pynvim -ErrorAction Break
+ }
+ catch {
+ print_missing_dep_msg "$dep"
+ }
+}
+
+function backup_old_config() {
+ foreach ($dir in $__lvim_dirs) {
+ # we create an empty folder for subsequent commands \
+ # that require an existing directory
+ if ( Test-Path "$dir") {
+ New-Item "$dir.bak" -ItemType Directory -Force
+ Copy-Item -Recurse "$dir\*" "$dir.bak\."
+ }
+ }
+
+ Write-Output "Backup operation complete"
+}
+
+
+function install_packer() {
+ Invoke-Command -ErrorAction Stop -ScriptBlock { git clone --progress --depth 1 "https://github.com/wbthomason/packer.nvim" "$env:LUNARVIM_RUNTIME_DIR\site\pack\packer\start\packer.nvim" }
+}
+
+function copy_local_lvim_repository() {
+ Write-Output "Copy local LunarVim configuration"
+ Copy-Item -Path "$((Get-Item $PWD).Parent.Parent.FullName)" -Destination "$env:LUNARVIM_RUNTIME_DIR/lvim" -Recurse
+}
+
+function clone_lvim() {
+ Write-Output "Cloning LunarVim configuration"
+ try {
+ Invoke-Command -ErrorAction Stop -ScriptBlock { git clone --progress --branch "$LV_BRANCH" --depth 1 "https://github.com/$LV_REMOTE" "$env:LUNARVIM_RUNTIME_DIR/lvim" }
+ }
+ catch {
+ Write-Output "Failed to clone repository. Installation failed."
+ exit 1
+ }
+}
+
+function setup_shim() {
+ if ((Test-Path "$INSTALL_PREFIX\bin") -eq $false) {
+ New-Item "$INSTALL_PREFIX\bin" -ItemType Directory
+ }
+ Copy-Item "$env:LUNARVIM_RUNTIME_DIR\lvim\utils\bin\lvim.ps1" -Destination "$INSTALL_PREFIX\bin\lvim.ps1" -Force
+}
+
+function setup_lvim() {
+ Write-Output "Installing LunarVim shim"
+
+ setup_shim
+
+ Write-Output "Preparing Packer setup"
+
+ if ((Test-Path "$env:LUNARVIM_CONFIG_DIR") -eq $false) {
+ New-Item "$env:LUNARVIM_CONFIG_DIR" -ItemType Directory
+ }
+
+ Copy-Item "$env:LUNARVIM_RUNTIME_DIR\lvim\utils\installer\config.example-no-ts.lua" `
+ "$env:LUNARVIM_CONFIG_DIR\config.lua"
+
+ Write-Output "Packer setup complete"
+
+ __add_separator "80"
+
+ Copy-Item "$env:LUNARVIM_RUNTIME_DIR\lvim\utils\installer\config.example.lua" "$env:LUNARVIM_CONFIG_DIR\config.lua"
+
+ $answer = Read-Host $(`
+ "Would you like to create an alias inside your Powershell profile?`n" +`
+ "(This enables you to start lvim with the command 'lvim') [y]es or [n]o (default: no)" )
+ if ("$answer" -eq "y" -and "$answer" -eq "Y") {
+ create_alias
+ }
+
+ __add_separator "80"
+
+ Write-Output "Thank you for installing LunarVim!!"
+ Write-Output "You can start it by running: $INSTALL_PREFIX\bin\lvim.ps1"
+ Write-Output "Do not forget to use a font with glyphs (icons) support [https://github.com/ryanoasis/nerd-fonts]"
+}
+
+
+function update_lvim() {
+ try {
+ Invoke-Command git -C "$env:LUNARVIM_RUNTIME_DIR/lvim" status -uno
+ }
+ catch {
+ git -C "$env:LUNARVIM_RUNTIME_DIR/lvim" pull --ff-only --progress -or
+ Write-Output "Unable to guarantee data integrity while updating. Please do that manually instead."
+ exit 1
+ }
+ Write-Output "Your LunarVim installation is now up to date!"
+}
+
+function __add_separator($div_width) {
+ "-" * $div_width
+ Write-Output ""
+}
+
+function create_alias {
+ if($null -eq $(Get-Alias | Select-String "lvim")){
+ Add-Content -Path $PROFILE -Value $(-join @('Set-Alias lvim "', "$INSTALL_PREFIX", '\bin\lvim.ps1"'))
+
+ Write-Output ""
+ Write-Host 'To use the new alias in this window reload your profile with ". $PROFILE".' -ForegroundColor Yellow
+
+ }else {
+ Write-Output "Alias is already set and will not be reset."
+ }
+}
+
+main "$args"
+
diff --git a/utils/installer/uninstall.ps1 b/utils/installer/uninstall.ps1
new file mode 100644
index 00000000..b362ff5a
--- /dev/null
+++ b/utils/installer/uninstall.ps1
@@ -0,0 +1 @@
+Remove-Item -Path "$HOME/.local/share/lunarvim" -Recurse -Force \ No newline at end of file