Skip to content

Snippets do not retain spacing and formatting #18481

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

Closed
1 task done
monarcode opened this issue Sep 28, 2024 · 2 comments · Fixed by #31933
Closed
1 task done

Snippets do not retain spacing and formatting #18481

monarcode opened this issue Sep 28, 2024 · 2 comments · Fixed by #31933
Assignees
Labels

Comments

@monarcode
Copy link

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

When snippets are expanded, the spacing / formatting defined in the snippet.json is ignored, the expanded snippets only apply spaces once

see screenshot and recording below

Screenshot 2024-09-28 at 3 39 25 PM

this screenshot shows my defined snippets in a tsx.json file in the snippets directory, notice the way the snippet code is formatted

here is a video recording showing me attempting to use said snippets, notice how when expanded they do not have the same spacing / formatting
https://www.loom.com/share/eb3fd3452c764fbcb46418705429ce24?sid=21fe77c5-978d-4264-a66f-0bc12a0ee7c4

Environment

Zed: v0.154.3 (Zed)
OS: macOS 15.0.0
Memory: 32 GiB
Architecture: aarch64

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

Zed.log
@monarcode monarcode added admin read bug [core label] crash [core label] labels Sep 28, 2024
@notpeter notpeter added editor Feedback for code editing, formatting, editor iterations, etc tooling An umbrella label for language tools, linters, formatters, etc snippets and removed triage crash [core label] labels Oct 10, 2024
@BartolomeyKant
Copy link

Have the same issue with c++ snippets.

I tried to add apache license snippet.

"apache license": {
    "prefix": "apache",
    "body": [
      "/*",
      " * Copyright 2024 Aethernet Inc.",
      " *",
      " * Licensed under the Apache License, Version 2.0 (the \"License\");",
      " * you may not use this file except in compliance with the License.",
      " * You may obtain a copy of the License at",
      " *",
      " *     http://www.apache.org/licenses/LICENSE-2.0",
      " *",
      " * Unless required by applicable law or agreed to in writing, software",
      " * distributed under the License is distributed on an \"AS IS\" BASIS,",
      " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.",
      " * See the License for the specific language governing permissions and",
      " * limitations under the License.",
      " */"
    ],
    "description": "Add an apache license preamble"
  }

Notice this extra space to align all * in vertical.
After applying it to document, this looks like this.
Image
All spaces at the beginning are gone.

@notpeter
Copy link
Member

Note, additional examples that should be validated when fixing this issue:

@notpeter notpeter removed bug [core label] tooling An umbrella label for language tools, linters, formatters, etc editor Feedback for code editing, formatting, editor iterations, etc labels May 30, 2025
@osiewicz osiewicz removed their assignment Jun 2, 2025
@mgsloan mgsloan self-assigned this Jun 2, 2025
@mgsloan mgsloan moved this from Todo to Done in Quality Week - Spring 2025 Jun 3, 2025
mgsloan added a commit that referenced this issue Jun 3, 2025
Closes #18481

Release Notes:

- Snippet insertions now preserve leading whitespace instead of using
language-specific auto-indentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants