Menü

Giving Back: Eine WordPress-Erweiterung für den Panic-Editor „Nova“

Veröffentlicht am 09.10.2020, zuletzt aktualisiert am 10.10.2020

Jahrelang war mein Editor der Wahl Coda von Panic. Ein Mac-nativer Editor, der mit Zusatzfunktionen wie SSH-Terminal und FTP-Browser direkt mehrere Tools vereinte. Für meine Ansprüche und Einsatzzwecke war dies immer absolut ausreichend, ich habe nichts wirklich vermisst.

Vor kurzem erschien nach langer Entwicklungszeit und vorheriger Closed Beta, an der ich auch teilgenommen habe, der Nachfolger aus dem Hause Panic: Nova. Was alles genau unter der Haube steckt, kann sich jeder auf der Nova-Website ansehen. Für mich am herausragendsten ist die Geschwindigkeit, die Nova an den Tag legt. Durch die native „Bauweise“ ist der Editor extrem flüssig.

Nova von Panic

Bereits der nun ausgediente Coda-Editor konnte mit Extensions angepasst und erweitert werden. Für mich immer sehr praktisch war die Autovervollständigung von WordPress-Funktionen, die ein netter Entwickler als Erweiterung angeboten hatte. Mit dem Erscheinen von Nova fragte ich mich also: Wird das wieder kommen? Und als Folgefrage: Warum kümmere ich mich nicht einfach selbst darum, dass es so eine Erweiterung wieder gibt?

Do it yourself: Autovervollständigung von WordPress Funktionen in Nova

Gesagt, getan. Oder nein, nicht so einfach direkt getan. Was braucht’s für diese kleine Erweiterung?

Zunächst habe ich mich auf die Suche begeben, wo man alle WordPress Funktionen gesammelt und in strukturierter Weise abrufen kann. Anfangs dachte ich daran, die Code Reference auf developer.wordpress.org zu scrapen und mir die Funktionen und zusätzliche Infos dort zusammenzutragen. Haken: Wenn man nicht auf wordpress.org angemeldet ist, kann man nicht auf die vollständige Code Reference zugreifen. Nach kurzem Chat mit dem WordPress Docs Team über Slack, die diesen Umstand bestätigten, war diese Möglichkeit raus.

Über die WordPress Docs bin ich dann auf den WordPress PHPDoc Parser bzw. WP-Parser aufmerksam geworden. Dieser wird genutzt, um aus dem WordPress-Quellcode die Code Reference zu generieren. Dabei werden die Funktionen und auch Kommentare aus dem Quellcode extrahiert und als Datensätze innerhalb einer WordPress-Installation gespeichert.

Also kurzerhand (eigentlich langerhand) eine lokal WordPress-Instanz aufgesetzt, den WP-Parser mit Composer installiert und über WP-CLI angeschmissen, und zack – eine saubere Liste aller Funktionen, Hooks und Klassen. Daraus dann über einen normalen Query und Loop die nötigen Daten extrahiert und als JSON ausgegeben, und diese in eine Nova-Erweiterung gepackt. Der einfachste Schritt war dann die Veröffentlichung der Erweiterung. Das Ergebnis ist die recht banale Funktionalität, im Editor Vorschläge und Autovervollständigung zu erhalten:

Autovervollständigung von WordPress Core Funktionen

Und da ist sie nun, die Erweiterung, die Autovervollständigung von WordPress-Funktionen in Nova bringt:

Natürlich lässt sich die Erweiterung auch komfortabel direkt in Nova, über die Erweiterungsbibliothek, laden.

Ich werde versuchen mindestens bei großen WordPress-Releases die Erweiterung mit aktuellen Funktionen zu aktualisieren. Fingers crossed, dass ich hier am Ball bleibe 🙂

Kommentare (9)

  • Romain

    Hello Christoph,

    something wrong with your extension „WordPress functions“ for Nova.
    Autocompletion alway open with function „_( $sting )“.
    Just tap a simple space and the autocompletion panel open.
    Very annoying because i have to tap ‚esc‘ before return key or tab key to make a new line.

    Verfasst am 28.10.2020 Antworten
    • Christoph

      Yeah thanks, noticed that as well. The autocompletion is too aggressive, starting for simple characters that shouldn’t actually trigger it. I’ll try to publish a fix soon 🙂

      Verfasst am 28.10.2020
  • KZeni

    Yes, it should also check whether it is in a PHP code block (open-ended or within one that is closed) before showing these autocomplete snippets (since these are PHP-based functions presented.) I’m having it suggest these code snippets even when just working in HTML, which happens to be in a PHP file & is actually incorrect, in addition to being overly aggressive in suggesting them overall.

    Glad to hear it’s updated. I would provide my finding & suggestion so that this is also addressed (just being a PHP file is not enough for autocomplete with PHP functions, it should be within a PHP code block.)

    Thanks for the great extension, btw!
    Kurt

    Verfasst am 28.10.2020 Antworten
    • KZeni

      Appoligies for the bad grammar (hopefully my message is still understandable.) My browser’s auto-translate was actually acting on my text submission (messing up my grammar in the process for some reason) without me noticing it until after I submitted my comment.

      Verfasst am 28.10.2020
    • Christoph

      Thanks, that‘s a valid point as well, hadn‘t noticed that yet. I *think* that would need to be implemented in Nova first though, as far as I know we can only define a filetype at the moment.

      I‘ve also already opened a topic at the Nova dev forum: https://devforum.nova.app/t/auto-completion-triggered-too-much/270 (need to be registered to view though).

      Let‘s see how we can get the extension polished 🙂

      Verfasst am 28.10.2020
  • Christoph

    For anyone stumbling upon this post, and the feeling that Nova is a little overeager on auto-completion: A fix is coming with Nova 3, along with some more API options for auto-completion. Should be due mid November. (Nova dev forum post here: https://devforum.nova.app/t/auto-completion-triggered-too-much/270/3)

    Verfasst am 02.11.2020 Antworten
  • Tobias

    Seems to be fixed now in Nova 3! Nice.

    Verfasst am 14.11.2020 Antworten
  • Mitchell

    When will the Nova WordPress Functions plugin be updated for the most recent WordPress 6.3 release? It has some useful new functions I’d love to autocomplete, including new ’strategy‘ for loading scripts with wp_enqueue_script.

    Verfasst am 18.09.2023 Antworten
    • Christoph

      I’ll try to get an update out in the coming days.

      Verfasst am 19.09.2023

Schreibe einen Kommentar zu Romain Abbrechen