Skip to content

Phoxite 0.8.0

Choose a tag to compare

@github-actions github-actions released this 20 Nov 23:11
· 22 commits to main since this release
  • CodeIgniter (4, and 3). In a CodeIgniter application the names its helper functions
    take are references: views (view(), $this->extend(), $this->include(), a
    module's Blog\Views\list), helpers (helper(), $helpers), language lines
    (lang('File.key')), routes (route_to(), redirect()->route() ↔ the as of a
    route, its path when it has none, or its handler), filter aliases ('filter' => 'auth'
    ↔ Config\Filters::$aliases), configurations, models, services, view cells
    (view_cell('Card::render')), events (Events::on() ↔ Events::trigger()),
    validation rules (each rule of 'required|min_length[3]' ↔ the methods of the rule
    sets) and rule groups, tables and columns ($db->table('books'), a model's $table
    and $allowedFields, ->where('title', …) ↔ the migrations), and a route's handler
    ('Books::show/$1', in the namespace of its group). Each goes to what it names and has
    Find References and a hover; a route name, a filter alias and an event are renamed.

    • Types: service('name'), model('BookModel') and config('App') are the service,
      the model and the configuration class; a model's find(), first() and findAll()
      follow its $returnType; $db->table('books') is a builder of that table.
    • A view has the variables its controller passes it, with their types
      (view('books/list', ['books' => $books])), as have the layout it extends and the
      views it includes. They aren't reported as undefined.
    • Inspections for a name that names nothing: PhpUndefinedCodeIgniterView,
      PhpUndefinedCodeIgniterHelper, PhpUndefinedCodeIgniterLanguageLine,
      PhpUndefinedCodeIgniterRoute, PhpUnknownCodeIgniterFilter,
      PhpUndefinedCodeIgniterController, PhpUnknownCodeIgniterRule,
      PhpUnknownCodeIgniterRuleGroup, PhpUndefinedCodeIgniterModel,
      PhpUndefinedCodeIgniterConfig, PhpUndefinedCodeIgniterService,
      PhpUndefinedCodeIgniterCell. Off unless turned on, as what they look for may be
      defined outside the project: PhpUndefinedCodeIgniterEvent,
      PhpUnknownCodeIgniterTable, PhpUnknownCodeIgniterColumn.
    • Several columns in one string (select('title, price')), a column in an expression
      (where('COUNT(price) >', 3)), the table and field of is_unique[books.title], the
      routes resource() and presenter() make, and a path (site_url('books/show'),
      redirect()->to(): its route, else the method auto-routing would call) are names too.
    • Modules (the $psr4 of Config/Autoload.php, Composer's namespaces) bring their
      views, helpers, language files and routes; Config/Paths.php says where a moved
      app, system or views folder is.
    • CodeIgniter 3: $this->load->view(), ->model(), ->library(), ->helper(),
      $this->lang->line(), $this->config->item() and the path of site_url() and
      redirect() are references; $this->load, $this->db, $this->session, a loaded
      model (under its own name or another) and a library of the application are typed in
      controllers, models and views; a path goes through the routes of config/routes.php;
      the tables and fields of application/migrations are the names of $this->db's
      methods.
  • A property a framework gives a class isn't reported as undefined, and a string in PHP
    embedded in markup (<a href="<?= site_url('books') ?>">) is found where it was taken
    for part of the attribute.

  • An inline /** @var Type $name */ declares a variable that nothing in the file sets
    ($routes at the top of a routes file), instead of only retyping one that exists.

  • Drupal (8 and later). In a Drupal site, or a module or theme opened on its own, the
    names its YAML files declare are references: services (\Drupal::service(),
    $container->get()), routes (Url::fromRoute(), redirect(), setRedirect()),
    permissions, libraries ('#attached' => ['library' => […]]), configuration and
    modules. So are the entity types and plugins that attributes and annotations declare,
    the theme hooks of hook_theme() ('#theme' => '…', with the template), and hooks
    (invokeAll(), alter(), #[Hook] ↔ the hook_…() function). Each completes, goes
    to its declaration, has Find References and a hover; services, routes, permissions and
    libraries are renamed with the YAML files that name them.

    • Types: \Drupal::service('id') and $container->get('id') are the service's
      class; getStorage('node') is the entity type's storage, and what it loads is the
      entity; the parameters of a hook's implementation (mymodule_form_alter(), a method
      with #[Hook]) have the types the hook's function gives them.
    • .module, .install, .theme, .profile, .engine and .inc files are PHP: they
      are indexed, the server watches them, and the VS Code extension opens them as PHP.
    • The templates folder of a module or theme is the Twig namespace of its name
      (@shop/card.html.twig).
    • The YAML files are answered in too: Go to Definition, hover, Find References, Rename
      and completion on the services, routes, permissions and libraries they name, and
      Go to Definition on their classes and controller methods. The server asks the client
      for *.yml files only while a Drupal project is open.
    • Configuration keys (\Drupal::config('shop.settings')->get('mail.from')), the
      plugins a links or layouts file declares, derivative plugin ids, theme hook
      suggestions (node__article) and the preprocess functions of a theme hook.
    • Go to Definition on the name of a function implementing a hook goes to the hook.
    • A template completes the variables its theme hook declares, and
      attach_library('…') in it is a library.
    • *.api.php files, which document hooks as empty functions, no longer report unused
      parameters.
    • A template's variable has the type a preprocess function assigns it
      ($variables['book'] = …), so {{ book.title }} completes.
    • A configuration only a schema describes (config/schema) has its name and keys;
      migrations and breakpoints are plugins; a #[Hook] on a class types the method it
      names.
    • In a YAML file, a line is read under the key above it (list items, bracketed lists
      over several lines), service.id:method is a service and its method, and class
      names complete after class: and _controller:.
    • Drupal 7: a site or a module with a .info file is detected; module_invoke_all(),
      drupal_alter(), theme(), user_access() and module_exists() name hooks, theme
      hooks, permissions (hook_permission()) and modules, and a hook's implementation
      is typed and goes to its hook.
    • More of Drupal 7: menu paths (drupal_goto('admin/shop') ↔ hook_menu(), also
      through % placeholders), variables (variable_get() ↔ variable_set()), a form's
      function in drupal_get_form(), and its .info files (dependencies[], files[]).
    • ->get('key') on a configuration has the type its schema gives the key; a template's
      variable has the type a render array passes it ('#book' => $book).
    • In a YAML file, a mapping in braces and an alias (*defaults) are read.
    • Database tables: db_select('node') and the connection's select(), insert()…
      go to the table's entry in hook_schema(), and a column of a query
      ($query->condition('n.nid', 5), ->fields('n', ['title'])) goes to its field
      there and completes, along a chain of calls and through the alias of a joined table
      (u.uid after ->join('users', 'u', …)).
    • A configuration key also takes its type from the value a file installs; a render
      array built up in a function ($build['#book'] = $book) types its template's
      variable.
    • Nothing of Drupal is bundled.
  • The YAML reader follows anchors and aliases (&defaults, *defaults) and merges
    <<: *defaults: a Symfony or Drupal service defined that way has its class.

  • A callback under a key named as one (callback, …_callback, …_cb, page callback) is a callable in any array, not only one that is a call's argument:
    $items['x'] = ['access callback' => 'my_access'];.

  • A string under a key of an array can be a reference wherever the array is written
    (CalleePattern::Entry): Drupal's render arrays use it.

  • WordPress. In a WordPress project (its core, a plugin or a theme), the names
    WordPress keeps in its registries are references: hooks (add_action('init', …) ↔
    do_action('init'), filters alike), shortcodes, post types, taxonomies, script and
    style handles, options, image sizes, menu locations, blocks (registered in PHP or
    declared by a block.json) and REST routes (rest_url('shop/v1/books') ↔
    register_rest_route('shop/v1', '/books'), patterns in the route included). A
    list of names counts where one is taken (is_singular(['book', 'page']),
    'post_type' => ['book']). Each completes, goes to the
    call that fires or registers it, has Find References and a hover, and is renamed when
    the project declares it itself (not a name of WordPress or of a library). A hook fired
    under a name put together at run time ("save_post_{$post->post_type}") is found by
    its pattern.

    • get_template_part('template-parts/content', 'page') goes to the theme's file and
      completes the theme's templates. So do get_header('shop'), get_footer(),
      get_sidebar(), locate_template(), get_theme_file_path() and
      get_theme_file_uri(). A child theme's file is looked for first, then its parent's.
    • Find References lists the project's scripts too, searched as text: a block's name, a
      REST route's path, and the action of an AJAX request for its wp_ajax_… hook.
      Renaming a block, the last part of a REST route or the action of an AJAX hook
      changes PHP, the scripts and the block.json.
    • In a script and in a block.json, a string naming a block, a REST route or an AJAX
      action has Go to Definition, hover, Find References, Rename and completion. The
      server asks the client for those documents only while a WordPress project is open
      (it registers for them, and unregisters when none is left): in other projects
      scripts aren't sent to it.
    • A hook's callback knows what the hook passes: the parameters of a closure given to
      add_action() or add_filter(), and of a function or method registered by name
      ('shop_saved', [$this, 'saved']), take the types the docblock at the firing call
      documents.
    • global $wpdb, $post; has the types the @global tags document: the function's
      own, else what the project's functions (WordPress's among them) say of that name.
      So have $GLOBALS['wpdb'] and a variable a file reads at its top level without
      setting it (a theme's template reads $post). This holds in any PHP project.
    • Callbacks given under a key of an array (register_rest_route(…, ['callback' => [$this, 'run']]), sanitize_callback, render_callback…) are string callables
      like the others.
    • PhpUndefinedHook reports a hook listened to that nothing fires. It is off until
      turned on ("PhpUndefinedHook": { "enabled": true }): a hook may be fired by a
      plugin that isn't in the workspace.

    Nothing of WordPress is bundled. A plugin or theme opened on its own knows WordPress's
    functions and hooks from a stubs package installed with Composer
    (php-stubs/wordpress-stubs) or from a WordPress folder named in includePaths.

  • The status item names the frameworks of the open projects (Phoxite: WordPress,
    Phoxite: Laravel, Symfony), not only Laravel. The server says them in
    phoxite/laravel/status and phoxite/laravel/statusChanged (frameworks).

  • The stubs setting's description no longer names a wordpress stub set: there is
    none.

  • A string that names a function or a method where a callable is expected is a name like
    any other: array_map('App\\trim_all', …), call_user_func('Foo::make'),
    usort($rows, [$this, 'compare']), [Foo::class, 'make']. Go to Definition and hover
    work on it, Find References counts it, and renaming the function, the method or the
    class changes it (before, a rename left these strings as they were). Function names
    complete inside such a string, and method names in [$o, '…'] and after 'Foo::. The
    same for a string a function declared to return a callable returns, and one assigned to
    a property typed as a callable. Only where a callable is expected and nothing else a
    string could be: for callable|string the string is left alone.

  • In a Symfony project, the template names PHP writes (render(), renderView(),
    renderBlock(), renderForm(), stream() on a controller; render(), display(),
    load() on Twig's environment) complete, go to the template, and have Find References
    (the PHP strings and the templates naming it) and hover.

  • PhpUndefinedTemplate: a Twig template PHP names that the project's template folders
    don't have. Not for a @Namespace/… name, which can be a bundle's, nor in a project
    without any template.

  • #[Template('page.html.twig')] names a template, and #[Autowire(service: 'mailer')]
    and #[Autowire(param: 'app.locale')] a service and a parameter: an attribute's
    arguments are read like a call's.

  • Service ids and parameters are renamed: the key in the YAML file, the PHP strings, the
    attributes, and @mailer / %app.locale% in the YAML files below config/, which are
    Find References' too. A service whose id is its class name isn't renamed this way.

  • XLIFF (.xlf, .xliff; 1.2 and 2.0) and JSON translation catalogues are read beside the
    YAML ones, and translation keys complete before |trans in a template.

  • Translation keys are renamed: in every catalogue, in PHP and in the templates. Of a
    nested key (form: { title: … }) the last part is renamed, to a name without a dot.

  • A service after alias: or parent: in a YAML file is a usage of it, and the
    parameters and services of the files in config/packages are known without a services
    file importing them.

  • In a template, a member of what the controller passes (post.title, post.author.name)
    has a hover with its type and goes to the property, or to the getter Twig calls.

  • The usages of a route, a template or a translation key, and their renames, read a Twig
    template with unsaved changes as the editor has it.

  • A Twig template knows what the controller rendering it passes: the keys of
    render('page.html.twig', ['post' => $post]) complete as variables with their types, and
    after a . the public properties and methods of the variable's class do, a getter under
    the name Twig reads it by (getTitle() as title). A {% for %} loop's variable is an
    element of what the loop goes through.

  • The filters, functions and tests a project's own Twig extensions add (new TwigFilter('price', …), #[AsTwigFilter('price')]) complete in templates, and go to
    where PHP names them.

  • Translation keys ($translator->trans('form.title'), new TranslatableMessage(…),
    t(), and 'form.title'|trans in a template) complete from the YAML catalogues of
    translations/, go to the key in every locale, and have Find References and a hover
    with the translations.

  • Doctrine: a property with #[ORM\OneToMany(targetEntity: Comment::class)] or
    #[ORM\ManyToMany] declared as a bare Collection is a Collection<int, Comment>, and
    one with #[ORM\ManyToOne] or #[ORM\OneToOne] and no class in its type is the target.
    The keys of a repository's findBy([...]), findOneBy([...]) and count([...]) complete
    with the entity's fields and go to the property.

  • Service ids ($container->get('mailer'), has()) and parameters (getParameter('app.locale'),
    a parameter bag's get()) complete from the project's services files, go to their key in
    the YAML file, and have Find References and hover. They aren't renamed yet.

  • Rename of a Twig template, from PHP or from a template naming it: the file moves, and its
    name changes in every PHP string and every {% extends %}, {% include %} and the like.

  • Route names inside a template's path('…') and url('…') complete, go to the route,
    and are usages of it: Find References on a route lists the templates too, and renaming a
    route renames it there.

  • Twig templates (*.twig) are served: the outline; completion of tags, filters,
    functions, tests, the variables and macros in scope and template names; hover on the
    built-ins and on macros; Go to Definition for template names, macro calls and the block a
    block overrides; Find References on a template name; Rename of a block (in every template
    of its extends and use family) and of a macro (where it is declared, imported and
    called); Format Document, which indents every line by the HTML elements and Twig blocks around it
    and puts the spacing inside the tags right ({{x|upper}} → {{ x|upper }}), without
    moving anything to another line (the code of a <script> or a <style> is indented by
    its brackets); semantic tokens; and
    syntax errors as you type. A tag Twig itself doesn't have is not an error, since
    extensions add tags, and "TwigSyntax": { "enabled": false } under inspections turns
    the errors off. With Symfony's Twig bridge installed, its tags, filters and functions
    are known too. None of it needs the index.

  • Format Document can use the project's Prettier for Twig templates: format.twig
    (phoxite.format.twig in VS Code) set to prettier runs node_modules/prettier on the
    template's text, with the project's Prettier configuration and its Twig plugin
    (@zackad/prettier-plugin-twig, say). Prettier also rewraps lines and formats the
    JavaScript and CSS inside, which the built-in formatter doesn't. In a trusted workspace
    only; without Prettier, for a selection, and when Prettier fails, the built-in formatter
    answers. analyzers.nodePath names the Node.js that runs it (node on PATH when
    empty). Tested against a stand-in and, by hand, against Prettier 3 with that plugin.

  • The VS Code extension has a Twig language: highlighting in the text, inside HTML tags
    and attribute values and in scripts and styles, snippets for the tags, and a warning when
    another extension defines the language too.

  • phoxite-lsp check reports the syntax errors of the Twig templates in the project's
    template folders (TwigSyntax).

  • Clients are asked to watch *.twig and the YAML files below config/: a route or a
    service added to a YAML file outside the editor is known without a restart.

  • Symfony route names (generateUrl(), redirectToRoute(), a URL generator's
    generate(), path() and url()) have Go to Definition, Find References, Rename and
    hover: to the key in a YAML routes file or the name of the #[Route] attribute.
    Renaming a route whose class has a name prefix changes the part the attribute writes.
    Completion and the undefined-route warning work as before.

  • Completion, hover, Go to Definition and Rename work in strings inside attributes
    (#[Route('/x', name: 'home')]): the # of #[ was read as the start of a comment.

  • A new setting, frameworks (phoxite.frameworks in VS Code), turns each framework's
    support enabled or disabled; auto, the default, detects it. frameworks.laravel
    wins over laravel.detection unless it is auto. Laravel, Symfony,
    WordPress, Drupal and CodeIgniter have support today; the other names (yii,
    cakephp, laminas, magento) are read now and take effect as each one's support is
    released.