Sublime Forum

Range for on_query_completions and callback auto_complete

#1

Hi,

I am a contributor to a sublime plugin providing LSP support available here and would like to suggest improvements for the Sublime API

on_query_completions in the Sublime Text API has two major limitations when it comes to auto complete.

First, Sublime Text replaces only the prefix with the user choice for auto completion and doesn’t allow arbitrary text replacment but there are scenarios were completion has to replace before the prefix. This is very common for LSP servers.
Example:

// first
def myF<ctrl+space>

// could lead to
override def myFunction1(): Unit = ???

// but currently leads to this invalid code :(
def override def myFunction1(): Unit = ???

Notice that we have to do something before the prefix myF.

So one feature request would be to allow on_query_completions (or have an other function) to return with each user choice the range (or the start position) from which we do the replacement.

Second limitation is the lack of callback, once the user has made the choice for the auto complete there is no way to know which choice the user made. This is again needed for LSP implementations.

Example: after completing to function name

new SimpleFileVisitor[Path] {
  override def visitFil<ctrl+space>
}

.We need to insert add an import

import java.nio.file.attribute.BasicFileAttributes
new SimpleFileVisitor[Path] {
  override def visitFil<ctrl+space>
}

So the feature request would be to allow registering a callback with result of on_query_completions to be called after user choice.

These two features would allow developers to provide a better user experience related to auto complete

1 Like

#2

arguably, both the override and the import could be handled by the callback, without the range additions

as we already have a commit_completion command/event which gets fired, it could perhaps include an arg of which completion, in case that simplifies implementation.
but this’d need to be resolved first:

1 Like

#3

you are right the commit_completion would be enough if we have more context about user choice :slight_smile:

0 Likes

#4

FYI someone also created an issue about the prefix completion issue https://github.com/SublimeTextIssues/Core/issues/2754

0 Likes

#5

@wbond any chance having these two issues tackled in the future?

0 Likes

#6

I haven’t looked at this post yet, but if you have something actionable you want added to Sublime Text, the issue tracker tends to be the best place. Stuff on the forum here is more of a place to have conversations that can be searched against.

0 Likes

#7

@wbond Sure they are actually two issues already, I pinged you there with no reply that is why I used the forum

https://github.com/SublimeTextIssues/Core/issues/2077 => detect user choice after completion
https://github.com/SublimeTextIssues/Core/issues/2754 => allow range remplacement in completion

They are basically blocking several issues on LSP package

cc @rwols

0 Likes

#8

Ok, if they are in the issue tracker then we’ll see them as we are working on things.

0 Likes