[Feature] Add Vue formatter (prettier) setup (#1016)

This commit is contained in:
Pasi Bergman 2021-07-18 21:36:08 +03:00 committed by GitHub
parent b797c2398f
commit d9936b0d84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 5 deletions

View file

@ -189,5 +189,6 @@ require("lang.swift").config()
require("lang.terraform").config()
require("lang.tex").config()
require("lang.vim").config()
require("lang.vue").config()
require("lang.yaml").config()
require("lang.zig").config()

View file

@ -1,13 +1,44 @@
local M = {}
M.config = function()
-- TODO: implement config for language
return "No config available!"
O.lang.vue = {
formatter = {
exe = "prettier",
args = {
"--stdin-filepath",
"${FILEPATH}",
},
stdin = true,
},
auto_import = true,
}
end
M.format = function()
-- TODO: implement formatter for language
return "No formatter available!"
vim.cmd "let proj = FindRootDirectory()"
local root_dir = vim.api.nvim_get_var "proj"
-- use the global formatter if you didn't find the local one
local formatter_instance = root_dir .. "/node_modules/.bin/" .. O.lang.vue.formatter.exe
if vim.fn.executable(formatter_instance) ~= 1 then
formatter_instance = O.lang.vue.formatter.exe
end
local ft = vim.bo.filetype
O.formatters.filetype[ft] = {
function()
local lv_utils = require "lv-utils"
return {
exe = formatter_instance,
args = lv_utils.gsub_args(O.lang.vue.formatter.args),
stdin = O.lang.vue.formatter.stdin,
}
end,
}
require("formatter.config").set_defaults {
logging = false,
filetype = O.formatters.filetype,
}
end
M.lint = function()
@ -24,8 +55,9 @@ M.lsp = function()
require("lspconfig").vuels.setup {
cmd = { DATA_PATH .. "/lspinstall/vue/node_modules/.bin/vls", "--stdio" },
on_attach = require("lsp").common_on_attach,
root_dir = require("lspconfig").util.root_pattern(".git", "vue.config.js", "package.json", "yarn.lock"),
}
require("lsp.ts-fmt-lint").setup()
end
M.dap = function()

View file

@ -204,6 +204,17 @@ lv_utils.define_augroups {
_user_autocommands = O.user_autocommands,
}
function lv_utils.gsub_args(args)
if args == nil or type(args) ~= "table" then
return args
end
local buffer_filepath = vim.fn.fnameescape(vim.api.nvim_buf_get_name(0))
for i = 1, #args do
args[i], _ = string.gsub(args[i], "${FILEPATH}", buffer_filepath)
end
return args
end
vim.cmd [[
function! QuickFixToggle()
if empty(filter(getwininfo(), 'v:val.quickfix'))