psi-header icon indicating copy to clipboard operation
psi-header copied to clipboard

Request for file-specific header comments

Open LeifWebber opened this issue 8 months ago • 2 comments

Request for file-specific header comments

Issue Description

I'm requesting a feature to add specific comment types for specific files.

SCSS is a CSS preprocessor that compiles all SCSS files into CSS files, including comments. Since each SCSS file has a header comment generated by the plugin, this results in the compiled CSS file containing multiple redundant comments accumulated from each SCSS file.

Proposed Solution

My proposed solution is:

Configure SCSS files to generate line comments like this:

// 
// Copyright © 2025 LeavesWebber
//
// SPDX-License-Identifier: MPL-2.0
//
// Feel free to contact [email protected]
//

Since these are line comments, they won't be included in the generated CSS file (due to SCSS behavior where line comments are omitted during compilation).

Specifically for main.scss only, use block comments:

/*
 * Copyright © 2025 LeavesWebber
 *
 * SPDX-License-Identifier: MPL-2.0
 *
 * Feel free to contact [email protected]
 */

This approach ensures that the generated CSS file only includes comments once.

Limitation

One drawback to this approach:

For a structure like this:

├── scss/
│   ├── base/               // Reset, typography, base styles
│   │   ├── *reset.scss
│   │   └── *typography.scss
│   ├── components/         // Buttons, cards, modals, etc.
│   │   ├── *buttons.scss
│   │   └── *cards.scss
│   └── main.scss           // Main SCSS file that imports all others
│   └── admin.scss          // Optional: Another entry point for a specific section

CSS files generated from admin.scss would unintentionally have no comments at all.

LeifWebber avatar May 16 '25 04:05 LeifWebber

Hmmmm - interesting idea and I understand your issue. I need to make sure that this change not only respects initial insertion of the headers, but also on save where the extension can be configured to check that there is a header that it is expecting.

It might be a better option to extend the language templates to allow you to declare a file name (rather than just file extension or VSCode language code). That would simplify a lot of other checks in the header and also solve your problem with admin.scss. A possible problem is that under some circumstances, VSCode might not report the actual filename until after the file has been saved so I will need to check that. There might be other alternatives, but I will take a look at it.

I can't look at this for the next 2 weeks, but should be able to investigate after that.

Regards D

davidquinn avatar May 17 '25 08:05 davidquinn

Setting rules based on specific filenames might not be a good idea. It would be better to configure rules like this:

For files with paths like scss/*.scss, generate block comments; and for files in subfolders like scss/components/*.scss, generate line-level header comments. This might solve the problem.

LeifWebber avatar May 21 '25 09:05 LeifWebber