LuaLS / LuaLS/lua-language-server

.editorconfig or defaultConfig formatting not respected

Open
#1,068 22 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feat/formatter
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

I'm using neovim 0.7 with lsp-installer and files are not being formatted with the requested configuration in both cases.

ls -lisa ~/.config/nvim/lua/plugins/

total 92
  27091  4 drwxr-xr-x 1 alessio alessio  480 Apr 17 21:17 .
  27090  4 drwxr-xr-x 1 alessio alessio  136 Apr 17 21:07 ..
 530316  4 -rw-r--r-- 1 alessio alessio 1209 Feb 27 10:32 alpha.lua
 530317  4 -rw-r--r-- 1 alessio alessio  863 Feb 27 10:32 autopairs.lua
3166143  4 -rw-r--r-- 1 alessio alessio  970 Apr 17 13:55 blankline.lua
 530321  4 -rw-r--r-- 1 alessio alessio 3601 Feb 27 10:32 bufferline.lua
3168662  4 -rw-r--r-- 1 alessio alessio  742 Apr 17 19:52 comment.lua
3173616  4 -rw-r--r-- 1 alessio alessio  139 Apr 17 20:48 .editorconfig
 530320  4 -rw-r--r-- 1 alessio alessio 1777 Feb 27 10:32 gitsigns.lua
 530325  4 -rw-r--r-- 1 alessio alessio  122 Feb 27 10:32 impatient.lua
 530315  4 -rw-r--r-- 1 alessio alessio  978 Feb 27 10:32 lualine.lua
3173626  4 -rw-r--r-- 1 alessio alessio   90 Apr 17 20:50 null-ls.lua
3168656  4 -rw-r--r-- 1 alessio alessio 3163 Apr 17 19:52 nvim-cmp.lua
 530326  4 -rw-r--r-- 1 alessio alessio 3479 Feb 27 10:32 nvim-dap.lua
3174745  4 -rw-r--r-- 1 alessio alessio  667 Apr 17 21:17 nvim-lspinstall.lua
 530313  4 -rw-r--r-- 1 alessio alessio  835 Feb 27 10:32 nvim-tree.lua
 530322  4 -rw-r--r-- 1 alessio alessio  332 Feb 27 10:32 telescope.lua
 530323  4 -rw-r--r-- 1 alessio alessio 1188 Feb 27 10:32 toggleterm.lua
3166177  4 -rw-r--r-- 1 alessio alessio  869 Apr 17 13:58 treesitter.lua
 530318  4 -rw-r--r-- 1 alessio alessio  248 Feb 27 10:32 trouble.lua
3166244 12 -rw-r--r-- 1 alessio alessio 9939 Apr 17 14:03 whichkey.lua

.editorconfig

[*.lua]
# [basic code reformat option]
# optional space/tab
indent_style = space
# if indent_style is space, this is valid
indent_size = 4

nvim-lspinstall.lua

local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer")
if not status_ok then
	return
end

lsp_installer.on_server_ready(function(server)
	local opts = {}
	if server.name == "sumneko_lua" then
		opts.settings = {
			Lua = {
				diagnostics = {
					globals = { "vim" }
				},
				format = {
					enable = true,
					defaultConfig = {
						indent_style = "space",
						indent_size = "4",
					}
				},
			}
		}
	end

	server:setup(opts)
end)

I use the command lua vim.lsp.buf.formatting() but the code is formatted with the default values (8 spaces I think)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the report with the shown .editorconfig, nvim-lspinstall.lua settings, and lua vim.lsp.buf.formatting() command. Trace how the language server receives formatting configuration and verify that formatting Lua files honors indent_style=space and indent_size=4 rather than the reported default.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, neovim
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.