Skip to content

Spaces and Tab indentation not reflecting in Snippet #15846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
itsmewes opened this issue Aug 6, 2024 · 4 comments
Open
1 task done

Spaces and Tab indentation not reflecting in Snippet #15846

itsmewes opened this issue Aug 6, 2024 · 4 comments
Labels
bug [core label] editor Feedback for code editing, formatting, editor iterations, etc snippets tooling An umbrella label for language tools, linters, formatters, etc

Comments

@itsmewes
Copy link

itsmewes commented Aug 6, 2024

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

I have seen some issues talking about snippets and indentation, but they are edge cases where spaces and tabs are working, but the line after the snippet doesn't indent or something similar, not about or \t not working out the box.

When running a snippet, spaces and/or tabs are not output. For example the below snippet:

{
    "PHPUnit Class": {
        "prefix": "ptest",
        "body": [
            "<?php",
            "",
            "declare(strict_types=1);",
            "",
            "namespace Tests$2;",
            "",
            "use Tests\\TestCase;",
            "use Tests\\Traits\\ShouldNotUseDatabase;",
            "",
            "class $1Test extends TestCase",
            "{",
            "\tuse ShouldNotUseDatabase;",
            "",
            "\tpublic function test$3(): void",
            "\t{",
            "\t\t$0",
            "\t}",
            "}"
        ],
        "description": "Skeleton for a PHP Unit class"
    }
}

Produces the below PHP code where there is no indentation at all.

<?php

declare(strict_types=1);

namespace Tests;

use Tests\TestCase;
use Tests\Traits\ShouldNotUseDatabase;

class Test extends TestCase
{
use ShouldNotUseDatabase;

public function test(): void
{

}
}

Another nice to have would be that the snippet adheres to the tab stop that it was run on. Every time I run a snippet when tabed in it will remove any indentation and put the snippet against the left side.

Environment

Zed: v0.147.2 (Zed Preview)
OS: macOS 14.5.0
Memory: 16 GiB
Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

snippets.mp4

If applicable, attach your Zed.log file to this issue.

Zed.log
@itsmewes itsmewes added admin read bug [core label] labels Aug 6, 2024
@notpeter notpeter added editor Feedback for code editing, formatting, editor iterations, etc snippets tooling An umbrella label for language tools, linters, formatters, etc and removed triage labels Aug 9, 2024
@ThisGuyCodes
Copy link

just here to add another example:

{
  "dependency block": {
    "prefix": "dependency ",
    "body": [
      "dependency \"${1:name}\" {",
      "  config_path                             = \"${2:path}\"",
      "  mock_outputs_allowed_terraform_commands = [\"validate\"]",
      "  mock_outputs = {",
      "    ${3:key} = \"${4:value}\",",
      "  }",
      "}",
      "${0}"
    ],
    "description": "Add a dependency block"
  }
}

and this is what comes out:

dependency "name" {
  config_path                             = "path"
  mock_outputs_allowed_terraform_commands = ["validate"]
mock_outputs = {
  key = "value",
}
}

I tried to figure out the pattern on when indentation is respected and when not, but I couldn't discern anything 🤷🏻

@machin3io

This comment was marked as spam.

@BartolomeyKant
Copy link

Added comment under another issue #18481 (comment)

@andyw8
Copy link
Contributor

andyw8 commented Apr 23, 2025

I ran into this when trying to add snippets to the Ruby extension.

zed-extensions/ruby#53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] editor Feedback for code editing, formatting, editor iterations, etc snippets tooling An umbrella label for language tools, linters, formatters, etc
Projects
None yet
Development

No branches or pull requests

6 participants