Google Apps脚本库自动填充功能

时间:2013-07-03 05:08:07

标签: google-apps-script javascript jsdoc

我正在创建一个用于谷歌应用程序脚本的库,但我遇到了JSDoc Style Documentation的问题,因此IDE自动完成功能将适用于最终用户。

以User.prototype.METHODNAME输入的所有方法都应显示在此库的自动完成中。目前,只有.getEmail()方法出现在User对象的自动完成中。也应该出现.getName()。getPassword()。hasPaid()等方法。特别奇怪的是,当我交换.getEmail()和.getId()的方法名称(并且只有方法名称)时,IDE仍然显示.getEmail()作为唯一选项,并运行原始.getId()方法。

以下是没有用于测试目的的敏感信息的模拟库的库键:M1TqnX8hyIa1H8ikAojXirsqqTKXVxxXC

/** 
*@param {Number} id
*@param {String} email
*@param {String} name
*@param {String} password
*@return {User} User
*/
function User(id, email, name, password){
  var ss = SpreadsheetApp.openById("INSERT SPREADSHEET HERE").getSheetByName("Users");
  var data = ss.getRange(1, 1, ss.getLastRow(), ss.getLastColumn()).getValues();
  for (var i = 1; i < data.length; i++){
    if (data[i][0] == id){
      this.id = id;
      this.email = data[i][1];
      this.name = data[i][2];
      this.password = data[i][3];
      this.picks = data[i][4];
      this.paid = data[i][5];   
    }
  }
  return this;
}
/**
* @param {Number} id ID of the user
* @return {User} User
*/
function getUserById(id){
  var user = new User(id, null, null, null);
  return user;
}
/**
* @param {String} email email of the user
* @param {String} name name of the user
* @return {User} User
*/
function getUserByEmailAndName(email, name){
  return new User(null, email, name, null);
}
/** 
*@return {Boolean} isCorrect
*/
User.prototype.checkPassword = function (password){ return this.password == Utilities.base64Encode(password); }

User.prototype.getEmail = function (){return this.email;}
/** 
*@return {Number} id 
*/
User.prototype.getId = function (){return this.id;}
/** 
*@return {String} name 
*/
User.prototype.getName = function (){return this.name;}
/** 
*@return {String} encodedPassword 
*/
User.prototype.getPassword = function (){return this.password;}
/** 
*@return {String} jsonPicks 
*/
User.prototype.getPicksAsString = function (){return this.picks;}
/** 
*@return {JSON} jsonPicks 
*/
User.prototype.getPicksAsJson = function (){return Utilities.jsonParse(this.picks);}
/** 
*@return {Boolean} hasPaid
*/
User.prototype.hasPaid = function (){return this.paid;}

2 个答案:

答案 0 :(得分:0)

如果您正在使用TypeScript-或打算迁移至-我们已经构建了一个旨在为此提供帮助的软件包:

https://github.com/maelcaldas/clasp-types

您可以使用它为TypeScript上编写的面向对象的库和客户端API生成自动完成功能。

答案 1 :(得分:-1)

I think the autocomplete only works for the functions that were in the first Library version. So I found that creating a new first library kinda solve that problem (but you now have to save your versions yourself).

Try this (everything is in French here, but I'll try to translate) :

1) Copy your Project to a new Project (File-Create a Copy) 2) Create a new Library in this new Project (File-Manage Versions) 3) Get the new project library Key (File-Project Properties) 4) Link this new Library to your Projects with the Key (Ressources-Libraries)