4

我目前想使用带有 PHP 的 monaco 编辑器,并且我想通过自动完成来扩展它,用于常规 PHP 函数以及自定义函数。

虽然函数的自动完成功能在我早期的原型上运行良好,但自动完成参数不起作用。参见小提琴的例子: https ://jsfiddle.net/95aq6497/2/

目前,只有函数 substr 被提供为自动完成并且正在工作。但是,由 registerSignatureHelpProvider 定义的参数的帮助器不起作用:

 monaco.languages.registerSignatureHelpProvider('php', {
provideSignatureHelp: (model, position, token) => {
  console.log('Signature Help');
  return {
    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.'
        }
      ]
    }]
  };
}

});

该功能甚至没有执行,因为 console.log 根本没有触发。我错过了什么?通过一个函数类似地扩展 javascript 像这样工作得很好,但它不适用于 PHP,那么这里有什么不同呢?

4

1 回答 1

3

看起来你没有提供signatureHelpTriggerCharacters选项:

monaco.languages.registerSignatureHelpProvider('php', {
  signatureHelpTriggerCharacters: ['(', ','],  <==================== this one
  provideSignatureHelp: (model, position, token) => {

https://jsfiddle.net/hec12da1/

要实现provideSignatureHelp功能,我建议您查看 typescript version

https://github.com/Microsoft/monaco-typescript/blob/7027f0b4ba56fc0df136fb41791aa27e8c25ef54/src/languageFeatures.ts#L262

于 2018-02-02T09:44:42.700 回答