The jsGotoDefinition main functionality is to give VS2010 developers the same ability of right-clicking on a method call/variable and going to its definition as they would in C#. To achieve this, jsGotoDefinition provides the user with an XML file where the user can enter regular expressions to assist in finding a function declaration. This allows the user to define a regular expression for the way he/she typically declares functions in javascript. The default settings.xml file has the following entries:

<settings>
  <stopAfterFindInFirst>true</stopAfterFindInFirst>
  <regularexpressions>
    <regex><![CDATA[function\s*.*\s*(\(|\,\s*)replacewithfunctionname\s*(\,|\))]]></regex>
    <regex><![CDATA[function\s+replacewithfunctionname\s*\(]]></regex>
    <regex><![CDATA[var\s+replacewithfunctionname\s*\;]]></regex>
    <regex><![CDATA[var\s+replacewithfunctionname\s*\=]]></regex>
    <regex><![CDATA[var\s+replacewithfunctionname\s*]]></regex>
    <regex><![CDATA[(\.|\s+)replacewithfunctionname\s?\=\s?function]]></regex>
    <regex><![CDATA[(\.|\s+)replacewithfunctionname\s?\=\s?new function]]></regex>
    <regex><![CDATA[.prototype.replacewithfunctionname\s+\=]]></regex>
  </regularexpressions>
  <allReferencesregularexpressions>
    <regex><![CDATA[replacewithfunctionname\s*\(]]></regex>
    <regex><![CDATA[\s*replacewithfunctionname\s*]]></regex>
  </allReferencesregularexpressions>
</settings>


Where "replacewithfunctionname" will be replaced with the actual function call selected. The regular expressions above in the "regularexpressions" element will find the following types of declarations:

function namespace.functionname(whateverparams)

function functionname(whateverparams)

var myFunctionOrVariable;

var myFunctionOrVariable = somevalue

var myFunctionOrVariable

namespacename.functionname = function(

namespacename.functionname = new function(

someExistingObject,prototype.functionname = 

The beauty of this is that you may look at this and see that this doesn't cater for all your needs so you just add your own regular expressions.

jsGotoDefinition also uses the Visual studio reference tags to help find a call's definitions. Please note that in order for this to work, you will have to define your references as relative paths:

    /// <reference path="../../scripts/jquery/jquery.js" />
    /// <reference path="../../msajax/MicrosoftAjax.js" />
    /// <reference path="../../MSAjaxExtension.js" />
    /// <reference path="../../scripts/generated/MyProject.Entities.js" />
    /// <reference path="../../MyProjectWCF/wcfstatic.debug.js" />


Also, it will not work for dynamic path i.e. A WCF /js endpoint will not be searched. This is why in the example above, we have generated a wcfstatic.debug.js file with all our /js endpoints. Running a "Go to Defintion" or "Find all references" will yield a VS toolbar window with your results and these results will remain there until the next search:



If you have included javascript reference that cannot be found they will come up in the errors tab:


Last edited Oct 20, 2011 at 8:44 AM by pedrodg, version 3

Comments

No comments yet.