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

Hide files with given glob patterns #150

Merged
merged 4 commits into from
Mar 10, 2018
Merged

Hide files with given glob patterns #150

merged 4 commits into from
Mar 10, 2018

Conversation

econtal
Copy link
Contributor

@econtal econtal commented Nov 25, 2017

This MR allows to hide certain files in the list, using their extension. Example: hides .pyc files.

@Osmose
Copy link
Owner

Osmose commented Nov 27, 2017

Thanks for the PR! Reviewing this is in my todo list, I'll get to it when I can. :D

Copy link
Owner

@Osmose Osmose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for the PR, I really like this feature! Hiding pyc files by default would be clutch.

lib/models.js Outdated
@@ -58,6 +58,16 @@ export class Path {
return this.stat ? !this.stat.isDirectory() : null;
}

isVisible() {
ignoredFiles = config.get('ignoredFiles');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to declare variables with const if they don't change, or let if they do.

lib/config.js Outdated
@@ -45,5 +45,11 @@ export let config = {
details.`,
type: 'boolean',
default: false,
},
ignoredFiles: {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignoredExtensions is a more accurate name for this config setting, since the value doesn't contain files, but extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to ignoredPatterns since it now uses glob patterns.

lib/config.js Outdated
ignoredFiles: {
title: "Ignore files with these extensions",
description: "Don't show files with the given extensions.",
type: 'string',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atom allows for array config values, which would be appropriate here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to array of string

lib/models.js Outdated
ignoredFiles = config.get('ignoredFiles');
if (!ignoredFiles) return true;
ignoredExtensions = ignoredFiles.split(',');
for( i in ignoredExtensions) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A for...of loop would work nicely here.

lib/models.js Outdated
if (!ignoredFiles) return true;
ignoredExtensions = ignoredFiles.split(',');
for( i in ignoredExtensions) {
if(this.fragment.endsWith(ignoredExtensions[i])) return false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little torn here, because this isn't strictly extension matching, it's suffix matching. Which is fine, but then the natural next step is to add prefix matching, etc. Maybe a list of regexes to check against the file?

Also, it might be more performant to add this ignoring logic to the matchingPaths method instead of adding isVisible, which would avoid creating a new Path object for paths that aren't going to be displayed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied these suggestions in the last commit: using globs (which I find more natural than regexp for filename); moved to the matchingPaths method; compile one and cache regexps for performances.

@econtal econtal changed the title Hide files with given extensions Hide files with given glob patterns Dec 10, 2017
@econtal
Copy link
Contributor Author

econtal commented Dec 10, 2017

Thanks for the suggestions. I updated the PR which now uses glob patterns instead of suffixes. It uses minimap as a backend to compute the matching. The Minimap objects are compiled once and then cached to optimize performances.

@econtal
Copy link
Contributor Author

econtal commented Jan 13, 2018

Hi @Osmose: please let me know, when you have time, if you have other suggestions!

Copy link
Owner

@Osmose Osmose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, I was out for the break and this has been sitting at the bottom of my todo list ever since. :(

This is really close though. Once the bit about the caching is dealt with I think this will be ready to land and ship. Nice work!

lib/utils.js Outdated
* the regexp.
*/
export function ignoredPatterns() {
if (this.minimatches === undefined ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure what this is set to when the function is imported into another file. Is it the global for this module?

In any case, just adding a let _minimatches = null; above the function and using that instead would clear that confusion up.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this caching means that changes to the preference wouldn't take effect in existing windows. I can think of two solutions to this:

  1. Make the cache and object keyed by the glob patterns, and re-fetch the config each time. That way we always get the current config, but can cache minimatch objects.
  2. Add an observer for changes to the config and invalidate the cache when the config changes.

Either would be fine IMO. The former seems easier.

"osenv": "^0.1.3",
"touch": "^1.0.0"
"touch": "^1.0.0",
"stringmap": "~0.2.2"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: stringmap is already used a dependencies of dependencies, so this shouldn't increase load time

@econtal
Copy link
Contributor Author

econtal commented Mar 10, 2018

Sorry for this delay before updating the PR. I appreciated the above comments and did my best to address them. Thanks for the ideas!

@Osmose
Copy link
Owner

Osmose commented Mar 10, 2018

Thanks for this! I realized I totally forgot to mention tests and will add one or two before merging this, and will do a release shortly after.

@Osmose Osmose merged commit ba1f1ca into Osmose:master Mar 10, 2018
@Osmose
Copy link
Owner

Osmose commented Mar 10, 2018

@pdxwolfy
Copy link

pdxwolfy commented Apr 8, 2018

Nice feature!

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

Successfully merging this pull request may close these issues.

3 participants