Search in all namespaces
Hi Team,
Is there a way to search for a string or use of a function in all namespaces in one go.
Studio option "Search in files"/Ctrl+shift+F search all files in the current namespace. We have 13 namespaces and wanted to know if there is an easy way to search in all namespaces in one go.
Thank you for your help
Product version: HealthShare 2023.1
@Mary George
There are two ways you could do this:
First, I presume, the Studio lacks such a functionality because usually each nsp contains independent data. As an example, for each of my customers (applications) I have an dedicated namespace (of course, you may say, one can allways have an exeption),
and second, if there is no readymade functionality, then make your own. Sometimes it takes longer asking questions or searching the internet then writing a quick-and-dirty "one liner", something like this:
// classdefinitions are stored in ^oddDEF, mac-routines in ^rMAC // as said above, quick-and-dirty: // if the SEARCHTERM occurs in %-items, then you will get multiple hits // // the one-liner version k n i ##class(%SYS.Namespace).ListAll(.n) s n="" f s n=$o(n(n)) q:n="" f s="^|n|rMAC","^|n|oddDEF" f s s=$q(@s) q:s="" w:@s_s["SEARCHTERM" s," ",@s,! // for folks with less experience // ClassMethod SearchAllNSP(searchterm) { i ##class(%SYS.Namespace).ListAll(.n) { s n="" f {s n=$o(n(n)) q:n="" f s="^|n|rMAC","^|n|oddDEF" { f s s=$q(@s) q:s="" w:@s_s[searchterm s," ",@s,! } } } }
It's up to you to left out all those multiple %-items and to add some formatting...
So the bottom line of my answer is: yes, there is a way to search (whatever you want) in one go
Another option (my preferred one) - ensure that source control is used for all namespaces in your instance and simply do the search in your source repository. Then you not only find the strings you are looking for but also you can easily find the history related to each of those parts of code.
Not with Studio, but if you use VS Code, enable proposed APIs, and create a multi-root workspace with one folder for each namespace then I think you can search across them all.
Thank you all for your suggestions. it looks like there is no direct way.
@Mary George
there is one.
I just posted a cross namespace cross CLS, MAC; INT, INC search
https://community.intersystems.com/post/code-scanner
It's pretty fast just using COS and Globals. No class.
💡 This question is considered a Key Question. More details here.