lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

New line triggered replace tab indent to spaces

Open d-enk opened this issue 1 year ago • 11 comments

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Linux

What is the issue affecting?

Formatting

Expected Behaviour

do nothing

Actual Behaviour

tab indent replaced to spaces

Reproduction steps

add new line

Peek 2024-05-31 15-21

Additional Notes

configuration has no effect

"Lua.format.enable": false,
"Lua.format.defaultConfig": {
  "indent_style": "tab"
},

Log File

No response

d-enk avatar May 31 '24 12:05 d-enk

This feature is format on type, which is based on what vscode thinks is the indentation of the current file.

CppCXY avatar May 31 '24 14:05 CppCXY

yeap, Lua.typeFormat.config.format_line: "false" disables this, thank

d-enk avatar May 31 '24 14:05 d-enk

Nevertheless Select indentation has no effect

d-enk avatar May 31 '24 14:05 d-enk

also, looks like need a Lua.typeFormat.enable option

d-enk avatar May 31 '24 15:05 d-enk

this is vscode basic config image

CppCXY avatar May 31 '24 15:05 CppCXY

But what if I don’t want to disable this for another lua formatter?

d-enk avatar May 31 '24 15:05 d-enk

No other lua plugin supports type format.

CppCXY avatar May 31 '24 15:05 CppCXY

emmyluacodestyle is lua's only fully functional formatter with vscode support.

CppCXY avatar May 31 '24 15:05 CppCXY

hm, i use stylua or what you mean by 'fully functional'?

d-enk avatar May 31 '24 15:05 d-enk

hm, i use stylua or what you mean by 'fully functional'?

It's good to use stylua, so my explanation doesn't matter.

CppCXY avatar May 31 '24 15:05 CppCXY

See this also on emacs using lsp-mode. Looking at the trace from the logs emacs is sending the following options in the textdocument/onTypeFormatting message:

  "options": {
    "tabSize": 2,
    "insertSpaces": false,
    "trimTrailingWhitespace": true,
    "insertFinalNewline": true,
    "trimFinalNewlines": true
  },

These options get ignored and the server always responds by reformatting one or more proceeding lines using an indent level of 4 characters and indenting with spaces despite me having the following settings in my .editorconfig

[*.lua]
indent_size = 2
indent_style = tab
tab_width = 2
insert_final_newline = true
end_of_line = lf
trim_trailing_whitespace = true
max_line_length = 120

Heres an example full message (with the filename elided)

  "textDocument/onTypeFormatting": {
    "uri": "<removed>"
  },
  "options": {
    "tabSize": 2,
    "insertSpaces": false,
    "trimTrailingWhitespace": true,
    "insertFinalNewline": true,
    "trimFinalNewlines": true
  },
  "ch": "\n",
  "position": {
    "line": 1336,
    "character": 0
  }
}

I'm not 100% sure if this is always the case but this problem manifests most noticably when the lines being reformatted are actually already correctly indented. In other cases I think the server returns the correct formatting adjustment.

mpumford avatar Oct 14 '25 14:10 mpumford