Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling javascript intellisense for external libraries in Visual Studio

I updated ~/Scripts/_references.js with

/// <autosync enabled="true" />
/// <reference path="angular.js" />
/// <reference path="angular-route.js" />

and in my app.js I can see some intellisense working, which is great

angular.js intellisense working

but go a little further and it doesn't work anymore.

angular.js intellisense not working

Any ideas on why this happens or ways to make it work?

like image 892
kenwarner Avatar asked Dec 13 '13 14:12

kenwarner


People also ask

How do I enable IntelliSense in Visual Studio?

To access this options page, choose Tools > Options, and then choose Text Editor > C# > IntelliSense.

Why is IntelliSense not working Visual Studio 2022?

Please try: Go to Visual Studio Installer, click Modify , uncheck IntelliCode in Individual components, then click Modify button to save the change, wait for the installation to complete, and then reinstall IntelliCode . In Visual Studio, go to Tools->Options->IntelliCode to check if the setting is Default.

How do I add JavaScript to Visual Studio?

With your project open in Visual Studio, right-click on a folder or your project node in Solution Explorer (right pane), and choose Add > New Item. In the New File dialog box, under the General category, choose the file type that you want to add, such as JavaScript File, and then choose Open.


2 Answers

Because you are using dependency injection, Visual Studio has no way to figure out what are the types of the arguments.

This is a common problem with Javascript intellisense and, since Javascript does not allow for explicit type annotations, it seems that there is no clear way to work around it.

However, this can be achieved easily using Typescript (which has a VS2013 extension) and angular types where your code would look like:

angular.module('example', ['ngRoute'])
  .config([ '$locationProvider',
    function ($locationProvider : ng.ILocationProvider) {

           $locationProvider. // Intellisense would work here.
    }
   ]);
like image 109
musically_ut Avatar answered Oct 06 '22 00:10

musically_ut


I built a library to do just this:

https://github.com/jmbledsoe/angularjs-visualstudio-intellisense

like image 45
John Bledsoe Avatar answered Oct 05 '22 23:10

John Bledsoe