Jump to content

User talk:ArielGlenn/Emacs as a PHP IDE

About this board

serenata and symlinks

1
MarkAHershberger (talkcontribs)

I wanted to get serenata to index a repo without me having to use emacs. I ended up using ngrep to see the jsonrpc calls that emacs was sending to serenata.

Also, I felt link indexing was taking too long to start up and, so, when I did an strace on serenata, I discovered that it was doing infinite recursion on a symlink that I had pointing to the directory it was sitting in.

Anyway, after clearing up the symlink, it is indexing a lot faster now. I'll let you know if it uses the SQLite files it created when I start load a php file when it is done.

Reply to "serenata and symlinks"
MarkAHershberger (talkcontribs)

Since I'm working on extensions and not so much core (but still want to be able to get to core info), your configuration for it isn't going to work for me. And while .dir-locals.el files have their uses, it looks like you have to use hack-local-variables.

I've started using a particular layout for MediaWiki + extensions, configuration, and skins, that makes this a little more difficult. I don't have extensions deployed in mediawiki/extensions, but in another place with symlinks and such to make web servers happy.

This means I can manage git repositories a little bit more sanely (for me, anyway) but it also means that Serenata isn't necessarily going to see the MediaWiki unless I point right to it.

Oh, and I'm dealing with multiple versions of MW for different clients, so I can't point to just one MW install.

Put this all together and I have to have a way to tell Emacs, lsp-mode, and Serenata how to find the parent MediaWiki for a given project. And, I think I want Serenata to use one sqlite db per project. Which will mean that $CLIENT1's MW+extensions, etc will all be stored in SQLITE-DIR1, while $CLIENT2's stuff will be in SQLITE-DIR2.

BTW, this is all made more difficult because MW wants to be its own special snowflake and avoid the common autoloader logic that PHP is migrating to.

Reply to "Serenata and paths"
MarkAHershberger (talkcontribs)

So, just a status update: I know flycheck can use multiple "providers", since I've used it to get psalm + codesniffer input at the same time.

lsp-mode does not appear to be able to work with multiple language servers, but I'd really like to be able to use it as a provider for M-.

This means (to me) that I need to get flycheck+lsp working together, which seems to be the intended possibility.

But right now, I'm seeing Error (use-package): lsp-ui/:config: :start lsp-diagnostics--flycheck-start of syntax checker lsp is not a functionand my use-package stanza for lsp-ui looks like this:

(use-package lsp-ui
  :requires flycheck
  :after lsp-mode
  :config
  (flycheck-define-generic-checker 'lsp
    "A syntax checker using the Language Server Protocol (LSP)
provided by lsp-mode.
See https://github.com/emacs-lsp/lsp-mode."
    :start #'lsp-diagnostics--flycheck-start
    :modes '(lsp-placeholder-mode) ;; placeholder
    :predicate (lambda () lsp-mode)
    :error-explainer (lambda (e)
                       (cond ((string-prefix-p "clang-tidy" (flycheck-error-message e))
                              (lsp-cpp-flycheck-clang-tidy-error-explainer e))
                             (t (flycheck-error-message e)))))
;;  (lsp-flycheck-add-mode 'php-mode)

  (setq
   lsp-ui-doc-enable t
;;   lsp-ui-doc-include-signature t

   lsp-ui-flycheck-list-position 'bottom

   lsp-ui-imenu-enable t

   lsp-ui-peek-enable t
   lsp-ui-peek-list-width 60
   lsp-ui-peek-peek-height 25

   lsp-ui-sideline-enable t
   lsp-ui-sideline-update-mode 'line
   lsp-ui-sideline-show-code-actions t
   lsp-ui-sideline-show-hover nil)

  :bind
  (:map lsp-ui-mode-map
	  ("C-c C-j" . lsp-ui-peek-find-definitions)
	  ("C-c i"   . lsp-ui-peek-find-implementation)
	  ("C-c m"   . lsp-ui-imenu))

  :hook
  (lsp-mode . lsp-ui-mode))

Reply to "flycheck + lsp"

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"
MarkAHershberger (talkcontribs)

I used to have a nice setup using codesniffer and psalm using flymake, but for *reasons*, I stopped using it. And I used to have lsp-mode with psalm's language server.

But bitrot has taken over so when I worked on restoring it recently I ran into some frustrations.

Anyway, I'm gonna try your set up. It seems like it should be possible to start the indexing from the command line.

ArielGlenn (talkcontribs)

Added Psalm to the lsp server list, thanks!

I've no idea about codesniffer, I've ben meaning to ask my "onboarding buddy" about that, heh :-)

