https://bugs.kde.org/show_bug.cgi?id=479779
Bug ID: 479779 Summary: textDocument/formatting LSP message causes duplication of buffer text Classification: Applications Product: kate Version: 23.08.4 Platform: Other OS: Linux Status: REPORTED Severity: normal Priority: NOR Component: application Assignee: kwrite-bugs-n...@kde.org Reporter: k...@lfcode.ca Target Milestone: --- Created attachment 164889 --> https://bugs.kde.org/attachment.cgi?id=164889&action=edit debug log from kate, with lsp logs SUMMARY *** NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols. See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports *** Given the following document of Nix code: let x = 5; in 1 When the formatting button is pressed using the nixd language server, the following becomes the buffer content: in 1 let x = 5; in 1 This is essentially pasting the content of the file a second time, which is a bug. This does not happen in neovim with coc, and I strongly suspect this is a bug in kate's LSP client. This is what the language server responds to the format request with: "{\"id\":4,\"jsonrpc\":\"2.0\",\"result\":[{\"newText\":\"let x = 5;\\nin 1\\n\",\"range\":{\"end\":{\"character\":2147483647,\"line\":2147483647},\"start\":{\"character\":0,\"line\":0}}}]}" This message is intending to overwrite the entire contents of the file with the provided text. However, kate seems to do something different with it. I have attached a full debug log of the LSP interaction. I ran kate with the following: LSPCLIENT_DEBUG=1 QT_FORCE_STDERR_LOGGING=1 QT_LOGGING_RULES='katelspclientplugin=true;default.debug=true' kate --startanon -b bad.nix STEPS TO REPRODUCE 0. Acquire nixd and nixpkgs-fmt from nixpkgs. If you have nix, this can be done with `nix-shell -p nixd nixpkgs-fmt`, then running kate from the resulting shell. 1. Configure kate with nixd like so: { "servers": { "nix": { "command": ["nixd"], "highlightingModeRegex": "^Nix$" } } } 2. Write this into bad.nix: let x = 5; in 1 3. Press the LSP format button 4. Get mangled text OBSERVED RESULT Text is mangled. EXPECTED RESULT Text should be replaced with the new text from the language server. SOFTWARE/OS VERSIONS Operating System: NixOS 24.05 KDE Plasma Version: 5.27.10 KDE Frameworks Version: 5.112.0 Qt Version: 5.15.11 Kernel Version: 6.1.69 (64-bit) Graphics Platform: Wayland Processors: 8 × Intel® Core™ i7-7700HQ CPU @ 2.80GHz Memory: 31.2 GiB of RAM Graphics Processor: Mesa Intel® HD Graphics 630 ADDITIONAL INFORMATION -- You are receiving this mail because: You are watching all bug changes.