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

Can't get argument completion with gopls #326

Closed
xuchunyang opened this issue Oct 26, 2019 · 4 comments
Closed

Can't get argument completion with gopls #326

xuchunyang opened this issue Oct 26, 2019 · 4 comments

Comments

@xuchunyang
Copy link
Contributor

With yas-minor-mode enabled, eglot + gopls still can't complete function argument, for example,

fmt.Errorf()

but lsp-mode with the same gopls can:

fmt.Errorf(format string, a ...interface{})

Through gopls -logfile=/tmp/gopls.log -rpc.trace, the response from gopls and lsp-mode are different, for eglot, it returns

"newText":"Errorf(${1:})"

but for lsp-mode, it returns

"newText":"Errorf(${1:format string}, ${2:a ...interface{\\}})"

By reading lsp-go.el, I assume usePlaceholders needs to be set to true, but the following doesn't work (no argument completion and gopls still returns Errorf(${1:}))

(setq-default eglot-workspace-configuration
                '((gopls (usePlaceholders . t))))

and by grep usePlaceholders in the log, it has

[Trace - 08:18:43.446 AM] Sending notification 'workspace/didChangeConfiguration'.
Params: {"settings":{"gopls":{"usePlaceholders":true}}}

but with lsp-mode, the log has something different

[Trace - 08:15:00.988 AM] Sending response 'workspace/configuration - (1)' took 2ms.
Result: [{"env":{},"buildFlags":[],"hoverKind":"SynopsisDocumentation","usePlaceholders":true},null]

I know eglot doesn't support workspace/configuration according to the README.md. Is it because gopls doesn't support didChangeConfiguration? How can I set usePlaceholders for gopls with eglot if it's possible?

@joaotavora
Copy link
Owner

Hi. This should be relatively easy to fix. Lsp-mode had custom code for every server, eglot doesn't (just two minor exceptions). I will think about adding one more, or adding something else. I'll have to install gopls first, but i was going to have to do that anyway. Hope it's not too hard.

@joaotavora
Copy link
Owner

Should be fixed. For your specific problem, see https://github.com/joaotavora/eglot#per-project-server-configuration

@xuchunyang
Copy link
Contributor Author

Yes, it is fixed. Thanks for your work.

@mohkale
Copy link
Contributor

mohkale commented Jun 23, 2020

Hi, @joaotavora I'm still facing this issue.

I'm on

  • eglot version 20200531.1058 (installed through MELPA)
  • Emacs GNU Emacs 27.0.91 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.17.3) of 2020-06-05
  • gopls golang.org/x/tools/gopls@v0.4.1 h1:0e3BPxGV4B3cd0zdMuccwW72SgmHp92lAjOyxX/ScAw=.

If I enter reflect.DeepEqual and then take the current completion using company, then only the function name/identifier is inserted. There aren't any parentheses or function arguments. The eglot events buffer shows this:

