Nasreddine 2 Posted October 28, 2020 (edited) is it possible to tweek the GExpert tool to search in the background for all function/procedure references and paint the result count on the source editor window like the attached picture? the Grep search feature now works great and it already has the functionality to jump to other files. so my proposition is to make the Grep search for all functions/procedure references that are found on the project path and lib path and the standard paths. then paint the count like visual studio is doing. and when the user clicks on the count the grep window is shown, and in future iteration it can be enhanced to show the implementation where the reference directly. This is just an idea that I had after spending an hour to locate all the references of a function in a large project. Edited October 28, 2020 by Nasreddine Share this post Link to post
dummzeuch 1505 Posted October 28, 2020 1 minute ago, Nasreddine said: is it possible to tweek the GExpert tool to search in the background for all function/procedure references and paint the result count on the source editor window like the attached picture? GExperts does not paint into the editor window and that's not easy to implement (CnWizards does it though). Also, Grep only searches for strings / regular expressions, it knows nothing about context, so it would be wrong for non unique identifiers, so this would be of very limited use. Feel free to try it though. I'll accept a patch. Maybe there are other tools that already implement this, but I know of none. 7 minutes ago, Nasreddine said: This is just an idea that I had after spending an hour to locate all the references of a function in a large project. Isn't there anything like the Find -> Find References functionality in the IDE for C++ code? It usually works fine for me for Delphi code. Share this post Link to post
Nasreddine 2 Posted October 28, 2020 (edited) @dummzeuch thank you for the response, and thank you for detailing what is missing, the cod in the picture is c# not c++. 16 minutes ago, dummzeuch said: Isn't there anything like the Find -> Find References functionality in the IDE for C++ code? It usually works fine for me for Delphi code. it does not always work and sometimes it throws exceptions. RAD Studio is way behind in productivity tools, it always takes me twice the time to do the same job in vs. 16 minutes ago, dummzeuch said: GExperts does not paint into the editor window and that's not easy to implement (CnWizards does it though). this can be done and I think there are many examples of how one can do it. so this is not the show stopper I guess. 16 minutes ago, dummzeuch said: Also, Grep only searches for strings / regular expressions, it knows nothing about context, so it would be wrong for non unique identifiers, so this would be of very limited use. this is the main problem I guess, but I think it can be solved the same way by the code responsible of the feature "go to definition" (initially as proof of concept) so Grep searches for all references (with whole word condition) and then see if the "go to definition" code will lead back to the line in the current file we are doing the search for. do you think an approach like this would work? Edited October 28, 2020 by Nasreddine Share this post Link to post
David Heffernan 2345 Posted October 28, 2020 grep is useless for this purpose. This functionality in VS works because the tooling is able to compile the code and understand all the references from the output of that compilation. A naive text match using grep will give nothing whatsoever of value. Share this post Link to post
Mahdi Safsafi 225 Posted October 28, 2020 54 minutes ago, dummzeuch said: GExperts does not paint into the editor window and that's not easy to implement (CnWizards does it though). Definitely true ! However I've some useful information for anyone that is interested: CnWizards and typically Bookmarks (by David Millington) use DDetours to intercept some functions and paint their stuffs. David on his blog gave a good explanation on how to do that on two part: Part1: https://parnassus.co/mysteries-of-ide-plugins-painting-in-the-code-editor-part-1/ Part2: https://parnassus.co/mysteries-ide-plugins-painting-code-editor-part-2/ BTW, this was the motivation behind developing chained hook for DDetours v2(because CnWizards and Bookmarks couldn't work correctly if they were active together at the same time) 🙂 Quote Also, Grep only searches for strings / regular expressions, it knows nothing about context, so it would be wrong for non unique identifiers, so this would be of very limited use. 1) You can use DelphiAST (by Roman Yankovsky) to parse the unit. 2) If I recall correctly on the days were the Delphi community was on G+, someone (I think it was Stefan gleinke) he made a plugin that displays all symbols and types location for all Delphi units ... Unfortunately all what I remember is that the plugin supposed to work as a cache. Share this post Link to post
Mahdi Safsafi 225 Posted October 28, 2020 16 minutes ago, David Heffernan said: grep is useless for this purpose. This functionality in VS works because the tooling is able to compile the code and understand all the references from the output of that compilation. A naive text match using grep will give nothing whatsoever of value. Agree ! The output ... you mean map file ? Share this post Link to post
David Heffernan 2345 Posted October 28, 2020 (edited) 8 minutes ago, Mahdi Safsafi said: The output ... you mean map file ? No. You need way more than a map file to find all the incoming references to a function. 12 minutes ago, Mahdi Safsafi said: You can use DelphiAST (by Roman Yankovsky) to parse the unit. This won't tell you the information either. Edited October 28, 2020 by David Heffernan Share this post Link to post
Mahdi Safsafi 225 Posted October 28, 2020 26 minutes ago, David Heffernan said: No. You need way more than a map file to find all the incoming references to a function. I use external debugger heavily and all what I need to find references to a given function is the executable only ... map/pdb is just a sugar. If map wasn't that in your mind ... what's the actual one ? Quote This won't tell you the information either. if you parse all units you can than get the information. Share this post Link to post
David Heffernan 2345 Posted October 28, 2020 25 minutes ago, Mahdi Safsafi said: I use external debugger heavily and all what I need to find references to a given function is the executable only ... map/pdb is just a sugar. If map wasn't that in your mind ... what's the actual one ? A map file doesn't list functions calls. You can't map the graph of function calls from a map file. 27 minutes ago, Mahdi Safsafi said: if you parse all units you can than get the information. Parsing isn't enough. You also need to interpret the tokens that the parser emits, using the syntax of the language. For sure you need a parser. But it's not enough. You need more. Share this post Link to post
Mahdi Safsafi 225 Posted October 28, 2020 8 minutes ago, David Heffernan said: A map file doesn't list functions calls. You can't map the graph of function calls from a map file. Yes that's true and I'm aware about that. In fact my DebugEngine is powered by detailed map file. It just seems to me that you didn't understand my comment. So here I explain again : Typically you only need the binary image (exe, dll) to generate the graph of functions ... map is just a sugar that gives additional information(location, ...). Quote Parsing isn't enough. You also need to interpret the tokens that the parser emits, using the syntax of the language. For sure you need a parser. But it's not enough. You need more. Sure DelphiAST doesn't give you that out of the box ... Although you need to make some effort. Share this post Link to post
David Heffernan 2345 Posted October 28, 2020 17 minutes ago, Mahdi Safsafi said: It just seems to me that you didn't understand my comment. I don't think so. I think that you don't seem to understand the requirement. You certainly can't achieve the functionality shown in the original post from a native executable file (like the ones that Delphi produce). Share this post Link to post
Mahdi Safsafi 225 Posted October 28, 2020 27 minutes ago, David Heffernan said: I don't think so. I think that you don't seem to understand the requirement. You certainly can't achieve the functionality shown in the original post from a native executable file (like the ones that Delphi produce). I clearly understand the requirement. What I discussed with you is different thing than what I suggested to Thomas. My answers were based on your statement which used a word output (BTW you still didn't explain what you mean by that) that makes me think to binary graph. Share this post Link to post
Stefan Glienke 2007 Posted October 28, 2020 This feature is called CodeLens - if you fancy you can look on GitHub how its implemented in VSCode. 2 Share this post Link to post
Bill Meyer 337 Posted October 28, 2020 (edited) 3 hours ago, Mahdi Safsafi said: I use external debugger heavily and all what I need to find references to a given function is the executable only ... map/pdb is just a sugar. If map wasn't that in your mind ... what's the actual one ? if you parse all units you can than get the information. As David, says, that is not enough. You need to parse all units, yes, but you need also to deal with many other issues. Think about like-named methods. Think about uses clauses. Consider the search path. If you want reliable results, there are many details which come into play. Sounds like a wish list item for LSP. Edited October 28, 2020 by Bill Meyer Share this post Link to post
Guest Posted October 28, 2020 An VS LSP for Pascal exists, OmniPascal. Also, your can check out C.W. Buddes VS Language server for DWScript. I'm one who got him started - sorry for losing the project Christian, things took different turns - it is unfinished, but it's written in Pascal, compiled w Delphi and IMHO it would serve as a *very* good base if you want to write another LSP for VS Code. You could view it as a "demo" to get started. Mr Budde did some high-level excellent scaffolding. The VS Language sever protocol is... extensive and agreeing w/ Heffernan et. al. you will need to compile in the background to be able to produce all those nifty Lenses, Inspectors and more. Share this post Link to post
David Heffernan 2345 Posted October 28, 2020 3 hours ago, Mahdi Safsafi said: I clearly understand the requirement. What I discussed with you is different thing than what I suggested to Thomas. My answers were based on your statement which used a word output (BTW you still didn't explain what you mean by that) that makes me think to binary graph. By output I mean what is produced by the compiler. Share this post Link to post
Mahdi Safsafi 225 Posted October 28, 2020 LSP does not fit with GExperts philosophy ! GExperts is a plugin that supports older versions perfectly. Adopting LSP means ... you know ! Share this post Link to post
dummzeuch 1505 Posted October 29, 2020 15 hours ago, Mahdi Safsafi said: 1) You can use DelphiAST (by Roman Yankovsky) to parse the unit. Which does not support C++, which the OP seems to be interested in mostly. Share this post Link to post