首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >registerSignatureHelpProvider()导致错误:无法读取未定义的属性'signatures‘

registerSignatureHelpProvider()导致错误:无法读取未定义的属性'signatures‘
EN

Stack Overflow用户
提问于 2021-02-09 04:49:22
回答 1查看 162关注 0票数 2

我正在使用Mongo0.22.2,试图提出关于函数参数的建议。我定义了一个简单的例子,如下所示:

代码语言:javascript
复制
monaco.languages.registerSignatureHelpProvider('myCustomLang', {
    signatureHelpTriggerCharacters: ['(', ','],
    provideSignatureHelp: (model, position, token) => {
        return {
            activeParameter: 0,
            activeSignautre: 0,
                signatures: [{
                    label:'string of_string(string $string, int $start)',
                    parameters: [
                        {
                            label: 'string $string',
                            documentation: 'The input string'
                        },
                        {
                            label: 'int $start',
                            documentation: "if $start is non-negative...",
                        }
                    ]
                }]
        };
    }
});

然而,只要我键入"(“或",”来触发此代码,我就会得到错误:

代码语言:javascript
复制
Cannot read property 'signatures' of undefined
TypeError: Cannot read property 'signatures' of undefined
    at ParameterHintsModel.eval (parameterHintsModel.js:166)
    at Generator.next (<anonymous>)
    at fulfilled (parameterHintsModel.js:19)
    at eval (errors.js:24)

我做错了什么?我的常规简单建议会出现,但我无法获得潜在的函数参数建议。

EN

回答 1

Stack Overflow用户

发布于 2021-02-14 08:29:29

响应应该是这样构造的:

代码语言:javascript
复制
  monaco.languages.registerSignatureHelpProvider("myCustomLang", {
    signatureHelpTriggerCharacters: ["(", ","],
    provideSignatureHelp: (model, position, token) => {
      return {
        dispose: () => {},
        value: {
          activeParameter: 0,
          activeSignature: 0,
          signatures: [
            {
              label:
                "string substr(string $string, int $start [, int $length])",
              parameters: [
                {
                  label: "string $string",
                  documentation:
                    "The input string. Must be one character or longer.",
                },
                {
                  label: "int $start",
                  documentation:
                    "If $start is non-negative, the returned string will start at the $start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.\r\nIf $start is negative, the returned string will start at the $start'th character from the end of string. If $string is less than $start characters long, FALSE will be returned.",
                },
                {
                  label: "int $length",
                  documentation:
                    "If $length is given and is positive, the string returned will contain at most $length characters beginning from $start (depending on the length of $string) If $length is given and is negative, then that many characters will be omitted from the end of $string (after the start position has been calculated when a start is negative). If $start denotes the position of this truncation or beyond, FALSE will be returned. If $length is given and is 0, FALSE or NULL, an empty string will be returned. If $length is omitted, the substring starting from $start until the end of the string will be returned.",
                },
              ],
            },
          ],
        },
      };
    },
  });

响应类型为SignatureHelpResult,它应该有一个valuedispose方法。value应为带有activeParameter activeSignaturesignaturesSignatureHelp

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

https://stackoverflow.com/questions/66109154

复制
相关文章

相似问题

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