Typescript LanguageService不提供数组类型的自动完成信息

时间:2016-02-16 10:51:51

标签: typescript

我已经为Typescript LanguageService(https://github.com/BestSolution-at/java2typescript)实现了一个java-bridge,它工作得很顺利,但我遇到了以下问题。

假设我有以下的Typescript-File(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代码(API与LanguageService API相同):

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正在显示必须可用的信息,奇怪的是,查看他们的代码,他们发出的语言服务调用次数与我(https://github.com/Microsoft/vscode/blob/master/src/vs/languages/typescript/common/features/suggestions.ts)相同。

1 个答案:

答案 0 :(得分:0)

回答我自己的问题:我忘了先加载lib.d.ts.加载lib.d.ts可以解决问题!