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

GoExtract sends incorrect location to LSP #3615

Closed
novadev94 opened this issue Dec 23, 2023 · 1 comment · Fixed by #3617
Closed

GoExtract sends incorrect location to LSP #3615

novadev94 opened this issue Dec 23, 2023 · 1 comment · Fixed by #3617
Labels

Comments

@novadev94
Copy link

novadev94 commented Dec 23, 2023

What did you do?

I tried to use :GoExtract on lines of code. Take this code as an example

package main        // 1
                    // 2
import "fmt"        // 3
                    // 4
func main() {       // 5
	fmt.Println(1)  // 6
	fmt.Println(2)  // 7
	fmt.Println(3)  // 8
}                   // 9

I selected lines 6 -> 8 (either via linewise visual mode or regular one) then run :'<,'>GoExtract.

What did you expect to happen?

All the 3 fmt.Println lines get extracted to a new function, resulting in something like this.

package main

import "fmt"

func main() {
	newFunction()
}

func newFunction() {
	fmt.Println(1)
	fmt.Println(2)
	fmt.Println(3)
}

What happened instead?

Only the last 2 fmt.Println lines get extracted. Resulting in.

package main

import "fmt"

func main() {
	fmt.Println(1)
	newFunction()
}

func newFunction() {
	fmt.Println(2)
	fmt.Println(3)
}

Configuration (MUST fill this out):

vim-go version:

Commit 7fb38264e3ab5c57a43de2470f22eccc62f82c02 (latest commit on master).

vimrc you used to reproduce:

vimrc
call plug#begin('~/.nvim/.plugs')
Plug 'fatih/vim-go'
call plug#end()

Vim version (first three lines from :version):

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1700008891

Go version (go version):

go version go1.21.5 darwin/arm64

Go environment

go env Output:
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/novadev/Library/Caches/go-build'
GOENV='/Users/novadev/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/novadev/.go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/novadev/.go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.21.5/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.21.5/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.5'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/lr/52fjbm9x3gd6qq33hmy91mxw0000gn/T/go-build3061960217=/tmp/go-build -gno-record-gcc-switches -fno-common'

gopls version

gopls version Output:
golang.org/x/tools/gopls (devel)
    golang.org/x/tools/gopls@(devel)
@bhcleek
Copy link
Collaborator

bhcleek commented Dec 23, 2023

I can duplicate what you're describing. Interestingly, Vim's help has this to say about the visual markers:

							*'<* *`<*
'<  `<			To the first line or character of the last selected
			Visual area in the current buffer.  For block mode it
			may also be the last character in the first line (to
			be able to define the block).

							*'>* *`>*
'>  `>			To the last line or character of the last selected
			Visual area in the current buffer.  For block mode it
			may also be the first character of the last line (to
			be able to define the block).  Note that 'selection'
			applies, the position may be just after the Visual
			area.

Which corresponds to what we're seeing here. I'll see if there's a correct way to figure out the full extent of the visual selection.

@bhcleek bhcleek added the bug label Dec 23, 2023
bhcleek added a commit to bhcleek/vim-go that referenced this issue Dec 24, 2023
Fix line selection for extraction.

Fixes fatih#3615
bhcleek added a commit to bhcleek/vim-go that referenced this issue Dec 24, 2023
Fix line selection for extraction.

Fixes fatih#3615
bhcleek added a commit to bhcleek/vim-go that referenced this issue Dec 24, 2023
Fix line selection for extraction.

Fixes fatih#3615
bhcleek added a commit to bhcleek/vim-go that referenced this issue Dec 24, 2023
Fix line selection for extraction.

Fixes fatih#3615
bhcleek added a commit to bhcleek/vim-go that referenced this issue Dec 24, 2023
Fix line selection for extraction.

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

Successfully merging a pull request may close this issue.

2 participants