Find, ignoring comments


#1

Does anyone know of an existing way to have the Find / Replace functionality ignore things that the syntax editor considers “comments”?

Or know what you would have to do to make that happen?


#2

There isn’t a way to do what you’re asking right now. And this isn’t something that we would add to the built-in find-and-replace package.

There are a few different ways that you could do it. None of them sound very performant. Basically you would have to either gather all the results and then iterate through them to figure out which are within comments … or you would have to find all the areas of comments and create selections of all the other space in the file to search within.


#3

I don’t believe this would be too hard. On finding a match for the search term, it could check editor.scopeDescriptorForBufferPosition(pos), use array.some() to compare the result to an array of scopes that shouldn’t be searched, and drop that result if it comes up true. Would that really be so many extra steps as to cause performance issues?