Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Completions inside of backticks #418

@harpocrates

Description

@harpocrates

Is your feature request related to a problem? Please describe.

Metals does a good job of suggesting identifier completions when the prefix for the identifier is not backticked. However, once backticks come into play, the experience degrades a bit.

For example, in the following code snippet, the This is a method name completion might or might not still be present. If the initial completion list was incomplete, then typing up to This is a may trigger VS code to ask for document/textCompletions again, but now the text buffer no longer contains a single valid identifier.

object Test {
  def `This is a method name` = 123
  this.This is a @@ // Cursor at `@@`
}

The solution I'd expect to have for the above is that as a user I might need to write the backticks upfront and then trigger completions inside the backticks. That way, as I type the prefix for my method, I stay in the intermediate state of having a valid preceding identifier:

object Test {
  def `This is a method name` = 123
  this.`This is a @@` // Cursor at `@@`
}

However, in this case, Metals gives no completions (not even when just at this.`@@` or this.`T@@`)

(I'm not sure how widespread this (ab)use of backticks is, but I'm working in codebases where there's a fluent-like DSL that heavily encourages these English sentence form names, so completions there are a bit miserable).

Describe the solution you'd like

Solution I think is coherent:

  • completions should work inside of backticks just the same as outside (just that the prefix might now include characters it couldn't in a non-back ticked case)
  • if you are requesting a completion from inside backticks, Metals should not remove the backticks when you select a completion and, (if the selected completion needs backticks) Metals should also not add a second pair of backticks
  • completions should ideally trigger even on the "empty backticks" case, eg `@@` or myObj.`@@` (with Auto-close backticks scala/vscode-scala-syntax#280, this means that you get put into this completing state just by typing a single `)

I went and implemented this for 2.13.x to see how it felt (harpocrates/metals@98d2ce5, though you'll need a small Scala compiler patch as well - see commit). Here's what it looks like:

Basic completions inside of backicks
Image

Manually re-triggering the completion after a space character (mocking up the case where VS code might do this automatically because the original completions were incomplete)
Image

Once inside backticks, completing a non-backticked identifier still leaves the backticks
Image

All of the above should hold for backticked select's as well
Image

Describe alternatives you've considered

We could continue not showing any completions when the identifier prefix under the cursor is backticked. 😄

Additional context

No response

Search terms

completions backticks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions