lite-xl / lite-xl-lsp

LSP Plugin for Lite XL editor
MIT License
160 stars 21 forks source link

Formatting fails with pylsp #86

Closed kra-mo closed 8 months ago

kra-mo commented 10 months ago

The following error is displayed:

Mon Jan 22 17:17:18 2024 [INFO] [toolbox-pylsp] Initialized at /var/home/kramo/.config/lite-xl/plugins/lsp/init.lua:293
Mon Jan 22 17:17:27 2024 [ERROR] /var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:87: invalid table: mixed or invalid key types at /var/home/kramo/.local/share/lite-xl/core/init.lua:1227

stack traceback:
[C]: in function 'error'
/var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:87: in function </var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:73>
(...tail calls...)
/var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:111: in function </var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:73>
(...tail calls...)
/var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:111: in function </var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:73>
(...tail calls...)
/var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:111: in function </var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:73>
(...tail calls...)
/var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:111: in function </var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:73>
(...tail calls...)
/var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:163: in function 'plugins.lsp.json.encode'
/var/home/kramo/.config/lite-xl/plugins/lsp/server.lua:648: in function 'plugins.lsp.server.process_requests'
/var/home/kramo/.config/lite-xl/plugins/lsp/init.lua:2073: in function </var/home/kramo/.config/lite-xl/plugins/lsp/init.lua:2048>
[C]: in function 'xpcall'
/var/home/kramo/.local/share/lite-xl/core/init.lua:1226: in function 'core.try'
(...tail calls...)
kra-mo commented 10 months ago

For the record, this does also happen with the default pylsp config.

Guldoman commented 9 months ago

invalid table: mixed or invalid key types

Oh this is interesting. Could you get a log with verbose = true in the server config?

kra-mo commented 9 months ago
Sat Jan 27 18:14:02 2024 [INFO] [LSP/pylsp]: Adding request textDocument/formatting
 at /var/home/kramo/.config/lite-xl/plugins/lsp/init.lua:761
Sat Jan 27 18:14:02 2024 [ERROR] /var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:87: invalid table: mixed or invalid key types at /var/home/kramo/.local/share/lite-xl/core/init.lua:1227

stack traceback:
[C]: in function 'error'
/var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:87: in function </var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:73>
(...tail calls...)
/var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:111: in function </var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:73>
(...tail calls...)
/var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:111: in function </var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:73>
(...tail calls...)
/var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:111: in function </var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:73>
(...tail calls...)
/var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:111: in function </var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:73>
(...tail calls...)
/var/home/kramo/.config/lite-xl/plugins/lsp/json.lua:163: in function 'plugins.lsp.json.encode'
/var/home/kramo/.config/lite-xl/plugins/lsp/server.lua:648: in function 'plugins.lsp.server.process_requests'
/var/home/kramo/.config/lite-xl/plugins/lsp/init.lua:2073: in function </var/home/kramo/.config/lite-xl/plugins/lsp/init.lua:2048>
[C]: in function 'xpcall'
/var/home/kramo/.local/share/lite-xl/core/init.lua:1226: in function 'core.try'
(...tail calls...)
kra-mo commented 9 months ago

Oh wait, I totally just posted the same logs. Yeah, it doesn't seem to give me anything else even if verbose is set to true.

Guldoman commented 9 months ago

Try replacing this line https://github.com/lite-xl/lite-xl-lsp/blob/9f7ff8220ac1b0f95a05f69a9cc50faa9a74590e/init.lua#L1926 with just trimTrailingWhitespace = true.

kra-mo commented 9 months ago

That fixes it! Thanks.

Guldoman commented 9 months ago

If you want to, feel free to PR that. Otherwise I'll PR it when I can.

Do you think this should be configurable?

kra-mo commented 9 months ago

I'm not even sure what that does 😅 so I think I'd leave it up to you.

kra-mo commented 9 months ago

But if it is just whether whitespace should be trimmed, it should probably follow the plugin.

Guldoman commented 9 months ago

I think I'd leave it up to you.

Sure, no worries.

But if it is just whether whitespace should be trimmed, it should probably follow the plugin.

Yeah, basically that. I guess I'll make it do that then, and maybe allow for an override (for example I don't use that plugin, but I would like for whitespace trimming on format).

kra-mo commented 9 months ago

config.plugins.trimwhitespace.enabled does seem to work, that is probably what was intended there.

Guldoman commented 9 months ago

Yeah, but it needs at least a check to see if the plugin is fully disabled (config.plugins.trimwhitespace = false).