我已经为Typescript LanguageService (https://github.com/BestSolution-at/java2typescript)实现了一个java桥,它工作起来非常流畅,但我遇到了以下问题。
让我们假设我有以下类型的文件(sample.ts)
class Person {
firstname : string;
lastname : string;
friendList : Person[];
constructor(firstname : string, lastname : string) {
this.firstname = firstname;
this.lastname = lastname;
}
public getName() {
return this.lastname + ", " + this.firstname;
}
public getFirstname() {
return this.firstname;
}
}
var p : Person = new Person("Tom","Schindl");
p.执行以下Java代码(接口同LanguageService接口):
CompletionInfo info = service.getCompletionsAtPosition(fileId, 424);
info.entries().stream().forEach( i -> {
service.getCompletionEntryDetails(fileId, 424, i.name());
});为我提供以下信息(编码为JSON):
{
"requestIdRef": 4,
"result": {
"name": "firstname",
"kindModifiers": "",
"kind": "property",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "property",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Person",
"kind": "className"
},
{
"text": ".",
"kind": "punctuation"
},
{
"text": "firstname",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "string",
"kind": "keyword"
}
],
"documentation": [
]
}
}..。
{
"requestIdRef": 6,
"result": {
"name": "friendList",
"kindModifiers": "",
"kind": "property",
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "property",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Person",
"kind": "className"
},
{
"text": ".",
"kind": "punctuation"
},
{
"text": "friendList",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "{",
"kind": "punctuation"
},
{
"text": "}",
"kind": "punctuation"
}
],
"documentation": [
]
}
}正如您注意到的,具有内置类型的属性的完成细节是有效的(displayParts中的最后一段),而对于自定义类型,我没有得到任何信息。
由于VS-Code正在显示它必须可用的信息,奇怪的是,在查看他们的代码时,他们发出的LanguageService调用与我相同(https://github.com/Microsoft/vscode/blob/master/src/vs/languages/typescript/common/features/suggestions.ts)。
发布于 2016-02-17 17:13:39
回答我自己的问题:我忘记预先加载lib.d.ts。加载lib.d.ts解决了这个问题!
https://stackoverflow.com/questions/35430552
复制相似问题