Jump to content

Topic on User talk:ArielGlenn/Emacs as a PHP IDE

using Psalm as a lsp provider

5
MarkAHershberger (talkcontribs)

You have to create an psalm.xml file in your git root, but after that, you can just do

  (lsp-register-client
   (make-lsp-client :new-connection
                    (lsp-stdio-connection
                     '("psalm" "--language-server"))
                    :major-modes '(php-mode)
                    :server-id 'psalmls)))

Since I'm toying with this today, I'm using the following in my extension:

<?xml version="1.0"?>
<psalm
    errorLevel="2"
    resolveFromConfigFile="true"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="https://getpsalm.org/schema/config"
    xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
    <projectFiles>
        <directory name="../../maintenance" />
        <directory name="../../includes" />
        <directory name="maintenance" />
        <directory name="includes" />
        <ignoreFiles>
            <directory name="vendor" />
        </ignoreFiles>
    </projectFiles>
</psalm>

Except for the two relative paths under projectFiles, psalm generated this automatically with psalm --init.

Those two lines I added so that psalm's language server would be able to find, for example, the Maintenance class that I'm using in my maintenance script. (I would, of course, prefer to use MW_INSTALL_PATH, but I don't know how to do that with this right now.)

Using this, I get popups with the method signature. For example, in a class that inherits from Maintenance, I can put point on addDescription and emacs puts up a popup with the following:

If I want to see the actual implementation, I just hit M-.

Anyway, if I can just add codesniffer here, I'll be golden.

MarkAHershberger (talkcontribs)

No code sniffer yet, but I wanted to point out something that psalm does that I find very useful.


I typed

$IP = getenv( "MW_INSTALL_PATH" ) ?? "../..";

and psalm immediately flagged it because ?? is the null coalescing operator and getenv only returns false or string.

ArielGlenn (talkcontribs)

Hey once you get your setup the way you like it, what do you think about creating a page for it somewhere with the pieces that should be swapped in/out of my one, and I can link to it from this one? And you could add a nice screenshot too, and a list of capabilties you want and got...

MarkAHershberger (talkcontribs)

Arghh!!! why can't it just work ootb? Ok, if I really want that I should give my life to PHPStorm, but we know that ain't happening, so I'll just tough it out.


But, yes, I thought you were aiming for a page in the main namespace or similar, which is why I was posting so many notes. That, and I like to imagine that people care what I think.

ArielGlenn (talkcontribs)

I hadn't thought about moving it but uh sure could do that, and definitely I WANT YOUR NOTES DO NOT STOP LEAVING THEM thank you.

Reply to "using Psalm as a lsp provider"