Let me know what you find out with treemacs/flymake/some-other-lsp-server-maybe-Serenata. Since you are a regular PHP/IDE user, you'll have a more clearly defined set of needs and be able to see things that need fixing.

MarkAHershberger (talkcontribs)

Well, I'm a PHP user. I toyed with lsp/ide/fly* bit in emacs enough to know that I like it.

btw, how much memory does your system have? I have "only" 16G but the indexing finished without stopping.

ArielGlenn (talkcontribs)

16GB but i have a hog firefox, pidgin, docker running, mariadb and httpd for local dumps testing, etc...

MarkAHershberger (talkcontribs)

Interesting. I have something similar. But who knows.

MarkAHershberger (talkcontribs)

And, actually, I'm not sure I used psalm in LSP or in flycheck. I know I used it in fly* to help with tidying up my code and what not. And codesniffer slaps your wrist (using fly*) to remind you to adhere to MW code standards.

ArielGlenn (talkcontribs)

Yeah I want to figure out a good setup for codesniffer, I see the update emails regularly but never had a need to use it until now.

Reply to "Giving this a try"
MarkAHershberger (talkcontribs)

Here is what I use

(use-package editorconfig)
(use-package prog-mode
  :init
  (defun mah/setup-prettify ()
    "Called when mode is activated."
    ;; specify font for all unicode characters
    (when (member "Symbola" (font-family-list))
      (set-fontset-font t 'symbol "Symbola")
      (set-fontset-font t 'greek "Go Mono"))
    (mapcar (lambda (x)
              (push x prettify-symbols-alist))
            '(("<=" . ?≤) (">=" . ?≥) ("->" . ?→) ("!==" . ?≢)
              ("==" . ?≅) ("===" . ?≡) ("lambda" . ?λ)
              ("=>" . ?⇒) ("!=" . ?≠) ("nil" . ?∅))))
  :hook ((prog-mode . prettify-symbols-mode)
         (prog-mode . editorconfig-mode)
         (prog-mode . mah/setup-prettify)))

(Well, ok, I use prettify, too, so if you don't like having Unicode equivalents to those operators, you can ignore that part.)

(Here's a question: why do are tabs set to 4 spaces in the editor here, but when they're displayed in the pre, they are eight?)

ArielGlenn (talkcontribs)

Hey thanks for this, when I get my head up from IDE tweaks I'll definitely look at better php mode settings, and these will be first on the list!

I will skip the greek operators, thanks, since that would just be potential for confusion with actual greek text.

Tab display is an utter mystery to me. Cargo cult copy-paste all the way and cross my fingers, that's my mantra!

MarkAHershberger (talkcontribs)

Greek is only used for lambda. The others are in the Symbola font. So, if you don't want the greek bit:

 (defun mah/setup-prettify ()
   "Called when mode is activated."
   ;; specify font for all unicode characters
   (when (member "Symbola" (font-family-list))
     (set-fontset-font t 'symbol "Symbola")
   (mapcar (lambda (x)
             (push x prettify-symbols-alist))
           '(("<=" . ?≤) (">=" . ?≥) ("->" . ?→)
             ("==" . ?≅) ("===" . ?≡) ("!==" . ?≢)
             ("=>" . ?⇒) ("!=" . ?≠) ("nil" . ?∅))))

Or you could just take out the (set-fontset-font t 'greek "Go Mono") and your own greek font would be used.

Reply to "tabs vs. spaces"
MarkAHershberger (talkcontribs)

It looks like you want use-package-always-ensure. From the docs:

The :ensure keyword causes the package(s) to be installed automatically if not already present on your system...Enable use-package-always-ensure if you wish this behavior to be global for all packages:
(require 'use-package-ensure)
(setq use-package-always-ensure t)

I only noticed because it is missing on lsp-ui and my emacs complained.

ArielGlenn (talkcontribs)

Woopsie! I added it to the stanza instead. Admittedly I always manually install elpa packages and choose the appropriate and generally very latest unstable version, and I never ship around my .emacs to some system that has not got the packages yet.

Reply to "ensure"
There are no older topics