Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some completions not shown on pressing dot while handling dynamic completions #4855

Open
rchl opened this issue Sep 24, 2021 · 12 comments
Open

Comments

@rchl
Copy link

rchl commented Sep 24, 2021

Description

The completions popup behavior is potentially non-ideal when pressing . during handling of the completions shown with the DYNAMIC_COMPLETIONS flag.

This use case is straight from LSP where a server might return completions like aa.MethodA but once the user types aa., the on_query_completions is triggered with empty prefix and then the server returns just MethodA completion. So in that case it would be natural to be able to see that completion but ST closes the completion popup on pressing the dot.

Steps to reproduce

  1. Create an user plugin:
import sublime_plugin
from sublime import CompletionItem, CompletionList, DYNAMIC_COMPLETIONS


class CompletionListener(sublime_plugin.ViewEventListener):
    def on_query_completions(self, prefix, locations):
        print('on_query_completions, prefix: ', prefix)
        if prefix == 'aa':
            completions = [
                CompletionItem(kind=(3, 'm', 'Method'), trigger='aa.MethodA'),
            ]
        elif prefix == '':
            completions = [
                CompletionItem(kind=(3, 'm', 'Method'), trigger='MethodA'),
            ]
        else:
            return
        completion_list = CompletionList()
        completion_list.set_completions(completions, flags=DYNAMIC_COMPLETIONS)
        return completion_list
  1. Open a blank tab
  2. Set the syntax to Python for example
  3. Type aa
  4. Once the completion popup is visible, press . (dot)

Expected behavior

That the completion popup opens (or stays open) and shows the MethodA item.

Actual behavior

The completion popup closes.

Environment

  • Build: 4115
  • Operating system and version: macOS 11.6
@rchl
Copy link
Author

rchl commented Nov 16, 2021

As observed in the issue that bothers gopls users, it's not so much that the completion popup is closed on pressing . but rather ST no longer considers completions that don't start with the "full" prefix.

This plugin demonstrates the issue better:

import sublime
import sublime_plugin
from sublime import CompletionItem, CompletionList


class CompletionListener(sublime_plugin.ViewEventListener):

    def on_query_completions(self, prefix, locations):
        if prefix in ('f', 'fm', 'fmt'):
            completions = [
                CompletionItem('fmt.module', annotation='"fmt"', kind=(3, 'm', 'Method'))
            ]
        elif prefix == '':
            completions = [
                CompletionItem(kind=(3, 'm', 'Method'), trigger='PASS'),
                CompletionItem(kind=(3, 'm', 'Method'), trigger='fmt.ONE_COMPLETIONS_IS_A_FAIL-TWO_IS_A_PASS'),
            ]
        else:
            return
        completion_list = CompletionList()
        completion_list.set_completions(
            completions,
            flags=sublime.DYNAMIC_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
        return completion_list

To trigger the faulty behavior, type fmt..
On pressing the dot, ST should show two completions (PASS and fmt.ONE_COMPLETIONS_IS_A_FAIL-TWO_IS_A_PASS). It only shows the latter since it seems like it doesn't consider the dot to reset the internal prefix (even though the prefix passed to on_query_completions is correctly an empty string).

Also note that manually triggering completion after the dot triggers both completions.

Screen.Recording.2021-11-16.at.21.05.24.mov

@rchl rchl changed the title Completions not shown on pressing dot while handling dynamic completions Some completions not shown on pressing dot while handling dynamic completions Nov 16, 2021
@pelemarse
Copy link

Is there any progress on this bug? This bug has been annoying for more than a year.

@alecthomas
Copy link

Any progress on this? This has been an issue since at least Aug 2021...

@hartsublime
Copy link

@alecthomas @pelemarse There's a MR for a fix.

@hartsublime
Copy link

@quapo merge request

@BenjaminSchaaf
Copy link
Member

Fixed in build 4132.

@predragnikolic
Copy link

predragnikolic commented May 16, 2023

Can we reopen this ticket? @rchl

This bug was reintroduced in build 4138. (build 4137 is the last build that worked as expected)

I tried the example from this comment
and it no longer works as expected in build 4138.

@rchl
Copy link
Author

rchl commented May 16, 2023

I'm not able anymore.

@predragnikolic
Copy link

Can you please take a look, @BenjaminSchaaf ?

@rchl
Copy link
Author

rchl commented Jun 19, 2023

Can someone please re-open?

@jvican
Copy link

jvican commented Aug 3, 2023

Is there any plans to reintroduce the fix for the bug? I'm affected by this bug.

@jvican
Copy link

jvican commented Oct 25, 2023

Hey @BenjaminSchaaf, I see there are new Sublime Text releases in October. Would it be possible to prioritize this bug fix? I can't upgrade because this bug still remains in the latest versions, and it's quite an annoying one for UX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants