scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.08k stars 326 forks source link

Completions for unimported global symbols #61

Closed olafurpg closed 5 years ago

olafurpg commented 6 years ago

Currently, completions only suggest symbols that are available in your active scope. It would be nice if the completions also included symbols that are accessible with an import. LSP CompletionItem has an optional textEdit field to support inserting the import on completion

    /**
     * An edit which is applied to a document when selecting this completion. When an edit is provided the value of
     * `insertText` is ignored.
     *
     * *Note:* The range of the edit must be a single line range and it must contain the position at which completion
     * has been requested.
     */
    textEdit?: TextEdit;

The Java LSP seems to be taking advantage of this.

screen shot 2017-11-25 at 23 02 39

Complete, and import is inserted

screen shot 2017-11-25 at 23 02 52
gabro commented 6 years ago

Just adding that also the TypeScript LSP does this (and it even handles binpacking :O )

olafurpg commented 6 years ago

I actually worked on this feature about a month ago but never got around to complete the PR

2018-01-11 16 24 45

The missing piece was that I don't know yet where to insert the import. I was thinking that it might be nice for starters to insert the import in the leading line above the completion. That would allow you to manually place the import where you like. Any thoughts?

gabro commented 6 years ago

That's cool!

I would just put it on top of the file, after the last import, similarly to what addGlobalImport does.

A future improvement could be adding it to an existing import group if any.

olafurpg commented 5 years ago

Metals doesn't support completions anymore. Completions may get added back in the future but for now I think it's best to close completion-related tickets.