Child pages
  • New in 7.0

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In order for all this to work, the builder process needs to be able to infer typing information from the JavaScript source. With JavaScript being a weak-typed and dynamic language, this information can't always be automatically inferred from the source-code itself. The typing information that cannot be inferred from the source-code itself can be supplied using JSDoc. In order to supply all the relevant information the JSDoc support within Servoy Developer has been extended as well.

Refactoring support

Added support for automated JavaScript source code refactoring. The following refactoring options are available:

...

 

An example of such a code structure is a JSDataSet. A JSDataSet created based on a query, cannot be automatically analysed @designtime to see which columns it will contain, thus references to the columns will generate builder markers. The same goes for dynamically inside code creating XML/XMLList objects or JavaScript Objects.

Other scenario's are functions that return a generic type like JSRecord or JSFoundSet, while the context in which they are called gives then additional properties (in the case of these examples all their dataproviders).

The typing information that cannot be inferred from the source-code itself can be supplied using JSDoc. This can be done for in JSDoc comments above the declaration of functions and variables. In order to supply all the relevant information the JSDoc support within Servoy Developer has been extended as well. 

To help identify the area's where the code cannot be automatically analysed, the improved builder process will generate builder markers for all parts of the code where it cannot automatically analyse the code and find all the relevant information.

The majority of the cases where code cannot be analysed fall into the following categories:

  • Calls to functions for which the parameters have not been defined at all (the arguments object is used to access the parameters).
  • Calls to functions for which the JSDoc info for the parameters is missing or incomplete
  • Calls to functions for which the return type is not specified through JSDoc
  • Use of scripting API that returns a generic type (for example JSRecord or JSFoundSet)
  • Use of dynamically objects like XML, XMLList, Object of JSDataSet
  • Wiki Markup
    Dynamic object property access (for example forms\['myFormName' + instanceId)

In order to take full advantage of the new refactoring features in Servoy 6, it is vital to resolve the markers by providing the required information through JSDoc. However, through the preferences, the warnings can also be ignored (they are just warnings, which not necessarily indicate errors in code!), but the usefulness of the refactoring functionality will diminish as code refactors will not be complete.
Refactoring support

Added support for automated JavaScript source code refactoring. The following refactoring options are available:

  • Rename...: to rename variables (global, form and local (inside functions)), functions and function parameters. The rename refactor will change the name both for the declaration of the object to be renamed as well as all references to the object.
  • Extract Local Variable...: Creates a local variable (variable inside a function declaration) based on the selected code within the function. Everywhere the the selected code that was extracted to the variable occurs in the function will be replaced with a reference to the new variable
  • Change Method signature...: Alters the signature of an existing method and updated all calls to the method to use the new signature. Newly introduced parameters can be given a default value, so all calls to the method can call the method with the default value for the new parameter.
  • Introduce Parameter...: Takes a hard-coded value inside the code of a function, creates a new parameter from it, replacing the hard-coded value with the parameter and also update all calls to the method to send the previously hard-coded value as value for the newly created parameter 
  • Inline...: Replaced a method call with the code of the called method 

The Refactor functionality can be accessed in the Script Editor through the context menu ()

Limitations:

As JavaScript is a dynamic language, there are code structures that cannot be analysed in an automated wayAlt-Shift-R)

Workarounds:

JSDoc support

  • Code completion inside JSDoc for supported JSDoc tags and types
  • Support for inline JSDoc to provide type information for objects: 
    Code Block
    function demo(){
       /** @type {JSFoundSet<db:/udm/contacts>}*/
       var x = databaseManager.getFoundset('udm', 'contacts');
       x. //Code-completion here will know that x is a FoundSet on table Contacts in the UDM database, thus will include all columns, calculations and aggregates
    }
  • Support for the @deprecated tag: When a variable or function is marked as deprecated any reference to the object will generate a builder marker
  • Support for the @private tag: Hides the object for access from outside the current scope. Accessing the hidden object from outside the scope in which it is defined will generate a builder marker 
  • Support for typed Arrays: 
    • Wiki Markup
      @type String\[\]&nbsp;
    • @type Array\<String\>
  • Support for typing JSFoundSets and JSRecord to be of a specific datasource: 
    • @type JSFoundset\<datasource\> 
    • @type JSRecord\<datasource\>
      (a datasource string is build up like this: "db:/{serverName}/{tableName}", so for example "db:/udm/contacts")
  • Support for rest parameters: Allows to indicate through JSDoc that a function can take unlimited trailing arguments of the specified type:
    Code Block
    /**
      * @param {...String} someExtraStrings One or more additional String can be send into this function
      */
    function methodWithRestParams(someExtraString){}
    
    
    function test() {
       methodWithRestParams('one', 'two', 'three', 'four');
    }
  • Support for @AllowToRunInFind on functions to indicate that the the function should be executed on event handlers while in FindMode:
    Eliminates the //controller.search() workaround. Note that that running JavaScript while in FindMode has it's limitations and not all behavior is 100% defined. More details will follow.
  • Support for @constructor tag, to indicate that a function declaration is to be used as a Constructor. Functions marked as Constructor also display differently in the Script Outline view 
  • Automatic JSDoc @type setting on global and Form variables
  • Ability to update the type of a variable by updating the JSdoc @type tag value AND the default value

...

  • Investigate if the "Paste to JavaScript console" option in the Context menu of the Script Editor can be removed or made to work
  • Investigate if the "Run as ..." and "Debug as ..." options in the Context menu of the Script Editor can be removed or made to work
  • Bring back support for the old way to type a foundset or records to belong to a certain database and table
  • Full support in JSDoc for typing as a specific type of Form: "@type Form<myformName>". Current support does not include Form variables and Form methods  
  • Introduce the option to suppress individual markers
  • Introduce the option to supply typing info for the content of variables of type XML, XMLList, Object and JSDataSet
  • Properly enable/disable the Refactor options based on the context and selection  
CSS Editor

A new CSS StyleSheet editor has been incorporated into Servoy Developer, with the following features:

...