Details
-
Bug
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
Qt Creator 17.0.0-beta1
-
None
-
Debian
Python 3.12.3
pylsp 1.12.2
Description
Steps to reproduce:
- Preapare by creatin simple python file having unneded spaces with 2 functions not having return statements:
def f1(): print(1) def f2( ): print(2)
save it to disk outside QtCreator as q.py
- Launch deb-installed- QtCreator as
/opt/qt-creator/bin/qtcreator -temporarycleansettings q.py
file opens
- Select python 3.12 in the upper dropdown (this step may be not needed, my machine has python2.7 installed and it is selected by default)
- Press "install" in the python language server installation suggestion
(install succeeded) - Select all via Ctrl+A
- Select manu "edit->advanced->autoformat selction"
Expected result: extr spaces disappear, both function stay toplevel
Actual result: the bottom function becomes indented as an inner function
def f1(): print(1) def f2(): print(2)
I'm attaching the log from "inspect language clients" window -bad-formatting-pylsp.log
Insights
According to the log it seems that the server done formatting right in the textDocument/rangeFormatting reply, but AFTER getting its result the QtCreator makes unexpected formatting breakage. As if it just inserts formatted result applying own qt creators autoindentation to it - since changing the print(1) to return - change sthe behaviour.
Here is corresponding log exerpt, not that first broken indentation is from client, not from server
13:19:30.575 Client { "id": "{dae2fb0a-b909-4bd1-84e1-e6a1a3fd83d1}", "jsonrpc": "2.0", "method": "textDocument/rangeFormatting", "params": { "options": { "insertSpace": true, "tabSize": 8 }, "range": { "end": { "character": 0, "line": 5 }, "start": { "character": 0, "line": 0 } }, "textDocument": { "uri": "file:///home/vasiliy.galkin/q.py" } } } 13:19:30.579 Server { "id": "{dae2fb0a-b909-4bd1-84e1-e6a1a3fd83d1}", "jsonrpc": "2.0", "result": [ { "newText": "def f1():\n print(1)\n\n\ndef f2():\n print(2)\n", "range": { "end": { "character": 0, "line": 5 }, "start": { "character": 0, "line": 0 } } } ] } 13:19:30.601 Client { "jsonrpc": "2.0", "method": "textDocument/didChange", "params": { "contentChanges": [ { "range": { "end": { "character": 0, "line": 5 }, "start": { "character": 0, "line": 0 } }, "rangeLength": 47, "text": "def f1():\n print(1)\n \n \n def f2():\n print(2)\n " }, { "range": { "end": { "character": 8, "line": 6 }, "start": { "character": 0, "line": 2 } }, "rangeLength": 49, "text": "\n\n def f2():\n print(2)\n" } ], "textDocument": { "uri": "file:///home/vasiliy.galkin/q.py", "version": 2 } } }
On formatting real files with a lot of code nearly all functions become nested into each other up to 10+ levels of nesting, making it a total mess. And same indentation problem appears after another "entire-file-affecting" refactoring "Ctrl+Shift+R" to rename symbol.
So, large part of python LSP functionality is unusable.