Skip to content

Commit

Permalink
feat(nvim): Add missing formatters/linters to efm
Browse files Browse the repository at this point in the history
Once I get them all working I'll contribute them upstream
  • Loading branch information
mrjones2014 committed Jul 27, 2023
1 parent bbc63b7 commit 6d179c9
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fish/functions/emptytrash.fish
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ function emptytrash
sudo rm -rfv ~/.Trash
sudo rm -rfv /private/var/log/asl/*.asl
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'
end
# end
8 changes: 5 additions & 3 deletions home-manager/modules/nvim.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{ config, pkgs, lib, ... }:
let
inherit (pkgs) stdenv;
inherit (stdenv) isLinux;
# inherit (pkgs) stdenv;
# inherit (stdenv) isLinux;
isLinux = pkgs.stdenv.isLinux;
in {
home.sessionVariables = {
MANPAGER = "nvim -c 'Man!' -o -";
Expand Down Expand Up @@ -58,7 +59,7 @@ in {
viAlias = true;
vimAlias = true;
vimdiffAlias = true;
withNodeJs = true;
withNodeJs = false;
withRuby = false;
withPython3 = false;
defaultEditor = true;
Expand All @@ -82,6 +83,7 @@ in {
nodePackages_latest.markdownlint-cli

# LSP servers
efm-langserver
rnix-lsp
rust-analyzer
taplo
Expand Down
9 changes: 9 additions & 0 deletions nvim/lua/efmls-configs/formatters/cbfmt.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- TODO this one isn't working
local fs = require('efmls-configs.fs')
local formatter = fs.executable('cbfmt')
local command = string.format('%s --stdin-filepath ${INPUT} --best-effort', formatter)

return {
formatCommand = command,
formatStdin = true,
}
6 changes: 6 additions & 0 deletions nvim/lua/efmls-configs/formatters/fish_indent.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local fs = require('efmls-configs.fs')
local formatter = fs.executable('fish_indent')
return {
formatCommand = formatter,
formatStdin = true,
}
6 changes: 6 additions & 0 deletions nvim/lua/efmls-configs/formatters/gofmt.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local fs = require('efmls-configs.fs')
local formatter = fs.executable('gofmt')
return {
formatCommand = formatter,
formatStdin = true,
}
8 changes: 8 additions & 0 deletions nvim/lua/efmls-configs/formatters/markdownlint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- TODO file isn't reloaded after formatting
local fs = require('efmls-configs.fs')
local formatter = fs.executable('markdownlint')
local command = string.format('%s --fix ${INPUT}', formatter)
return {
formatCommand = command,
formatStdin = false,
}
11 changes: 11 additions & 0 deletions nvim/lua/efmls-configs/formatters/nixfmt.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local fs = require('efmls-configs.fs')
local formatter = fs.executable('nixfmt')
return {
formatCommand = formatter,
formatStdin = true,
rootMarkers = {
'flake.nix',
'shell.nix',
'default.nix',
},
}
7 changes: 7 additions & 0 deletions nvim/lua/efmls-configs/formatters/rustfmt.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local fs = require('efmls-configs.fs')
local formatter = fs.executable('rustfmt')
local command = string.format('%s --emit=stdout', formatter)
return {
formatCommand = command,
formatStdin = true,
}
9 changes: 9 additions & 0 deletions nvim/lua/efmls-configs/linters/fish.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- TODO this isn't working
local fs = require('efmls-configs.fs')
local linter = fs.executable('fish')
local command = string.format('%s --no-execute ${INPUT}', linter)

return {
lintCommand = command,
lintFormats = { '%f (line %l): %m' },
}
15 changes: 15 additions & 0 deletions nvim/lua/efmls-configs/linters/statix.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- TODO this one doesn't work
local fs = require('efmls-configs.fs')
local linter = fs.executable('statix')
local command = string.format('%s check --stdin --format=errfmt', linter)
return {
lintCommand = command,
lintStdin = true,
-- lintIgnoreExitCode = true,
lintFormats = { '<text>%l:%c:%t:<text>:%m' },
rootMarkers = {
'flake.nix',
'shell.nix',
'default.nix',
},
}
3 changes: 3 additions & 0 deletions nvim/lua/my/configure/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ return {
'hrsh7th/cmp-nvim-lsp',
{
'creativenull/efmls-configs-nvim',
-- neoconf must be loaded before any LSP
dependencies = { 'folke/neoconf.nvim' },
enabled = false,
event = 'BufReadPre',
config = function()
Expand All @@ -12,6 +14,7 @@ return {
},
{
'jose-elias-alvarez/null-ls.nvim',
enabled = true,
event = 'BufReadPre',
opts = function()
return require('my.lsp.null-ls')
Expand Down
2 changes: 1 addition & 1 deletion nvim/lua/my/legendary/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function M.lsp_autocmds(bufnr, server_name)
end

if
server_name == 'null-ls'
(server_name == 'null-ls' or server_name == 'efm')
and #vim.tbl_filter(function(autocmd)
return autocmd.buflocal == true and autocmd.buffer == bufnr and autocmd.event == 'BufWritePost'
end, autocmds)
Expand Down
2 changes: 1 addition & 1 deletion nvim/lua/my/legendary/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function M.lsp_commands(bufnr, server_name)
},
}

if server_name == 'null-ls' and not (vim.api.nvim_buf_get_commands(0, {}) or {}).Format then
if (server_name == 'null-ls' or server_name == 'efm') and not (vim.api.nvim_buf_get_commands(0, {}) or {}).Format then
commands = TblUtils.join_lists(commands, {
{
':Format',
Expand Down
24 changes: 24 additions & 0 deletions nvim/lua/my/lsp/efm.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
local efmls = require('efmls-configs')

local cbfmt = require('efmls-configs.formatters.cbfmt')
cbfmt.formatCommand =
string.format('%s --config %s', cbfmt.formatCommand, string.format('%s/.config/cbfmt.toml', vim.env.HOME))

local node_config = {
linter = require('efmls-configs.linters.eslint_d'),
-- switch to prettier_d once I can figure out how to install it with Nix
Expand Down Expand Up @@ -30,4 +34,24 @@ efmls.setup({
linter = require('efmls-configs.linters.luacheck'),
formatter = require('efmls-configs.formatters.stylua'),
},
nix = {
linter = require('efmls-configs.linters.statix'),
formatter = require('efmls-configs.formatters.nixfmt'),
},
markdown = {
formatter = {
require('efmls-configs.formatters.markdownlint'),
cbfmt,
},
},
fish = {
formatter = require('efmls-configs.formatters.fish_indent'),
linter = require('efmls-configs.linters.fish'),
},
go = {
formatter = require('efmls-configs.formatters.gofmt'),
},
rust = {
formatter = require('efmls-configs.formatters.rustfmt'),
},
})
10 changes: 9 additions & 1 deletion nvim/lua/my/lsp/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function M.on_attach(client)
end

-- Disable formatting with other LSPs because we're handling formatting via null-ls
if client.name ~= 'null-ls' then
if client.name ~= 'null-ls' and client.name ~= 'efm' then
client.server_capabilities.documentFormattingProvider = false
end
end
Expand All @@ -26,6 +26,14 @@ function M.setup_async_formatting()
-- format on save asynchronously, see M.format_document
vim.lsp.handlers['textDocument/formatting'] = function(err, result, ctx)
if err ~= nil then
-- efm uses table messages
if type(err) == 'table' then
if err.message then
err = err.message
else
err = vim.inspect(err)
end
end
vim.api.nvim_err_write(err)
return
end
Expand Down

0 comments on commit 6d179c9

Please sign in to comment.