New Command in My CRS AL Language Extension: Search Object Names

Recently, I came across this post by Jack Mallender.  An interesting idea on how to efficiently find AL Objects among your files. It basically comes down to using regex in combination with the global search functionality in VSCode, like (yep, I’m stealing this from Jack’s post – sorry, Jack ;-)):

It immediately convinced me that this would be very useful for everyone, so I was thinking – why not making it part of “waldo’s CRS AL Language Extension“?  It didn’t seem too difficult for the experienced TypeScript developer – so for a noob like me, it should be do-able as well ;-).  A few hours later – after a lot of googling – I found the 9  lines of code that made this easily possible .. I’m not joking ;-).

So – I present to you – a new command as part of the extension: Search Object Names.  Simply call the command, provide the searchstring, and look at the result in the search window:

Now, I made it so that when you are on a word, or selected a word in the active editor, it’s going to take that word as the default Searchstring.  Just imagen, you’d like to go to the source of the code of a variable you’re on, simply make sure your cursor is on the word, and invoke the command:

Settings

May be it’s a bit overdone, but yes, there is a setting as well (CRS.SearchObjectNamesRegexPattern) , because you might want to search differently than I do .. .  We were discussing that on twitter, and I just decided to not decide for you on how you want to search, but let you set it up if you would like to search differently as me.  Let me give you a few options on what would be interesting settings…

Find the source object (default)

Pattern

'^\w+ (\d* )?"*'

Setting in VSCode:

"CRS.SearchObjectNamesRegexPattern": "^\\w+ (\\d* )?\"*"

// Mind the escape characters

This is the default pattern, which means you don’t have to set anything up for this behaviour.  Basically this pattern will search any occasion where it starts with a word, than optionally a number, and then your search string.. .  In other words: the exact source object of the object name you’re searching for.. .

Find all references

Pattern

'\w+ (\d* )?"*'

Setting in VSCode:

"CRS.SearchObjectNamesRegexPattern": "\\w+ (\\d* )?\"*"

// I just removed the "^" from the default setting, which indicates "search anywhere"

This pattern will search any occasion in code – which means: also the variable declarations.  Let’s say it’s an alternative “where used”.  I won’t set it up like this as a default setting, but I might just change it ad hoc in the search by simply removing that character.. .

Find anywhere in the name

Pattern:

'^\w+ (\d* )?"*(\w+ *)*'

Setting in VSCode:

"CRS.SearchObjectNamesRegexPattern": "^\\w+ (\\d* )?\"*(\\w+ *)*"

// basically added that there could be multiple words before the searchstring.

This pattern is somewhat more complicated, but if you would not rely on your search term being the beginning of the object, but rather “somewhere” in the object name, you could use this one.

Enjoy!

5.00 avg. rating (97% score) - 1 vote

Permanent link to this article: https://www.waldo.be/2020/03/26/new-command-in-my-crs-al-language-extension-search-object-names/

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.