HookyQR / VSCodeBeautify

Enable js-beautify (https://github.com/beautify-web/js-beautify) in VS Code
MIT License
607 stars 178 forks source link

Extension delays startup for every project #403

Closed robole closed 2 years ago

robole commented 2 years ago

Version: 1.61.0 Commit: ee8c7def80afc00dd6e593ef12f37756d8f504ea Date: 2021-10-07T18:11:02.929Z Electron: 13.5.1 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Linux x64 5.11.0-37-generic snap Beautify: v.1.5

Provide the settings you use: Not relevant

Expected results

The extension is expected to be loaded only when JS, JSON, CSS, Sass, and HTML files are opened.

Actual results

The extension is loaded when any file is open. You can check this by running the command Developer: Show Running Extensions.

Why?

This is due to the activationEvents set to an asterisk in the package.json. This is the startup activation event. Extensions with this activation event effectively delay VS Code from becoming active.

The VS Code docs gives the following advice on this:

To ensure a great end user experience, please use this activation event in your extension only when no other activation events combination works in your use-case.

Since, there are other activation event combination open, I would consider this a bug. As a comparsion, ESLint uses onStartUpFinished.

You can narrow down the languages you are targeting by using the onLanaguage event instead. You can use something like this instead:

"activationEvents": [
    "onLanguage:html",
    "onLanguage:css",
    "onLanguage:scss",
    "onLanguage:javascript",
    "onLanguage:javascriptreact",
    "onLanguage:json"
  ],

The scss language ID includes .sass files.

I dont know if you support formatting in template sections in languages such as Vue and Svelte currently, you can add those too if you do.

This will impact your tests, you will need to accommodate the delay for the extension to be loaded. It should not affect the beautify.language settings, but should be reviewed.

If you have some difficulty in making using onLanguage, you could use onStartUpFinished instead which would remove it from blocking VS Code on startup.

Thank you for your hard work.