summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorAbouzar Parvan <[email protected]>2021-07-14 04:19:36 +0430
committerGitHub <[email protected]>2021-07-13 19:49:36 -0400
commitde7ec62f5fde20ca1d7e53ed83a0077f8945f67c (patch)
tree1d54b2232489e53a98025825ed550c28e7adea95 /lua
parent6bbc082f5758cdb57ecb25f270e5558ab63d3754 (diff)
Added default formatters (#908)
* added default formatters for a couple of langs * fix: sugesstions from tastyep * allow users to change default formatters * suggestion: mellow pointed out the telescope issue * we don't need to use formatter.setup
Diffstat (limited to 'lua')
-rw-r--r--lua/core/formatter.lua2
-rw-r--r--lua/default-config.lua8
-rw-r--r--lua/lsp/tsserver-ls.lua17
3 files changed, 12 insertions, 15 deletions
diff --git a/lua/core/formatter.lua b/lua/core/formatter.lua
index 06fcb56d..05de74ab 100644
--- a/lua/core/formatter.lua
+++ b/lua/core/formatter.lua
@@ -53,8 +53,6 @@ if not status_ok then
return
end
-formatter.setup {}
-
if not O.format_on_save then
vim.cmd [[if exists('#autoformat#BufWritePost')
:autocmd! autoformat
diff --git a/lua/default-config.lua b/lua/default-config.lua
index 8eca53c9..df17d0af 100644
--- a/lua/default-config.lua
+++ b/lua/default-config.lua
@@ -258,11 +258,6 @@ O = {
"typescript",
"typescriptreact",
},
- formatter = {
- exe = "prettier",
- args = { "--write", "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" },
- stdin = false,
- },
},
terraform = {},
tsserver = {
@@ -275,8 +270,7 @@ O = {
},
formatter = {
exe = "prettier",
- args = { "--write", "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" },
- stdin = false,
+ args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" },
},
},
vim = {},
diff --git a/lua/lsp/tsserver-ls.lua b/lua/lsp/tsserver-ls.lua
index c95b7810..22c58950 100644
--- a/lua/lsp/tsserver-ls.lua
+++ b/lua/lsp/tsserver-ls.lua
@@ -1,18 +1,23 @@
vim.cmd "let proj = FindRootDirectory()"
-print(vim.api.nvim_get_var "proj")
local root_dir = vim.api.nvim_get_var "proj"
+
+-- use the global prettier if you didn't find the local one
+local prettier_instance = root_dir .. "/node_modules/.bin/prettier"
+if vim.fn.executable(prettier_instance) ~= 1 then
+ prettier_instance = O.lang.tsserver.formatter.exe
+end
+
O.formatters.filetype["javascriptreact"] = {
- -- vim.cmd "let root_dir "
- -- prettier
function()
return {
- exe = root_dir .. "/node_modules/.bin/prettier",
- -- TODO: append to this for args don't overwrite
+ exe = prettier_instance,
+ -- TODO: allow user to override this
args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" },
- stdin = true,
+ stdin = true
}
end,
}
+O.formatters.filetype["javascript"] = O.formatters.filetype["javascriptreact"]
require("formatter.config").set_defaults {
logging = false,