Skip to content

Commit

Permalink
fix: use stylua to avoid clearing diagnostic text on save
Browse files Browse the repository at this point in the history
  • Loading branch information
konradmalik committed Aug 29, 2023
1 parent ffc1837 commit afe394e
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .luarc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"Lua.workspace.checkThirdParty": false
"workspace.checkThirdParty": false
}
3 changes: 3 additions & 0 deletions .nvim.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
require("konrad.lsp").setup({
efm = {
"stylua",
},
"lua_ls",
"nil_ls",
})
5 changes: 4 additions & 1 deletion config/native/after/plugin/heirline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ heirline.setup({
disable_winbar_cb = function(args)
return conditions.buffer_matches({
buftype = { "nofile", "prompt", "help", "quickfix" },
filetype = { "^git.*", "fugitive", "Trouble", "dashboard" },
filetype = { "^git.*", "fugitive",
-- undotree
"undotree", "diff",
},
}, args.buf)
end,
},
Expand Down
1 change: 1 addition & 0 deletions config/native/lua/konrad/lsp/efm/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ M.build_lspconfig = function(plugins)
filetypes = vim.tbl_keys(languages),
init_options = {
documentFormatting = true,
documentRangeFormatting = true,
},
settings = {
rootMarkers = { '.git/' },
Expand Down
13 changes: 13 additions & 0 deletions config/native/lua/konrad/lsp/efm/stylua.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- url: https://github.com/johnnymorganz/stylua
local efm = require('konrad.lsp.efm')

local command = 'stylua --color Never ${--range-start:charStart} ${--range-end:charEnd} -'
local fts = { "lua" }
local entry = {
formatCanRange = true,
formatCommand = command,
formatStdin = true,
rootMarkers = { 'stylua.toml', '.stylua.toml' },
}

return efm.make_languages_entry_for_fts(fts, entry)
13 changes: 12 additions & 1 deletion config/native/lua/konrad/lsp/settings/lua_ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ neodev.setup({
})

return {
init_options = {
documentFormatting = false,
documentRangeFormatting = false,
},
on_init = function(client)
-- use stylua via efm, this formatter is not great and it cleares diagnostic text on save
client.server_capabilities.documentFormattingProvider = nil
client.server_capabilities.documentRangeFormattingProvider = nil
end,
settings = {
Lua = {
addonManager = { enable = false },
telemetry = { enable = false },
hint = { enable = true },
format = { enable = true },
-- use stylua via efm, this formatter is not great and it cleares diagnostic text on save
format = { enable = false },
}
}
}
4 changes: 4 additions & 0 deletions config/native/lua/konrad/lsp/settings/omnisharp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ local util = require 'lspconfig.util'

local function nix_omnisharp_dll_path()
local binpath = vim.fn.exepath("OmniSharp")
if not binpath then
vim.notify("cannot find omnisharp executable", vim.log.levels.ERROR)
return "OmniSharp"
end
local omnipath = binpath:sub(1, -(string.len("bin/OmniSharp") + 1))
local dllpath = omnipath .. "lib/omnisharp-roslyn/OmniSharp.dll"
return dllpath
Expand Down
1 change: 1 addition & 0 deletions config/native/skeletons/.nvim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require("konrad.lsp").setup({
-- "ansiblels",
-- efm = {
-- 'black'
-- 'stylua'
-- },
-- "gopls",
-- "jsonls",
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
packages = with pkgs; [
# formatters/linters
nixpkgs-fmt
stylua
# language-servers
nil
sumneko-lua-language-server
Expand Down

0 comments on commit afe394e

Please sign in to comment.