Next OTA question: Is there a way to get the name of the method the cursor is in? I saw some plugins (like Castalia) showing that in some toolbars - or is that done by some custom pas parser?
There's no OTAPI way to do it - you need to parse the source. Castalia has its own parser (which is open source); for Bookmarks I wrote my own lightweight one; CnPack has their own too I think. David G Hoyle has some sample code to select an entire method, which parses very simply just looking for procedures in the implementation section: http://www.davidghoyle.co.uk/WordPress/?p=341
Don't know the answer, but I do know that CnPack does it, so you could plow through their source code.
ReplyDeleteThere's no OTAPI way to do it - you need to parse the source. Castalia has its own parser (which is open source); for Bookmarks I wrote my own lightweight one; CnPack has their own too I think. David G Hoyle has some sample code to select an entire method, which parses very simply just looking for procedures in the implementation section: http://www.davidghoyle.co.uk/WordPress/?p=341
ReplyDeleteCnPack also has a toolbar that shows a similar thing (and since that it open source, it might be worth getting the source and have a look - https://code.google.com/p/cnpack/source/browse/trunk/cnwizards/Source/Utils/CnPasCodeParser.pas).
ReplyDeleteI think both of them use a custom parser to work out where the cursor is.
There is Castalia-Delphi-Parser (https://github.com/jacobthurman/Castalia-Delphi-Parser) but I believe our resident Simon Stuart has updated with his Monkey Mixer (https://github.com/LaKraven/MonkeyMixer), in the Source/Common directory
Simon Stuart https://github.com/RomanYankovsky/DelphiAST - How could I have forgotten that one??
ReplyDeleteNeed more coffee (and sleep)... :-D
IOTAModuleRegions and a little bit parsing do the job for me - see TLiveBlameEditorPanel.ChangeLineEvent
ReplyDeleteUwe Schuster I saw that and was going to suggest it but it depends on which version of Delphi needs supporting...
ReplyDelete