poc with local prettier working

This commit is contained in:
christianchiarulli 2021-07-13 00:48:37 -04:00
parent 4fad35a7e1
commit eceb656b4b
7 changed files with 86 additions and 42 deletions

View file

@ -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 if not require("lv-utils").check_lsp_client_active "sumneko_lua" then
-- https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone) -- https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone)
local sumneko_root_path = DATA_PATH .. "/lspinstall/lua" local sumneko_root_path = DATA_PATH .. "/lspinstall/lua"

View file

@ -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. vim.g.colors_name = O.colorscheme -- Colorscheme must get called after plugins are loaded or it will break new installs.
require "settings" require "settings"
require "lv-utils" require "lv-utils"
require "core.formatter"
-- TODO: these guys need to be in language files -- TODO: these guys need to be in language files
-- require "lsp" -- require "lsp"

View file

@ -11,48 +11,45 @@ if O.format_on_save then
} }
end end
-- check if formatter has been defined for the language or not -- -- check if formatter has been defined for the language or not
local function formatter_exists(lang_formatter) -- local function formatter_exists(lang_formatter)
if lang_formatter == nil then -- if lang_formatter == nil then
return false -- return false
end -- end
if lang_formatter.exe == nil or lang_formatter.args == nil then -- if lang_formatter.exe == nil or lang_formatter.args == nil then
return false -- return false
end -- end
return true -- return true
end -- end
-- returns default formatter for given language -- returns default formatter for given language
local function formatter_return(lang_formatter) -- local function formatter_return(lang_formatter)
return { -- return {
exe = lang_formatter.exe, -- exe = lang_formatter.exe,
args = lang_formatter.args, -- args = lang_formatter.args,
stdin = not (lang_formatter.stdin ~= nil), -- stdin = not (lang_formatter.stdin ~= nil),
} -- }
end -- end
-- fill a table like this -> {rust: {exe:"sth",args:{"a","b"},stdin=true},go: {}...} -- fill a table like this -> {rust: {exe:"sth",args:{"a","b"},stdin=true},go: {}...}
local formatter_filetypes = {} -- local formatter_filetypes = {}
for k, v in pairs(O.lang) do -- for k, v in pairs(O.lang) do
if formatter_exists(v.formatter) then -- if formatter_exists(v.formatter) then
local keys = v.filetypes -- local keys = v.filetypes
if keys == nil then -- if keys == nil then
keys = { k } -- keys = { k }
end -- end
for _, l in pairs(keys) do -- for _, l in pairs(keys) do
formatter_filetypes[l] = { -- formatter_filetypes[l] = {
function() -- function()
return formatter_return(v.formatter) -- return formatter_return(v.formatter)
end, -- end,
} -- }
end -- end
end -- end
end -- end
require("formatter").setup { require("formatter").setup {}
logging = false,
filetype = formatter_filetypes,
}
if not O.format_on_save then if not O.format_on_save then
vim.cmd [[if exists('#autoformat#BufWritePost') vim.cmd [[if exists('#autoformat#BufWritePost')

View file

@ -79,6 +79,11 @@ O = {
{ "FileType", "qf", "set nobuflisted" }, { "FileType", "qf", "set nobuflisted" },
}, },
formatters = {
filetype = {},
},
-- TODO move all of this into lang specific files, only require when using
lang = { lang = {
cmake = { cmake = {
formatter = { formatter = {
@ -113,7 +118,7 @@ O = {
docker = {}, docker = {},
efm = {}, efm = {},
elm = {}, elm = {},
emmet = { active = true }, emmet = { active = false },
elixir = {}, elixir = {},
graphql = {}, graphql = {},
go = { go = {

View file

@ -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 if require("lv-utils").check_lsp_client_active "tsserver" then
return return
end end

View file

@ -42,6 +42,11 @@ function lv_utils.define_augroups(definitions) -- {{{1
end end
end end
function lv_utils.unrequire(m)
package.loaded[m] = nil
_G[m] = nil
end
lv_utils.define_augroups { lv_utils.define_augroups {
_general_settings = { _general_settings = {

View file

@ -82,10 +82,9 @@ return require("packer").startup(function(use)
-- Formatter.nvim -- Formatter.nvim
use { use {
"mhartington/formatter.nvim", "mhartington/formatter.nvim",
config = function() -- config = function()
require "core.formatter" -- require "core.formatter"
end, -- end,
event = "BufRead",
} }
-- NvimTree -- NvimTree