From ae1dea8b6499afbc35d3386654f9d0d8d208d342 Mon Sep 17 00:00:00 2001 From: dklymenk <64093836+dklymenk@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:31:03 +0300 Subject: [PATCH] [Feature] Expose null ls setup to user config (#1323) * expose null_ls setup to user config * add new config to example configs * fix tabs with stylua * change else statement in the example --- init.lua | 2 +- lua/default-config.lua | 3 +++ utils/installer/config.example-no-ts.lua | 15 +++++++++++++++ utils/installer/config.example.lua | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 0224a383..5844d79d 100644 --- a/init.lua +++ b/init.lua @@ -58,7 +58,7 @@ require("lsp").config() local null_status_ok, null_ls = pcall(require, "null-ls") if null_status_ok then null_ls.config {} - require("lspconfig")["null-ls"].setup {} + require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) end local lsp_settings_status_ok, lsp_settings = pcall(require, "nlspsettings") diff --git a/lua/default-config.lua b/lua/default-config.lua index 85a907d1..44da8954 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -104,6 +104,9 @@ lvim = { on_init_callback = nil, ---@usage query the project directory from the language server and use it to set the CWD smart_cwd = true, + null_ls = { + setup = {}, + }, }, plugins = { diff --git a/utils/installer/config.example-no-ts.lua b/utils/installer/config.example-no-ts.lua index b0de00f0..e5c24274 100644 --- a/utils/installer/config.example-no-ts.lua +++ b/utils/installer/config.example-no-ts.lua @@ -61,6 +61,21 @@ lvim.builtin.treesitter.highlight.enabled = true -- --Enable completion triggered by -- buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") -- end +-- you can overwrite the null_ls setup table (useful for setting the root_dir function) +-- lvim.lsp.null_ls.setup = { +-- root_dir = require("lspconfig").util.root_pattern("Makefile", ".git", "node_modules"), +-- } +-- or if you need something more advanced +-- lvim.lsp.null_ls.setup.root_dir = function(fname) +-- if vim.bo.filetype == "javascript" then +-- return require("lspconfig/util").root_pattern("Makefile", ".git", "node_modules")(fname) +-- or require("lspconfig/util").path.dirname(fname) +-- elseif vim.bo.filetype == "php" then +-- return require("lspconfig/util").root_pattern("Makefile", ".git", "composer.json")(fname) or vim.fn.getcwd() +-- else +-- return require("lspconfig/util").root_pattern("Makefile", ".git")(fname) or require("lspconfig/util").path.dirname(fname) +-- end +-- end -- set a formatter if you want to override the default lsp one (if it exists) -- lvim.lang.python.formatters = { diff --git a/utils/installer/config.example.lua b/utils/installer/config.example.lua index 1c39a571..2f8984bb 100644 --- a/utils/installer/config.example.lua +++ b/utils/installer/config.example.lua @@ -70,6 +70,21 @@ lvim.builtin.treesitter.highlight.enabled = true -- --Enable completion triggered by -- buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") -- end +-- you can overwrite the null_ls setup table (useful for setting the root_dir function) +-- lvim.lsp.null_ls.setup = { +-- root_dir = require("lspconfig").util.root_pattern("Makefile", ".git", "node_modules"), +-- } +-- or if you need something more advanced +-- lvim.lsp.null_ls.setup.root_dir = function(fname) +-- if vim.bo.filetype == "javascript" then +-- return require("lspconfig/util").root_pattern("Makefile", ".git", "node_modules")(fname) +-- or require("lspconfig/util").path.dirname(fname) +-- elseif vim.bo.filetype == "php" then +-- return require("lspconfig/util").root_pattern("Makefile", ".git", "composer.json")(fname) or vim.fn.getcwd() +-- else +-- return require("lspconfig/util").root_pattern("Makefile", ".git")(fname) or require("lspconfig/util").path.dirname(fname) +-- end +-- end -- set a formatter if you want to override the default lsp one (if it exists) -- lvim.lang.python.formatters = {