Workspace Scan not using regex


#1

I am using the following regex as part of my workspace.scan. However the iterator is returning pretty much every file in the project. I’m trying to trigger a file to open just based on clicking the name. I am passing the regex in as a string because it threw an error when I tried otherwise.

"/^(.*?(\bMyFile.js\b)[^$]*)$/g"

@leedohm


#2

When you pass a string to the function, then it isn’t a regular expression. You also shouldn’t need the g modifier, it should already search globally. I also suspect you can simplify the regular expression to /\bMyFile\.js\b/


#3

I found out that the scan is actually searching the contents of the files rather than the file names. I looked through the options and I do not see an option to just look at the file names. Any thoughts?


#4

You can use atom.project.getPaths to get the root paths and then use standard Node.js APIs to search those paths for files.


#5

Thanks! I combined that with node-glob and got what I was looking for.


#6

If you want to be consistent with Atom own globbing you should probably go with minimatch instead. It’s used in packages such as fuzzy-finder and probably many others, and if you need to expose a setting for that users won’t feel confused by the possible differences in the implementations.