Skip to content
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

vscode: show _templ.go files greyed out? #730

Closed
jwarlander opened this issue May 6, 2024 · 8 comments
Closed

vscode: show _templ.go files greyed out? #730

jwarlander opened this issue May 6, 2024 · 8 comments

Comments

@jwarlander
Copy link

It would be nice if the generated *_templ.go files could be greyed out in the tree view in VS Code, either by default or as an option, just to indicate that one probably doesn't want to edit those, and that it's the .templ files that are important.

Perhaps one could even indicate that _templ.go files are stale by some kind of marker, if they have an older timestamp than the corresponding .templ file..

I'm not super familiar with TypeScript, or how VS Code plugins work in general, but I'm guessing something like how files in .gitignore are handled would be applicable:

https://github.com/microsoft/vscode/blob/4a6ebe0ee5b2d13435e42416640b69d1a1004289/extensions/git/src/decorationProvider.ts#L14-L85

@a-h
Copy link
Owner

a-h commented May 6, 2024

Nice idea. Here's some options.

1. Enable file nesting

By adding this to the package.json of the templ VS Code plugin:

  "contributes": {
    "configurationDefaults": {
      "explorer.fileNesting.enabled": true,
      "explorer.fileNesting.patterns": {
        "*.templ": "${capture}_templ.go"
      }
    },

Nesting is enabled, and you see this:

Screenshot 2024-05-06 at 16 41 58

And you can expand it to:

Screenshot 2024-05-06 at 16 42 25

2. Hide _templ.go files by default

Adding this to package.json simply hides the _templ.go files by default:

  "contributes": {
    "configurationDefaults": {
      "files.exclude": {
        "**/*_templ.go": true
      }
    },
image

Summary

Can either enable nesting, or hide the _templ.go files by default. I'm not sure which one people would prefer.

@indaco
Copy link

indaco commented May 6, 2024

Why not allow both the options via plugin settings?

Anyhow, my personal preference would be for option 1

@a-h
Copy link
Owner

a-h commented May 6, 2024

Reasonable. It's also possible to enable commands like "showGeneratedFiles". We do this already for "templ.restartServer"`.

3: Grey out the filename in explorer

Updating the activate function in main.ts:

export async function activate(ctx: vscode.ExtensionContext) {
  try {
    ctx.subscriptions.push(
      vscode.commands.registerCommand(
        "templ.restartServer",
        startLanguageClient
      )
    );

    vscode.window.registerFileDecorationProvider(formatGeneratedFilesInExplorer);

    await startLanguageClient();
  } catch (err) {
    const msg = err && (err as Error) ? (err as Error).message : "unknown";
    vscode.window.showErrorMessage(`error initializing templ LSP: ${msg}`);
  }
}

const formatGeneratedFilesInExplorer: vscode.FileDecorationProvider = {
  provideFileDecoration: async (uri) => {
    if (uri.path.endsWith('_templ.go')) {
      return {
        color: new vscode.ThemeColor('gitDecoration.ignoredResourceForeground')
      };
    }
    return undefined;
  }
};

Produces this effect:

Screenshot 2024-05-06 at 18 15 04

Note how the filename is greyed out.

@joerdav
Copy link
Collaborator

joerdav commented May 7, 2024

Nesting seems the most sensible to me, its the default behavior of the goland plugin too.

@jwarlander
Copy link
Author

Either nesting or greyed out files would work quite well, I think, and make it clearer what parts to focus on in the explorer! 🎉

Hiding them completely might be confusing.

@ddelpero
Copy link

ddelpero commented May 7, 2024

Options 1 and 2 can be set in the vscode Settings without changing anything in the extension.

Edit: option 2 is really great. It makes it much easier to focus on the templ files and not be distracted by the _templ.go files. Ctrl+p also excludes them so searching for file names shows less results too.

@a-h
Copy link
Owner

a-h commented May 12, 2024

We have consensus on enabling file nesting (option 1)?

I don't think we can realistically do option 2 in that list until #726 and #415 are dealt with.

And option 3 is basically just abusing git decorations. 😁

So, time to implement option 1 for now.

@a-h
Copy link
Owner

a-h commented May 12, 2024

Fixed in templ-go/templ-vscode@913c9b8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants