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

gopls completions re-ordered #576

Open
muirdm opened this issue Dec 22, 2020 · 5 comments
Open

gopls completions re-ordered #576

muirdm opened this issue Dec 22, 2020 · 5 comments

Comments

@muirdm
Copy link

muirdm commented Dec 22, 2020

Hello again.

With gopls/company-mode I'm seeing eglot re-order the top completion candidate:

package main

func fooBar() {}

func _() {
	var sbp string
	var s struct { blah int }
	var _ int = sb<>
}

Completing at <> I expect to see "s.blah" as the top candidate (because the type matches) but I see "sbp".

[server-reply] (id:277) Tue Dec 22 09:32:34 2020:
(:jsonrpc "2.0" :result
          (:isIncomplete t :items
                         [(:label "s.blah" :kind 5 :detail "int" :preselect t :sortText "00000" :filterText "s.blah" :insertTextFormat 2 :textEdit
                                  (:range
                                   (:start
                                    (:line 6 :character 13)
                                    :end
                                    (:line 6 :character 15))
                                   :newText "s.blah"))
                          (:label "sbp" :kind 9 :detail "\"github.com/go-playground/locales/sbp\"" :sortText "00001" :filterText "sbp" :insertTextFormat 2 :textEdit
                                  (:range
                                   (:start
                                    (:line 6 :character 13)
                                    :end
                                    (:line 6 :character 15))
                                   :newText "sbp")
                                  :additionalTextEdits
                                  [(:range
                                    (:start
                                     (:line 1 :character 0)
                                     :end
                                     (:line 1 :character 0))
                                    :newText "\nimport \"github.com/go-playground/locales/sbp\"\n")])
                          (:label "sbp_TZ" :kind 9 :detail "\"github.com/go-playground/locales/sbp_TZ\"" :sortText "00002" :filterText "sbp_TZ" :insertTextFormat 2 :textEdit
                                  (:range
                                   (:start
                                    (:line 6 :character 13)
                                    :end
                                    (:line 6 :character 15))
                                   :newText "sbp_TZ")
                                  :additionalTextEdits
                                  [(:range
                                    (:start
                                     (:line 1 :character 0)
                                     :end
                                     (:line 1 :character 0))
                                    :newText "\nimport \"github.com/go-playground/locales/sbp_TZ\"\n")])])
          :id 277)

Screen Shot 2020-12-22 at 9 34 42 AM

@joaotavora
Copy link
Owner

joaotavora commented Dec 22, 2020

as soon as you enable the flex completion style, its sorting algorithm kicks in. sb is a closer match to sbp than it is to sbp_TZ, or s.blah, according to that algorithm, because you're very close to typing the whole word in the first case.

There's no way to tweak that algorithm, and at any rate in would not be done in Eglot.

@joaotavora
Copy link
Owner

(Full disclosure, I wrote the flex algorithm in Emacs, too)

@muirdm
Copy link
Author

muirdm commented Dec 22, 2020

I see, thanks.

gopls does a lot of type aware candidate ordering, so ideally the client would not re-order candidates at all based purely on text matching.

Previously VSCode had the same issue so gopls worked around it by giving all candidates the same "filterText" to trick VSCode into not re-ordering anything. That hack has since been removed from gopls.

Is there any good way forward with this?

@joaotavora
Copy link
Owner

joaotavora commented Dec 22, 2020

Don't know. A first instinct seems to be to have a flex-nosort completion style. You see, the reason why some kind of sorting is usually absolutely vital in flex is because the filtering step lets so many candidates through. IOW if you have a population of thousands symbols and you type a couple of letters, the number of candidates is extremely large and if you don't have any sorting built-in, it becomes useless.

But the Go LS is already prefiltering the results, so one wouldn't have that problem. On the other hand, other servers might not prefilter stuff.

Let's leave this issue open and maybe someone wants to comment. @monnier usually has useful things to say about completion styles and sorting.

Anyway, can you confirm that invoking company manually without (without any prefix text) displays the available candidates in the order that the Go LS intended them?

@muirdm
Copy link
Author

muirdm commented Dec 22, 2020

can you confirm that invoking company manually without (without any prefix text) displays the available candidates in the order that the Go LS intended them?

Yes, confirmed.

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

No branches or pull requests

2 participants