emacs-lsp / lsp-metals

lsp-mode :heart: metals
https://emacs-lsp.github.io/lsp-metals
GNU General Public License v3.0
58 stars 34 forks source link

InputBox Provider feature #6

Closed kpbochenek closed 2 years ago

kpbochenek commented 4 years ago

Specs for LSP for initialization message: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize

When sending ClientCapabilities client can add experimental section that is custom for different client/server settings.

Metals supports parameter inputBoxProvider that is boolean and can be set to true/false.

If this setting is set to true metals will assume this request can be handled by client:

  /**
   * Opens an input box to ask the user for input.
   *
   * @return the user provided input.
   */
  @JsonRequest("metals/inputBox")
  def metalsInputBox(
      params: MetalsInputBoxParams
  ): MetalsInputBoxResult

Command name will be: metals/inputBox Request will contain this parameter(it is as with all other requets serialized to json)

case class MetalsInputBoxParams(
    // The value to prefill in the input box
    @Nullable value: String = null,
    // The text to display underneath the input box.
    @Nullable prompt: String = null
)

response:

case class MetalsInputBoxResult(
    // value=null when cancelled=true
    @Nullable value: String = null,
    @Nullable cancelled: java.lang.Boolean = null
)
kpbochenek commented 4 years ago

Example: https://github.com/kpbochenek/emacs-scala-metals Creating new file from template is best example as it uses this feature and messageBox.

When you execute command metals.new-scala-file metals will ask client firstly about one of a few choices(class, trait, ...) and then expect to type name of file.

A gif showing how it looks in VSCode attached in mentioned repo.

kurnevsky commented 2 years ago

Done in https://github.com/emacs-lsp/lsp-metals/pull/67