Table of contents
SynopsisThis extension is a result of hackathon event done in the company we work for. We had an opportunity to invest 2 days into anything we could possibly want. We chose to develop an extension for VS Code which would make our daily work easier. Our current project is an Angular 1.5 based web application. As Angular developers we wanted to have auto-completion for all custom components that are available in our application. FeaturesIntellisenseGiven the following components in a project:
One should be able to use auto-completion like that: As a result component's html code along with all bindings is added. It can also help with the bindings themselves (will only suggest missing ones): There is also a command to refresh components cache which might be useful if you're developing components constantly and don't want to restart vscode each time.
You can trigger the command from command panel, it's called Controller model in viewsYou can use auto-completetion for controller members while being in component's view like seen on the screenshot below: Currently only one level of intellisense is available since otherwise the extension would have to scan all files in the whole project. Controller files are already scanned so it was little effort to suggest first-level members.
Go To definitionYou can go from html directly to either the component definition, controller or template. Just use F12 (default) or ControllersControllers are searched using For base classes (scanning their members) to work those base class files have to fit into the same glob. One has to extend it to cover those files if naming convention is different. For instance I use this:
TemplatesTemplates are searched based on either the
In case you have different scenarios please let me know the details and I'll try to include it in next version. Find All ReferencesYou can use In HTML template cursor has to be focused on component name, not the binding or the inner html of the component for this to work: In component definition file cursor has to be on component name: In controller file cursor has to be on the class name: New in 0.7.0 Find all references now works also for controller members, ie. they will be found in components' templates as well: Find unused componentsThis feature will allow you to easily find components which are not used in the project. Selecting one of the unused components will navigate to it in the editor. It does understand HTML a bit so commented out parts will be taken into account. See screenshot below: Find unused directivesThe same like above but for directives. It will find all element based and attribute based directives which are not used across the project. Component member diagnosticsExperimental feature to detect using non-existing fields in component template: This will check controller members including base classes if possible as well as component bindings.
This feature is off by default until getting stable enough. Use Code actionsMember diagnostics has been enhanced with Code Actions now: Like seen on the image you can ignore an error for instance if it's a false positive (which may happen rarely) or for any other reasons. It will be added to a separate configuration file which resides in .vscode directory under the workspace. One can commit that file to repository so that whole team sees the same. Other option is a 'Did you mean' suggestion. It uses great didyoumean2 library under the hood and exposes one of its options via Watch file changesTo avoid a need to manually refresh components cache every time a change is introduced a new mechanism of file watching has been introduced. It watches all parts of the component - ie. component itself, template and controller.
Whenever one of the file is changed it should automatically rebuild the cache so that all features relying on that file should immediately reflect the changes. It will work for intellisense, It is not perfect yet and may not always work as desired. One known issue is when a project changes the branch. It sometimes loses the changes and for that case it's still better to call Directives
Directives support has been finally introduced. Both A command to find unused directives is there as well: ConfigurationThis plugin contributes the following settings:
Whenever one of the globs changes components cache is automatically rebuilt. Additionally all component files are monitored for changes and they will be reflected immediately, ie. after adding a binding you can just save the file and go straight to template file to use that binding.
CommandsThis extension contributes the following commands to the Command palette.
Performance note on configuration globsPlease use as specific globs as possible. Parsing files is only a fraction of the whole process. Vast majority of time is consumed on "globbing" for files to be processed so the more precise the globs are the better performance you can expect. In my example project there are around 22k files and 3k folders. Given default glob pattern it takes slightly above a second to scan all these folders to find all component files. Restricting the pattern to one single subfolder (ie. subdir/**/*Component.ts) which contains only 3k files and 500 folders it goes down to around 200-300ms on my machine being almost a second faster than the default. The bigger the project the greater the impact so in general it is better to use multiple specific patterns rather than one pattern to glob them all :)
ChangelogFull changelog is available here or in the Changelog tab from within vscode itself. |