Skip to content

buggy auto-indent inside array syntax [] and array() #138

Description

@carestad

Summary

Pressing Enter inside short array syntax [] does not indent the new line. Array elements are only indented when using the legacy array() form, which has a matching curly-brace pattern in indents.scm.

Steps to reproduce

  1. Open a .php file.
  2. Type $foo->bar([ or array( and press Enter.

Actual behavior

$foo->bar([
new line starts at column 0
]);
$foo = array(
new line starts at column 0
);

Expected behavior

$foo->bar([
    new line indented one level
]);
$foo = array(
    new line indented one level
);

Environment

Zed: v1.13.1
OS: Ubuntu 24.04
PHP extension: v0.5.1

Reproduced on a fresh Zed profile (isolated HOME) with only the PHP extension installed and no custom settings, so this is not caused by other extensions or user configuration. if, foreach, and try blocks all indent correctly in the same environment - only short array syntax fails.

Suggested fix

languages/php/indents.scm currently only matches curly-brace nodes. Adding:

(array_creation_expression "]" @end) @indent
(array_creation_expression ")" @end) @indent

resolves it. I've tested this locally against the installed extension and it produces the expected indentation.

Edit: added PR to fix it: #139

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions