saibing / bingo

Bingo is a Go language server that speaks Language Server Protocol.
MIT License
495 stars 25 forks source link

Completion on a constant returns it's value as well #111

Closed paulbdavis closed 5 years ago

paulbdavis commented 5 years ago

Requesting a completion on a constant returns the value it is set to as well

package main

const foo = "bar"

var bar = "foo"

func main() {
    // completing on "f"
    foo = "bar"
    // completing on "b"
    bar
}

This is occurring using eglot in emacs

The data coming back from bingo looks like this (in elisp)

(:jsonrpc "2.0" :method "textDocument/didChange" :params
          (:textDocument
           (:uri "file:///home/paul/dev/test/bingo/issue.go" :version 134)
           :contentChanges
           [(:range
             (:start
              (:line 8 :character 1)
              :end
              (:line 8 :character 2))
             :rangeLength 1 :text "")
            (:range
             (:start
              (:line 8 :character 1)
              :end
              (:line 8 :character 1))
             :rangeLength 0 :text "foo = \"bar\"")]))

(:jsonrpc "2.0" :method "textDocument/didChange" :params
          (:textDocument
           (:uri "file:///home/paul/dev/test/bingo/issue.go" :version 138)
           :contentChanges
           [(:range
             (:start
              (:line 10 :character 1)
              :end
              (:line 10 :character 2))
             :rangeLength 1 :text "")
            (:range
             (:start
              (:line 10 :character 1)
              :end
              (:line 10 :character 1))
             :rangeLength 0 :text "bar")]))

I'm not sure if this is a bingo issue or something on my client's configuration

saibing commented 5 years ago

@paulbdavis

I can't reproduce the problem in both vscode and coc.nvim, I don't use emacs, is it an issue handled by emacs lsp client?

phux commented 5 years ago

I can reproduce it with neovim with prabirshrestha/vim-lsp. It is using the label field instead of the insertText or newText fields if insertTextFormat exists but != 1.

For constants, bingo currently returns "insertTextFormat": 2, which stands for a snippet So I think changing it in bingo to 1 (= plain text) will at least fix it in vim-lsp, not sure about the emacs plugin though.

paulbdavis commented 5 years ago

This issue is only happening on the latest tagged release. Building from master solves it.