Jump to content

Include UDFs versus paste in snippets (VSCode-AutoItSnippets)


SOLVE-SMART
 Share

Recommended Posts

Hi folks,

personally, I felt it always unclean or simply ugly to include whole UDFs into his script or project, in cases where you need only individual functions from it. The fact that the *.exe gets larger when compiling is often no longer a problem these days or you just don't mind it anymore - I, on the other hand, do somehow 😅 .

That's why I used to take the individual functions from the UDFs into my script so that I didn't have to include the entire UDF (#include).
Depending on the license, I have recorded the attribution of the UDF creators or the contributors in the credits or similar to keep it fair.

Then the change came:
I got to know Visual Studio Code (VSCode) professionally, first for other languages, then also for AutoIt. With VSCode's rapidly improving and nowadays very powerful IntelliSense (code completion) I got an idea.

Easy and fast:
I store functions that I often need or have in some (own) UDFs in snippet files and can quickly insert them into the respective script or project if required. But it's important to me that I can access the functions contained in the snippets from anywhere - on my private computer, at work or at a colleague's/friend's. So I created a VSCode Extension 😀 .

VSCode-AutoItSnippets:
If you also implement your AutoIt projects with VSCode, then my AutoIt Snippets Extension might interest you or even help you to implement your projects faster.

  • I would be very happy if you could take a look at the project.
  • Of course, I'm interested in your opinion on this as well as whether one or the other would like to share their function(s) and would also like to have them immortalized in the extension 🧐 .
  • If this should be interesting for you, then you are welcome to
    • add your functions via pull request,
    • or just write them here so I can include them in the snippet files,
    • or you write with a private message or email.
  • I'm curious if this can be helpful for you, because there are already over 500 installations of the extension, which makes me happy 😁 .

This is how it looks in practice/in use:
https://github.com/Sven-Seyfert/VSCode-AutoItSnippets#features

Best regards
Sven

________________
Stay innovative!

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

  • Moderators

SOLVE-SMART,

Quote

I felt it always unclean or simply ugly to include whole UDFs into his script or project, in cases where you need only individual functions from it

Just for interest, there is an excellent utility included in the full SciTE4AutoIt3 package called Au3Stripper which will: 

  • Strip all unused UDF's (Funcs) and/or unused Global/Local Variables from your main script and all included files
  • PreExpand Global Const Variables
  • Rename Variables and Func names to shorter versions (makes the script quicker)
  • Warn you that the script is likely to have difficulties running if a parameter cannot be determined before run-time

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi @Melba23,

to be honest with you, I know Au3Stripper but I didn't know how powerful it is and what it can do for me (blame on me 😔).
Thank you for the explanation I will have a deeper look in the future.

hi @Danp2,

principle you're right 👍 with your consideration. I believe it's not that big problem you might think.

  • How often is it the case to change small, one purpose designed methods/functions?
  • Older scripts or even projects might require more maintenance in general besides updating a few functions when it's really necessary to update them.
    • In my experience it's often a good approach to rethink whether there has to be a bigger refactoring or even a redesign of the application.
    • Of course this depends 😅 .
  • The difference to update separate UDF file(s) and re-including them to your projects in comparison to update functions isn't that big in my opinion.

As long we are not talking about such things like a package manager (e.g. npm) with third-party code that will be included in the project, we will always have some kind of maintenance duties and work. Still, it could be a maintenance nightmare like you said. If so, I believe it's better to rethink the design because the project concept or structure might be the wrong.

Quote

Thanks for the interesting thought which lead possibly to an additional updating concept (or even have to).


Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

  • Moderators

I like the premise of this extension and I believe it could be quite useful. I'd like to see a method to more easily add user snippets from within VSCode, similar to how https://snippet-generator.app/ works. If you could accomplish this, I believe that it would be high adopted.

I'm not a fan of having to type !au3, however, I found that the included snippets can be accessed using a keyboard shortcut for "editor.action.showSnippets". Maybe you could add user friendly way to set this shortcut.

Keep up the solid work!

Edited by big_daddy
to = the
Link to comment
Share on other sites

Hi @big_daddy,

thank you for your assessment 😀 .

3 hours ago, big_daddy said:

I'd like to see a method to more easily add user snippets from within VSCode, similar to how https://snippet-generator.app/ works.

Indeed this would be helpful - I will try to find a good appraoch to achieve it.

3 hours ago, big_daddy said:

using a keyboard shortcut for "editor.action.showSnippets"

I tried it quickly but I am not sure I like it 😅 . I will explain it later (in a separate post, because of a lack of time).

By the way, what if I would set "_" as the trigger for IntelliSense (instead of "!au")?
Because all other functions which are provided by the "AutoIt" Extension (of Damien, nowadays of @LoganCH) ...

grafik.png.4678b54630294c28b08820d934f18469.png

... do the same 😀 .

 grafik.thumb.png.9bd3af9c89eb3bab9a812a84ab818e33.png

Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

  • Moderators

I found a few snippet management extensions for VSCode, however, they do not handle AutoIt variables well since $ is the variable identifier for the snippets. I'm not very proficient in managing strings in javascript or I'd just modify one of the extensions. Someone well versed in RegEx could probably make easy work of it. I did find this extension along with this fork that looks promising.

I noticed that in your snippets, you are using $$ instead of properly escaping with \\$. This causes the editor to see all AutoIt variables as snippet variables and therefore tabstops. I'd like to suggest a format like seen below with properly escaped AutoIt variables.

As for the trigger key, I wouldn't suggest using just an underscore. I would think !a would be a good trigger as I don't see that being typed very frequently. 

"IsWindowNotResponding": {
        "prefix": "IsWindowNotResponding",
        "body": [
            "#include <WinAPISys.au3>",
            "",
            "If IsWindowNotResponding(\\$${1:hWindow}, ${2|1000,5000,10000,30000|}) Then",
            "\t$0",
            "EndIf",
            "",
            "; Author ........: Damon Harris (TheDcoder)",
            "Func IsWindowNotResponding(\\$hWindow, \\$iTimeout = 5000)",
            "\t_WinAPI_SendMessageTimeout(\\$hWindow, 0, 0, 0, \\$iTimeout, \\$SMTO_ABORTIFHUNG)",
            "\tReturn @error",
            "EndFunc"
        ],
        "description": "Checks if a Window is not responding"
    }
Link to comment
Share on other sites

Hi @big_daddy,

sorry for my late response 😅 and thank you for investing the time to have a research 👍 .

On 1/27/2022 at 7:05 PM, big_daddy said:

[...] they do not handle AutoIt variables well since $ is the variable identifier for the snippets [...]

Yes this is unfortunately a problem, but shouldn't be a big one.

 

On 1/27/2022 at 7:05 PM, big_daddy said:

I did find this extension along with this fork that looks promising.

They were updated in 2018 which could bring a lot of package dependencies problems when it come to relive them up 🙁 . I will do a research on my own.

 

On 1/27/2022 at 7:05 PM, big_daddy said:

I'd like to suggest a format like seen below with properly escaped AutoIt variables.

I will definitely change to the proper escape pattern 👍 .

 

On 1/27/2022 at 7:05 PM, big_daddy said:

As for the trigger key, I wouldn't suggest using just an underscore. I would think !a would be a good trigger as I don't see that being typed very frequently.

It's already the case. When you type !a and the IntelliSense of VSCode will show you all the extensions which do have the prefix !au3.
But I see your point. This could be a breaking change in a way - but also not - I don't know right now, but lets see what I will do 😁 .

Thanks for your input big_daddy cool 😅 .

Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

  • 2 weeks later...

Hi folks,

I released Version v2.1.0, see CHANGELOG.

@big_daddy

  • I changed to proper escape pattern ✔
  • I switched to !_ instead of !au3_, because almost all user defined functions starting with a underscore ⚠
  • Function names are adjusted to starting with capital letter (after the underscore) to fit more common practise ✔
  • I still try to provide a user friendly way of snippet generation (the snippet management extensions that you mentioned, aren't that good) ⚠

Next release coming soon 😁 .

Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...