remove prettier format

This commit is contained in:
Ivan Dimitrov 2023-09-16 02:43:00 +03:00
parent 003177e093
commit ea45a78b26

View File

@ -44,34 +44,6 @@ nmap("<leader>e", vim.diagnostic.open_float)
-- START LSP
local highlight_filetypes = { "*.ts", "*.tsx", "*.js", "*.jsx", "*.html", "*.lua", "*.hs" }
local prettier_filetypes = { "%.ts$", "%.tsx$", "%.js$", "%.jsx$", "%.html$", "%.json$", "%.css$" }
local function matches_filetypes(file_path, filetypes)
for _, pattern in ipairs(filetypes) do
if file_path:match(pattern) then
return true
end
end
return false
end
local function str_to_table(str)
local t = {}
for line in string.gmatch(str, "([^\n]+)") do
table.insert(t, line)
end
return t
end
local function prettier_format(file_path, content)
local prettier_command = string.format("prettier --stdin-filepath '%s' <<< '%s'", file_path, content)
local output = io.popen(prettier_command, "r")
local result = output:read("*a")
output:close()
return result
end
local cmp = require("cmp")
local lspconfig = require("lspconfig")
local servers = {
@ -93,23 +65,11 @@ local servers = {
}
local cmp_capabilities = require("cmp_nvim_lsp").default_capabilities()
local on_attach = function(client, bufnr)
local format_buffer = function()
local file_path = vim.api.nvim_buf_get_name(bufnr)
if (matches_filetypes(file_path, prettier_filetypes)) then
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
local content = table.concat(lines, "\n")
local result = prettier_format(file_path, content)
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, str_to_table(result))
else
vim.lsp.buf.format()
end
end
nmap("<leader>ca", vim.lsp.buf.code_action)
nmap("<leader>lr", vim.lsp.buf.rename)
nmap("gd", vim.lsp.buf.definition)
nmap("<leader>lf", function()
format_buffer()
vim.lsp.buf.format()
end)
nmap("K", vim.lsp.buf.hover)
nmap("gr", require("telescope.builtin").lsp_references)