(:jsonrpc "2.0" :result
 (:contents
  (:kind "markdown" :value "```go\nfunc reflect.DeepEqual(x interface{}, y interface{}) bool\n```\n\n[`reflect.DeepEqual` on pkg.go.dev](https://pkg.go.dev/reflect#DeepEqual)\n\nDeepEqual reports whether x and y are “deeply equal,” defined as follows\\.\nTwo values of identical type are deeply equal if one of the following cases applies\\.\nValues of distinct types are never deeply equal\\.\n\nArray values are deeply equal when their corresponding elements are deeply equal\\.\n\nStruct values are deeply equal if their corresponding fields,\nboth exported and unexported, are deeply equal\\.\n\nFunc values are deeply equal if both are nil\\; otherwise they are not deeply equal\\.\n\nInterface values are deeply equal if they hold deeply equal concrete values\\.\n\nMap values are deeply equal when all of the following are true\\:\nthey are both nil or both non\\-nil, they have the same length,\nand either they are the same map object or their corresponding keys\n\\(matched using Go equality\\) map to deeply equal values\\.\n\nPointer values are deeply equal if they are equal using Go\\'s \\=\\= operator\nor if they point to deeply equal values\\.\n\nSlice values are deeply equal when all of the following are true\\:\nthey are both nil or both non\\-nil, they have the same length,\nand either they point to the same initial entry of the same underlying array\n\\(that is, \\&x\\[0\\] \\=\\= \\&y\\[0\\]\\) or their corresponding elements \\(up to length\\) are deeply equal\\.\nNote that a non\\-nil empty slice and a nil slice \\(for example, \\[\\]byte\\{\\} and \\[\\]byte\\(nil\\)\\)\nare not deeply equal\\.\n\nOther values \\- numbers, bools, strings, and channels \\- are deeply equal\nif they are equal using Go\\'s \\=\\= operator\\.\n\nIn general DeepEqual is a recursive relaxation of Go\\'s \\=\\= operator\\.\nHowever, this idea is impossible to implement without some inconsistency\\.\nSpecifically, it is possible for a value to be unequal to itself,\neither because it is of func type \\(uncomparable in general\\)\nor because it is a floating\\-point NaN value \\(not equal to itself in floating\\-point comparison\\),\nor because it is an array, struct, or interface containing\nsuch a value\\.\nOn the other hand, pointer values are always equal to themselves,\neven if they point at or contain such problematic values,\nbecause they compare equal using Go\\'s \\=\\= operator, and that\nis a sufficient condition to be deeply equal, regardless of content\\.\nDeepEqual has been defined so that the same short\\-cut applies\nto slices and maps\\: if x and y are the same slice or the same map,\nthey are deeply equal regardless of content\\.\n\nAs DeepEqual traverses the data values it may find a cycle\\. The\nsecond and subsequent times that DeepEqual compares two pointer\nvalues that have been compared before, it treats the values as\nequal rather than examining the values to which they point\\.\nThis ensures that DeepEqual terminates\\.\n")
  :range
  (:start
   (:line 13 :character 9)
   :end
   (:line 13 :character 18)))
 :id 120)

joaotavora referenced this issue Sep 17, 2022
Also tweak eglot-show-workspace-configuration a bit.

* README.md (Workspace configuration): Rework.

* eglot.el (eglot-show-workspace-configuration): Rework.
(eglot--workspace-configuration-plist): New helper.
bhankas pushed a commit to bhankas/emacs that referenced this issue Sep 18, 2022
This helps users configure servers such as Gopls, which doesn't
support didChangeConfiguration signals.

* README.md (Per-project server configuration): New section.

* eglot.el (eglot-workspace-configuration): Fix docstring.
(eglot-signal-didChangeConfiguration): Rename a variable.
(eglot-handle-request workspace/configuration): New request
handler.
bhankas pushed a commit to bhankas/emacs that referenced this issue Sep 19, 2022
This helps users configure servers such as Gopls, which doesn't
support didChangeConfiguration signals.

* README.md (Per-project server configuration): New section.

* eglot.el (eglot-workspace-configuration): Fix docstring.
(eglot-signal-didChangeConfiguration): Rename a variable.
(eglot-handle-request workspace/configuration): New request
handler.
bhankas pushed a commit to bhankas/emacs that referenced this issue Sep 19, 2022
This helps users configure servers such as Gopls, which doesn't
support didChangeConfiguration signals.

* README.md (Per-project server configuration): New section.

* eglot.el (eglot-workspace-configuration): Fix docstring.
(eglot-signal-didChangeConfiguration): Rename a variable.
(eglot-handle-request workspace/configuration): New request
handler.

#326: joaotavora/eglot#326
jollaitbot pushed a commit to sailfishos-mirror/emacs that referenced this issue Oct 12, 2022
This helps users configure servers such as Gopls, which doesn't
support didChangeConfiguration signals.

* README.md (Per-project server configuration): New section.

* eglot.el (eglot-workspace-configuration): Fix docstring.
(eglot-signal-didChangeConfiguration): Rename a variable.
(eglot-handle-request workspace/configuration): New request
handler.

GitHub-reference: fix joaotavora/eglot#326
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

3 participants