首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Typescript LanguageService不提供数组类型的自动完成信息

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

Stack Overflow用户
提问于 2016-02-16 18:51:51
回答 1查看 178关注 0票数 1

我已经为Typescript LanguageService (https://github.com/BestSolution-at/java2typescript)实现了一个java桥,它工作起来非常流畅,但我遇到了以下问题。

让我们假设我有以下类型的文件(sample.ts)

代码语言:javascript
复制
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接口):

代码语言:javascript
复制
CompletionInfo info = service.getCompletionsAtPosition(fileId, 424);
info.entries().stream().forEach( i -> {
  service.getCompletionEntryDetails(fileId, 424, i.name());
});

为我提供以下信息(编码为JSON):

代码语言:javascript
复制
{
  "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": [

    ]
  }
}

..。

代码语言:javascript
复制
{
  "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)。

EN

回答 1

Stack Overflow用户

发布于 2016-02-17 17:13:39

回答我自己的问题:我忘记预先加载lib.d.ts。加载lib.d.ts解决了这个问题!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35430552

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档