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
  • 24,097
  • 9
  • 55
  • 116
consideRatio
  • 981
  • 10
  • 18
  • 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

1 Answers1

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,688
  • 4
  • 29
  • 49
  • 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