Some while ago I started a plugin to easily add units to the uses clause just like you can do via quickfix in VisualStudio.

Some while ago I started a plugin to easily add units to the uses clause just like you can do via quickfix in VisualStudio.

I never actually polished it but since I felt it might be useful to others as well here it is (still beta - supported Delphi versions currently are 10, 10.1 and 10.2).

Just run the setup and install into a directory where the IDE will also have write access to (should be %localappdata% by default).

When you first start the IDE with the plugin it will index $(BDS)\source which should reasonably fast and you won't even notice it. You can then add additional directories via Options -> Third Party -> UsesHelper (or F6 -> UsesHelper). Just add any additional directories that should be indexed (recursively, only *.pas). Indexing will happen in the background. In the end it will save an index.dat file which it will only access when it gets changed or you restart the IDE.

Via shortcut (Shift+Alt+F10 - fix for now, might be configurable later) while in the editor on some symbol you can show the suggestion list for units that contain that symbol and add it to interface or implementation uses. What does not work yet is moving from one to the other if it already exists in either.

Let me know if there any issues and enjoy!

Oh, the download link:
https://1drv.ms/u/s!ArjIoB43KhwDg3Ju1tkHlJniN2WS

Comments

  1. One bottle of vodka for you sir. 🙌

    ReplyDelete
  2. You beat me to it. That was on my list to combine the uses manager with the class browser.

    ReplyDelete
  3. Jacek Laskowski I know that - not what I want. Why should I do some search when the plugin can already only suggest those units that have exactly the type under my cursor.

    ReplyDelete
  4. By the way - I am indexing everything in the interface section of the units: all kinds of types including all values of enums, consts, variables, routines. So for example if you type mrOk and hit the shortcut it should show Dialogs and UITypes.

    Attila Kovacs Yes, I am currently removing the common unit scope names (like System, Winapi, Vcl or Fmx) on purpose but I plan to make it an option which ones to omit.

    ReplyDelete
  5. Too bad its .pas based, won't work on Starter :(
    Sounds cool btw

    ReplyDelete
  6. Agustin Ortu The indexer is pas based. So if you produce the index.dat yourself or someone else shares it. It works =)

    ReplyDelete
  7. Attila Kovacs Not until you hit the button or change the directories to index :)

    ReplyDelete
  8. Well done. Thanks for sharing, Mr Stefan Glienke

    ReplyDelete
  9. Stefan Glienke
    "while in the editor on some symbol you can show the suggestion" how?
    Trying on Berlin free it dose not seem to work.
    What am i expected to see?Mouse on symbol? Right mouse click?
    Can we have the source?

    ReplyDelete
  10. shlomo abuisak I wrote the shortcut right before the part you quoted and also in the readme that shows after you install (if you did not uncheck that in the setup).

    And no - with the amount of libraries, plugins and other things in the Delphi ecosystem people ask money for I think its fair enough if I don't open source every single piece of work I create. It will still be free though.

    ReplyDelete
  11. helo . Exists plugin to generate get set in editor Delphi Starter?

    ReplyDelete
  12. Stefan Glienke The idea is good. Open source is of course nice but it is your decision.

    What is the required version of Delphi ? Does it work with D2007 ?

    ReplyDelete
  13. Roland Bengtsson I am using features only available on XE and up.

    ReplyDelete
  14. Stefan Glienke Please add config for shortcut. For me shift+alt+F10 is quite uncomfortable

    ReplyDelete
  15. Stefan thank you: this is really great!

    ReplyDelete
  16. Stefan, can you please add a config for shortcut?

    ReplyDelete
  17. I implemented unit scope as optional and config for shortcut. I will upload a new version in the next days.

    Attila Kovacs If the unit is part of a project you don't need to add it to the global index as it will be indexed as part of a local index (all units in the project).

    ReplyDelete
  18. I had similar problems in the beginning like Attila. After having info on what is indexed i could change the options. First time AV. Next restart.

    Wow! It's working now. OMG this is brilliant:) THANKS!

    FYI:

    BTW: A path will get stored and handled as two paths is it exceeds the line length in the memo. I.e. linewrap is stored. Not 100% easy to notice when you Ctrl+V.

    ReplyDelete
  19. Dany Marmur I have to disable wordwrap then, thanks.

    ReplyDelete
  20. Stefan Glienke if you are interested. Ever since installation i see a window "flashing". I cannot know if its the util of course. But it started then and it only happens in my dev vm when the ide is open. By "flashing" i mean a window is created, displayed and immediately hidden or destroyed. I speculate but it might be of help...

    ReplyDelete
  21. Do you plan to support older Delphi versions too?
    (Where "older" means Delphi 2007 in particular. ;-) )

    ReplyDelete
  22. Thomas Mueller I answered that question already: no. Code is using DelphiAST which only works on versions that know generics. Backporting that is not worth my time.

    ReplyDelete
  23. Where can I download the last version of it?

    ReplyDelete
  24. Hi Stefan Glienke do you released a new version of it? I am interested in some new changes you have told us, like disabled word-wrap, configurable shortcut etc. Thank you for this little jewel :-)

    ReplyDelete
  25. Attila Kovacs Me in that case, yes. I did not add those to the indexed symbols, will do for next version - probably around 2 weeks from now.

    ReplyDelete
  26. I updated the plugin (link is still the same) - the default shortcut now is Ctrl+Shift+A (so it overrides the similar functionality from the IDE) but you can change it in the options.
    Also fixed the issues with not indexing some symbols and the wrong wordwrap in the index directories.
    It also indexes the full qualified unit name. If you want to shorten some of them you can specify the scopes in the options (so if you add System for example the plugin adds SysUtils to the uses and not System.SysUtils).

    Supported versions: 10.0, 10.1, 10.2

    ReplyDelete
  27. Hi Stefan, how can I force a complete reindex after having added some directories to UsesHelper? I have pressed the reindex button in the Options, but nothing happened and when I press the shortcut on a symbol contained in one of the units contained in the directories I have added to the UsesHelper config, it give me an error "No unit found for identifier MyIdentifier". Any idea?

    ReplyDelete
  28. Fabio VITALE I does the reindexing in the background and eventually finishes. It just does not give you a notification.

    ReplyDelete
  29. Ok thanks Stefan Glienke! I will patiently wait the reindexing process

    ReplyDelete
  30. I will add a notification in the messages panel in the next version.

    ReplyDelete
  31. Maybe something wrong in my setup but I have noticed that the directory I have added to my config, where all my source files (*.pas) reside, did not get indexed. I also closed delphi, deleted the index.dat file and restarted delphi: nope, that directory is not indexed. I am short on ideas

    ReplyDelete
  32. Fabio VITALE Did you properly enter the directory into the indexed directories list? No delimiter, just new lines for each directory.

    In the registry under the bds key there is the UsesHelper key with the value SearchPath. It contains the semicolon delimited directories.

    ReplyDelete
  33. Yes, all things seem to be correct. I've also restarted Delphi and now the UsesHelper shortcut is functional on symbols of the directory I've added to the config in Options . I do not know what was wrong with the indexing. Anyway thank you very much for your support!

    ReplyDelete
  34. Also noticed that if you launch Rebuild Index and then exit Delphi, an access violation occours: this is kind of expected, I imagine, since maybe the reindex has not yet finished.

    ReplyDelete
  35. Fabio VITALE Yes, I did not put any cancellation mechanism into that. It's simply an anonymous thread working in the background. I would fix that if I would charge money for the plugin, otherwise not worth the time ;) In your version it's also possible to fire it up multiple times which I fixed for the next version.

    ReplyDelete
  36. Thank you very much! I will stay tuned for the new version.

    ReplyDelete
  37. It is a nice, very nice product.
    I love to use it, but now in 10.3 i miss it.
    When will it be available in 10.3 (Rio) ?
    thx

    ReplyDelete

Post a Comment