Page 1 of 1

FIXED: [14.90b1] Format document is a mess

Posted: 08 Jun 2021 10:56
by pjj
Formating PHP document via new LSP function destroys it completely :cry:
E.g. from this

Code: Select all

function showReferral(string $id): void
{
    global $thisParticipantReferrals;
//    global $implementersDB;
//    global $iProfessionsDB;
this is produced:

Code: Select all

    function showReferral(str
    ing $id): voidglobal $thi

    sParticipantRef        errals;
            
    //    global $implementersDB;
Wouldn't call it helpful 8)

Re: [14.90b1] Format document is a mess

Posted: 08 Jun 2021 17:58
by Rickard Johansson
It seems some servers are very helpful and send the changes that should be made to the document from the end of document to the beginning. Which is the best way to make the changes to the document.

Other servers add the changes from top to bottom. Which means I have to reverse the order and process the list backwards.

I just have to check the list to determine what to do 8) I'll fix it in the next release...

Re: [14.90b1] Format document is a mess

Posted: 08 Jun 2021 18:16
by pjj
I should have mentioned I used Intelephense server for PHP. I might add that I never use any tool to automatically format code (with slight exception of un-minifying JavaScript once in a blue moon, but that's it.) If you prefer to postpone fixing this, I won't bat an eye 8)

Re: [14.90b1] Format document is a mess

Posted: 09 Jun 2021 12:15
by Rickard Johansson
It's been fixed. Thanks!

Re: FIXED: [14.90b1] Format document is a mess

Posted: 10 Jun 2021 17:47
by pjj
In the second beta it does the job just fine, great! However, it seems that it works only when entire document is selected -- which is confusing...

Small nitpick: "Insert spaces (instead of not tabs)" has superfluous "not", hasn't it?

And while I'm in the nitpicking mood : Project > Configuration > LSP > buttons at the bottom: if the first one is "start", the second should be "stop" 8) (cf. ApacheMonitor.exe) .

Re: FIXED: [14.90b1] Format document is a mess

Posted: 10 Jun 2021 18:37
by Rickard Johansson
There may be a bug in the language server. It works properly in other servers I've tested.

If I send a "textDocument/formatting" request to the server - I receive the response:

{"jsonrpc":"2.0","id":54,"result":[{"range":{"start":{"line":12,"character":28},"end":{"line":14,"character":2}},"newText":"\n"}]}

But if I send a "textDocument/rangeFormatting" request with the entire document selected - I receive the response:

{"jsonrpc":"2.0","id":55,"result":[{"range":{"start":{"line":11,"character":12},"end":{"line":12,"character":0}},"newText":"\n"},{"range":{"start":{"line":10,"character":28},"end":{"line":11,"character":0}},"newText":"\n"},{"range":{"start":{"line":9,"character":23},"end":{"line":10,"character":0}},"newText":"\n"},{"range":{"start":{"line":8,"character":19},"end":{"line":9,"character":2}},"newText":"\n"},{"range":{"start":{"line":6,"character":1},"end":{"line":8,"character":0}},"newText":"\n\n"},{"range":{"start":{"line":5,"character":5},"end":{"line":6,"character":0}},"newText":"\n"},{"range":{"start":{"line":4,"character":24},"end":{"line":5,"character":4}},"newText":"\n "},{"range":{"start":{"line":3,"character":30},"end":{"line":4,"character":8}},"newText":"\n "},{"range":{"start":{"line":3,"character":28},"end":{"line":3,"character":29}},"newText":"\n "},{"range":{"start":{"line":2,"character":14},"end":{"line":3,"character":4}},"newText":"\n "},{"range":{"start":{"line":1,"character":15},"end":{"line":2,"character":4}},"newText":"\n "},{"range":{"start":{"line":1,"character":13},"end":{"line":1,"character":14}},"newText":"\n"},{"range":{"start":{"line":0,"character":5},"end":{"line":1,"character":0}},"newText":"\n"}]}

Re: FIXED: [14.90b1] Format document is a mess

Posted: 12 Jun 2021 18:10
by Rickard Johansson
Seems formatting the entire document works fine if you omit the PHP closing tag at the end of your document...

Re: FIXED: [14.90b1] Format document is a mess

Posted: 12 Jun 2021 19:09
by pjj
Interesting. It is a good practice (and even a standard) to omit PHP closing tag at the end of a file with PHP code!