Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JimNayzium's avatar

VSCODE Extension Question / Line height

Does anyone use or know of an extension that will do this: Make the lineHeights between code and comments different from the lineHeight between code and code?

So in our code base we could type things like this:

 if ($foo === $bar) {
		$insane = null;
}
// amazingly efficiently written comment
$fooBar = $insane ??= $weAlreadyKnow;
// another efficient comment
$surprisedYouAsk = false;

And then it would automatically format itself with lineHeight separations like this:

if ($foo === $bar) {
		$insane = null;
}

// amazingly efficiently written comment
$fooBar = $insane ??= $weAlreadyKnow;

// another efficient comment
$surprisedYouAsk = false;

But in the best case scenario the lineHeight after curly braces and before comments would not be the same full lineHeight but have its own setting like this:

lineHeight: 1.625,
lineHeightAfterCurlyBracesBeforeComments: 1.375,
lineHeightAfterCommentBeforeCode: 1.00,

As it stands now, prettier does allow for some extra goodness to customize things a bit, but all its solutions assume the lineHeight on every line is the same. So it allows for treatement of manually inserted hard-returns to be taken away and what not, but that never quite scratches my itch.

I want a world where the comments are more closely tied to the next line of code than the lines of code are tied to each other. WHILE also that different space is SMALLER than the regular lineHeight on the editor window in general.

Does that make sense?

I realize most people on here will tell me to update to PHP Storm as they read this, and I understand! I bought it a year ago when I first dove into the Laravel world! But it just was so frustrating spending so much time on "this is how I do that in Storm" type issues when VsCode setup for me was just never really broken.

I never think to myself that I am not being productive in VsCode, and I love the DevSense PHP extension for VsCode. I did love all the Laravel built in cheat-codes of Storm but I found myself waisting so much other time in Storm that I gave up after a few days. šŸ˜„

0 likes
1 reply
LaryAI's avatar
Level 58

Unfortunately, Visual Studio Code does not natively support different line heights for different types of content (e.g., code vs. comments) within the editor. The line height setting in VSCode is global and applies uniformly across all lines of text.

However, you can achieve a similar effect by using a combination of extensions and settings to format your code in a way that visually separates comments from code. Here are a few suggestions:

  1. Prettier and Custom Formatting Rules:

    • While Prettier doesn't support different line heights, you can configure it to add or remove blank lines around comments to visually separate them from code. You can use the prettier extension and configure it to add blank lines before or after comments.
  2. EditorConfig:

    • Use an .editorconfig file to enforce consistent formatting across your project. While it won't change line heights, it can help maintain consistent spacing and indentation.
  3. Custom VSCode Theme:

    • You can create or modify a VSCode theme to visually differentiate comments from code by changing the font style, color, or weight of comments. This won't change the line height but can make comments stand out more.
  4. Code Snippets:

    • Create custom code snippets that automatically insert comments with the desired spacing. This can help maintain consistency when writing new code.
  5. Custom Extension:

    • If you're comfortable with JavaScript and the VSCode API, you could develop a custom extension that formats your code in the desired way. This would involve writing a formatter that inserts blank lines or adjusts spacing around comments.

Here's a basic example of how you might configure Prettier to add blank lines around comments:

// .prettierrc
{
  "proseWrap": "always",
  "printWidth": 80,
  "overrides": [
    {
      "files": "*.php",
      "options": {
        "insertPragma": true,
        "requirePragma": true
      }
    }
  ]
}

This configuration doesn't directly address line height but can help with spacing around comments. For more advanced formatting, consider writing a custom script or extension.

Ultimately, achieving different line heights for comments and code would require a feature that VSCode currently does not support. You might consider submitting a feature request to the VSCode team if this is a critical need for your workflow.

Please or to participate in this conversation.