Skip to content

Allow to extend default signature help for the language #179120

@alenakhineika

Description

@alenakhineika

The contextual signature help for find thinks that any find keyword is the Array.find() method. This is confusing for users of the MongoDB VSCode extension, because MongoDB has its own usage and syntax the find method.

Screenshot 2023-04-03 at 11 48 25

I tried to use the Method Signatures API to extend the current behavior, but I did not find a way to support both the default JavaScript signatures and custom ones for the same language.

The vscode.languages.registerSignatureHelpProvider allows to add custom signatures to the JavaScript language, but the JavaScript signatures always have a priority and overwrite the custom options, they are not merged into a single list where users could see all of the possible options.

this._context.subscriptions.push(
      vscode.languages.registerSignatureHelpProvider({ language: 'javascript' }, new MongodbHelpProvider(), {
        triggerCharacters: MongodbHelpProvider.triggerCharacters,
        retriggerCharacters: MongodbHelpProvider.retriggerCharacters
      })
    );

Another option I have tried is to overwrite the existing SignatureHelpProvide in the language server with connection.onSignatureHelp. But it also didn't work as I expected. We do something similar with connection.onCompletion, and in case we don't have anything to suggest we return an empty array. In this case, vscode shows the native JavaScript completion items. The onSignatureHelp method returns SignatureHelp | undefined | null. In case of the missing result, it does not return default JavaScript signatures.

connection.onSignatureHelp((params: SignatureHelpParams) => {
  return {
    activeSignatureHelp: params.context?.activeSignatureHelp,
    signatures: [{
      label: 'Collection.find(query, projection, options) : Cursor',
      documentation: undefined,
      parameters: []
    }]
  };
});

Not sure what would be the right curse of action here, but either one of those would solve the issue for us:

  • Smarter parsing of the text document content, to not assume that any find is the Array.find() method.
  • Merge native signatures with custom signatures. If the onSignatureHelp method returns empty signatures { signatures: [] } the empty array will be merged with default values for the current language and only default values will be returned.
  • Provide the vscode.languages.getSignatureHelp(document.uri) API to access default values and merge them with custom values manually (similarly to Diagnostics API).

Metadata

Metadata

Assignees

Labels

*as-designedDescribed behavior is as designed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions