Aptana Studio 3 JavaScript内容辅助问题

时间:2011-10-30 09:56:00

标签: javascript aptana content-assist

我使用Aptana Studio 3编写JavaScript;它为内置类型提供了出色的内容辅助,它正确地从源代码中推断出变量的类型,并且在编写将代码写入字符串文字中的代码时可以节省生命,该代码将代码写入HTML文档中的字符串文字中。也就是说,内容辅助和支持ScriptDoc功能一直令人困惑,缓慢和令人愤怒。当我尝试编写一个类/构造函数并将函数记录下来时,我可以使用ScriptDoc标记来获取内容辅助:

- 不能将函数/类的名称识别为任何内容;

- 将构造函数重新识别为函数,并将类作为类型,但无法将该识别传播到变量。只要我想写我的课并且从不使用它,这很好;

- 将类重新认识为类型,但无法将构造函数理解为函数。也就是说,它不会详细说明函数的参数,描述或返回类型,但如果我实例化它,它将帮助我了解对象的成员。

可以在http://wiki.appcelerator.org/display/tis/ScriptDoc+%28SDOC%29+2.0+Specification找到ScriptDoc功能的文档(Aptana从中获取用户定义的内容辅助信息);然而,Aptana并没有认识到列出的许多关键词,并且认出了一些不存在的关键词。例如," @ classDescription"在文档中列出但未被识别,而" @ class"已被识别但未在文档中列出。还要注意,完全按照他们描述的那样做事根本不起作用。

任何人都可以帮我一个JavaScript"类"记录下来,Aptana Studio 3代码辅助将正确描述类和构造函数的参数,正确推导出已分配变量的类型,并正确推断其方法之一返回的变量类型,就像它对原生一样类型?使用下面的代码,根据需要添加注释块和标签。我已经删除了我的大部分内容,因为我们一直在弄乱他们,因为他们不能工作。

/**
 * Constructor for Vector class
 */
function Vector(nX, nY) {
    this.x = nX || 0;
    this.y = nY || 0;
}
Vector.prototype = {
    x: 0,
    y: 0,
    /**
     * make a new Vector out of me
     */
    copy: function () {
        return new Vector(this.x, this.y);
    },
    /**
     * compare to some other vector.  Are they equal?
     * @param {Vector} vOther   some other Vector
     */
    equals: function (vOther) {
        //vOther should have content assistance, too.
        return (vOther.x === this.x) && (vOther.y === this.y);
    }
};
var v = new Vector(1,2);  //Should describe Vector class/constructor, types & purposes of nX & nY (Numbers)
var c = v.copy();         //Should recognize v as a Vector and describe v.copy()
c.copy();                 //If c.copy() is described properly, return type is correctly deduced & you win!
//bonus points if you can get it to inherit from something and describe c.inheritedMethod(someParameter)

谢谢!

更新:如果没有对Aptana的Jira,Tenderapp或StackOverflow作出确凿的回应,我已经开发了一个可怕的黑客,没有人应该使用。我将它包括在这里有两个原因:它可以为开发人员提供信息,以确定问题的根本原因,并可能激励他们解决问题以防止人们使用黑客攻击。它是这样的:

// Only recognizes global names
/**
 * This constructor will still be listed as returning 'none', but successfully infers
 * the type of a 'new' expression.  Adding a return tag will break this effect.
 * @constructor (can't tell if this tag does anything)
 */
MyClass = function () {
    // properties added here still won't work
}

/**
 * Describes an obvious property.
 * @type {String}
 */
MyClass.prototype.obviousProperty = "obvious";
// only works for properties declared like that

/**
 * Logs a comment on the parameter's property and returns this object (for chaining)
 * @param {MyClass} oProperty This is what you see for help on calling this method,
 *                            but it doesn't affect CA inside the method
 * @return {MyClass}          This makes the CA for calling the method correctly list
 *                            the return type, but doesn't cause inference of the
 *                            returned value's type.
 */
MyClass.prototype.commentOn = function (oProperty) {
    // hack below makes CA work when you type oProperty.
    log("obvious property is " + oProperty.obviousProperty);

    // the type of 'this' is not understood; I don't even know if the ScriptDoc
    // standard has a mechanism for it
    return this;

    // BEGIN HACK (note that this code is unreachable)

    // force working inference from assignment directly to symbol
    oProperty = new MyClass;

    // force working inference of return type
    return new MyClass;

    // END HACK
}

var foo = new MyClass; // see class description from above
var bar = new MyClass; // see it again, so it's not a crazy fluke
var baz = foo.commentOn(bar); // CA suggests & documents commentOn
baz. // CA suggests & documents obviousProperty & commentOn

它的工作原理是因为代码成功地引起了推理并且ScriptDoc成功地将文档附加到代码中,但是ScriptDoc本身无法引起推断(或者它以一种真正破碎的方式进行推理,似乎没有人能够弄明白)。我的赌注仍然是ScriptDoc对类型名称的扼杀,这在索引视图中很明显。在Aptana Studio 3.08上,它将我的所有类型列为&#39;动态类型&#39;名称而不是人们可以合理地理解它们的名称。在2012年2月2日的每晚构建中,它现在将我的所有构造函数列为Function<NameOfClass>并单独列出NameOfClass.prototype(似乎没有帮助ScriptDoc或推理)。

我已经在记事本中编写了代码,所以这不应该像我想的那样大,但我仍然非常感谢非黑客的答案。谢谢!

更新更新:

对Aptana源代码的详尽调查揭示了文档和列出的功能与实际实现之间的许多差异。您可以在https://jira.appcelerator.org/browse/APSTUD-4454找到关于此的说明。

1 个答案:

答案 0 :(得分:1)

相关问题