Sublime Forum

Conditionally Exclude Files?

#1

I’m not sure if this is a feature request (or a request for support) so putting it in here.

Essentially I want to hide .js files and .d.ts files, but only if there is a matching .ts file. This is because most of the time I’m working with JavaScript, but every now and again I need to work with something else (such as TypeScript) which transpiles into JavaScript. The downside is my navigation bar becomes very cluttered and goto file is harder to use. Example:

api.ts
api.d.ts     // should hide
api.js        // should hide
lambda.js // should not hide

Is there a way to conditionally hide a file? If not I’d like to raise a feature request. This is something I managed to achieve within VSCode like this for reference:

files.exclude": {
    "**/*.js": {
      "when": "$(basename).ts"
    },
0 Likes

#2

It’s not possible to conditionally hide files in this manner, no; so in that regard this is more of a feature request.

That said, if you configure the TypeScript compiler to generate it’s output and map files into a folder like dist or such, you can exclude that folder (similar to hiding the .obj directory of compiled code).

0 Likes

#3

Thanks, feature request it is then :slight_smile:

I’m not sure I want to monkey around too much with the TypeScript compiler as it’s all pre-configured in this project. It means I’d end up changing the structure of the project just to support my editor, there’d be a lot of push back just to use a different editor (hence me having VSCode too).

0 Likes

#4

I think that is a pretty neat feature

0 Likes

#5

If you were willing to rename lambda.js to lambda.ts, you could exclude <that_tree>/*.js and <that_tree>/*.d.ts. And it would work as desired.

0 Likes

#6

You could write a plugin to update your project settings for you and add the excludes dynamically.
I dont think that would be that difficult.

0 Likes

#7

Thanks for the suggestion. My challenge is this isn’t necessarily project based, I have a mix within the same project (which I imagine is quite common with monoreps or people migrating to TypeScript). Unless you did it file by file which doesn’t seem very clean compared to a condition.

0 Likes