mirror of
https://github.com/LunarVim/LunarVim.git
synced 2024-09-20 10:35:08 +02:00
poc with local prettier working
This commit is contained in:
parent
4fad35a7e1
commit
eceb656b4b
7 changed files with 86 additions and 42 deletions
|
@ -1,3 +1,19 @@
|
|||
O.formatters.filetype["lua"] = {
|
||||
-- prettier
|
||||
function()
|
||||
return {
|
||||
exe = "stylua",
|
||||
-- TODO: append to this for args don't overwrite
|
||||
args = {},
|
||||
stdin = false,
|
||||
}
|
||||
end,
|
||||
}
|
||||
|
||||
require("formatter.config").set_defaults {
|
||||
logging = false,
|
||||
filetype = O.formatters.filetype,
|
||||
}
|
||||
if not require("lv-utils").check_lsp_client_active "sumneko_lua" then
|
||||
-- https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone)
|
||||
local sumneko_root_path = DATA_PATH .. "/lspinstall/lua"
|
||||
|
|
1
init.lua
1
init.lua
|
@ -8,6 +8,7 @@ require "plugins"
|
|||
vim.g.colors_name = O.colorscheme -- Colorscheme must get called after plugins are loaded or it will break new installs.
|
||||
require "settings"
|
||||
require "lv-utils"
|
||||
require "core.formatter"
|
||||
|
||||
-- TODO: these guys need to be in language files
|
||||
-- require "lsp"
|
||||
|
|
|
@ -11,48 +11,45 @@ if O.format_on_save then
|
|||
}
|
||||
end
|
||||
|
||||
-- check if formatter has been defined for the language or not
|
||||
local function formatter_exists(lang_formatter)
|
||||
if lang_formatter == nil then
|
||||
return false
|
||||
end
|
||||
if lang_formatter.exe == nil or lang_formatter.args == nil then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
-- -- check if formatter has been defined for the language or not
|
||||
-- local function formatter_exists(lang_formatter)
|
||||
-- if lang_formatter == nil then
|
||||
-- return false
|
||||
-- end
|
||||
-- if lang_formatter.exe == nil or lang_formatter.args == nil then
|
||||
-- return false
|
||||
-- end
|
||||
-- return true
|
||||
-- end
|
||||
|
||||
-- returns default formatter for given language
|
||||
local function formatter_return(lang_formatter)
|
||||
return {
|
||||
exe = lang_formatter.exe,
|
||||
args = lang_formatter.args,
|
||||
stdin = not (lang_formatter.stdin ~= nil),
|
||||
}
|
||||
end
|
||||
-- local function formatter_return(lang_formatter)
|
||||
-- return {
|
||||
-- exe = lang_formatter.exe,
|
||||
-- args = lang_formatter.args,
|
||||
-- stdin = not (lang_formatter.stdin ~= nil),
|
||||
-- }
|
||||
-- end
|
||||
|
||||
-- fill a table like this -> {rust: {exe:"sth",args:{"a","b"},stdin=true},go: {}...}
|
||||
local formatter_filetypes = {}
|
||||
for k, v in pairs(O.lang) do
|
||||
if formatter_exists(v.formatter) then
|
||||
local keys = v.filetypes
|
||||
if keys == nil then
|
||||
keys = { k }
|
||||
end
|
||||
for _, l in pairs(keys) do
|
||||
formatter_filetypes[l] = {
|
||||
function()
|
||||
return formatter_return(v.formatter)
|
||||
end,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
-- local formatter_filetypes = {}
|
||||
-- for k, v in pairs(O.lang) do
|
||||
-- if formatter_exists(v.formatter) then
|
||||
-- local keys = v.filetypes
|
||||
-- if keys == nil then
|
||||
-- keys = { k }
|
||||
-- end
|
||||
-- for _, l in pairs(keys) do
|
||||
-- formatter_filetypes[l] = {
|
||||
-- function()
|
||||
-- return formatter_return(v.formatter)
|
||||
-- end,
|
||||
-- }
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
require("formatter").setup {
|
||||
logging = false,
|
||||
filetype = formatter_filetypes,
|
||||
}
|
||||
require("formatter").setup {}
|
||||
|
||||
if not O.format_on_save then
|
||||
vim.cmd [[if exists('#autoformat#BufWritePost')
|
||||
|
|
|
@ -79,6 +79,11 @@ O = {
|
|||
{ "FileType", "qf", "set nobuflisted" },
|
||||
},
|
||||
|
||||
formatters = {
|
||||
filetype = {},
|
||||
},
|
||||
|
||||
-- TODO move all of this into lang specific files, only require when using
|
||||
lang = {
|
||||
cmake = {
|
||||
formatter = {
|
||||
|
@ -113,7 +118,7 @@ O = {
|
|||
docker = {},
|
||||
efm = {},
|
||||
elm = {},
|
||||
emmet = { active = true },
|
||||
emmet = { active = false },
|
||||
elixir = {},
|
||||
graphql = {},
|
||||
go = {
|
||||
|
|
|
@ -1,3 +1,24 @@
|
|||
vim.cmd "let proj = FindRootDirectory()"
|
||||
print(vim.api.nvim_get_var "proj")
|
||||
local root_dir = vim.api.nvim_get_var "proj"
|
||||
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
|
||||
args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" },
|
||||
stdin = true,
|
||||
}
|
||||
end,
|
||||
}
|
||||
|
||||
require("formatter.config").set_defaults {
|
||||
logging = false,
|
||||
filetype = O.formatters.filetype,
|
||||
}
|
||||
|
||||
if require("lv-utils").check_lsp_client_active "tsserver" then
|
||||
return
|
||||
end
|
||||
|
|
|
@ -42,6 +42,11 @@ function lv_utils.define_augroups(definitions) -- {{{1
|
|||
end
|
||||
end
|
||||
|
||||
function lv_utils.unrequire(m)
|
||||
package.loaded[m] = nil
|
||||
_G[m] = nil
|
||||
end
|
||||
|
||||
lv_utils.define_augroups {
|
||||
|
||||
_general_settings = {
|
||||
|
|
|
@ -82,10 +82,9 @@ return require("packer").startup(function(use)
|
|||
-- Formatter.nvim
|
||||
use {
|
||||
"mhartington/formatter.nvim",
|
||||
config = function()
|
||||
require "core.formatter"
|
||||
end,
|
||||
event = "BufRead",
|
||||
-- config = function()
|
||||
-- require "core.formatter"
|
||||
-- end,
|
||||
}
|
||||
|
||||
-- NvimTree
|
||||
|
|
Loading…
Reference in a new issue