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

textDocument/formatting should return a edits instead of totall text for client

Open kevinhwang91 opened this issue 3 years ago • 6 comments

Describe the bug https://github.com/sumneko/lua-language-server/blob/f760dc359b389c20a0d48bef463d14800e67894c/script/core/formatting.lua#L5-L25

As a server, we should diff the document and the return result and generate the edits for the client. If the server returns totally text result, the context resource in the client may be invalid, like semantic token.

kevinhwang91 avatar Apr 13 '22 14:04 kevinhwang91

@CppCXY

sumneko avatar Apr 14 '22 12:04 sumneko

Diff into a lot of edits may have a large consumption, and there is no consideration in this regard for the time being. maybe this will be considered in the future.

CppCXY avatar Apr 14 '22 12:04 CppCXY

I used https://github.com/Koihik/LuaFormatter provider format for the text and https://github.com/mattn/efm-langserver provider diff before I migrate to the format in this server.

@CppCXY I am not sure whether the diff logic done by the backend provider is good or not, but IMO, it is the responsibility of a language server. A server may use other FOSS format providers only provider full text format and adapt them into the LSP. However, https://github.com/CppCXY/EmmyLuaCodeStyle have provided the rangeformatting, the diff logic looks not a big feature.

@sumneko How do you think about doing the diff logic on server side?

kevinhwang91 avatar Apr 14 '22 13:04 kevinhwang91

I agree to make diffs by the server. But I'm busy with other work, so the priority is relatively low.

sumneko avatar Apr 14 '22 13:04 sumneko

Maybe I can help this weekend or next weekend. Is PR welcome?

kevinhwang91 avatar Apr 14 '22 13:04 kevinhwang91

Of course. Since you have made and passed a lot of PR, maybe my answer not welcome will be more dramatic🙃.

sumneko avatar Apr 14 '22 13:04 sumneko