6

Can I get in editor autocomplete for my functions using JSDoc somehow?

I am creating a big google spreadsheet with a lot of code in the associated script editor.

I get autocompletion help when I write the period on LINE 1 (see code below), but not when writing the period on LINE 2. Is it possible to use JSDoc syntax to get autocomplete help when writing the period on LINE 2 also?

I have not succeeded getting this to work for normal javascript objects nor Spreadsheet related objects. I'm interested in both.

/** Failed attempt on getting autocomplete help using JSDoc on a google Range object
* @returns {Range}
*/
function getMyRange() {
  return SpreadsheetApp.getActiveSpreadsheet().getRangeByName('myRange');
};

/** Failed attempt on getting autocomplete help using JSDoc on standard JS-object
* @returns {Array}
*/
function getMyArray() {
  return SpreadsheetApp.getActiveSpreadsheet().getRangeByName('myRange');
};

function test() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  // Please think of the code below as 4 separate examples, nothing
  // of the below is meant to compile as it is. It is just 4 separate
  // demonstrations of when I'd like to get autocompletion help and notes
  // on when I do and don't
  ss.getRangeByName('myRange'). // **** LINE 1 **** I get autocomplete
  getMyRange().                 // **** LINE 2 **** No autocomplete

  [].                           // **** LINE 3 **** I get autocomplete
  getMyArray().                 // **** LINE 4 **** No autocomplete...
};
Rubén
  • 34,714
  • 9
  • 70
  • 166
consideRatio
  • 1,091
  • 13
  • 19
  • And when the line 2 starts with `.` ? i.e. starts with `.getMyRange()` – JSDBroughton Jan 11 '15 at 20:26
  • I edited my question and added a comment above the LINE 1-4. Did I correctly guess that you no longer need to ask your question after reading those comments? "i.e. starts with `.getMyRange()`"? – consideRatio Jan 11 '15 at 21:03

2 Answers2

8

Auto complete using JSDoc for non GAS functions works for code added as a Library not inline to the same script. It is a limited IDE in that respect.

https://developers.google.com/apps-script/guide_libraries#guidelines

JSDBroughton
  • 3,966
  • 4
  • 32
  • 52
  • Thanks for that clarification! So if I encapsulate my functions in a library, do you see me successfully getting autocomplete on google-specific classes like the spreadsheet Range objects? – consideRatio Jan 11 '15 at 21:37
  • 4
    First level functions in the library's global scope yes, secondary methods not. https://code.google.com/p/google-apps-script-issues/issues/detail?id=1731 – JSDBroughton Jan 11 '15 at 21:39
1

From Editor, File, Project Properties, Copy "Script ID", Cancel, Resources, Libraries,Add a Library, Paste, Add, Set Version, Set Identifier to "a" because my left little finger is always on the "a" key, so to see your local script functions in auto complete, just type "a.", then remove "a." when you have your parameters set.

Biz Bot9
  • 11
  • 1