레이블이 vim-go인 게시물을 표시합니다. 모든 게시물 표시
레이블이 vim-go인 게시물을 표시합니다. 모든 게시물 표시

golangci-lint

# vim 에서 golang generic(1.18)를 사용하는데 lint 에러가 많이 발생한다.
# vim > vim-go > golint 를 사용하고 있고 golint 바이너리는 업데이트 해도 다음과 같은 메시지가 발생한다.
golint ./...
main.go:12:8: expected ';', found '|' (and 4 more errors)

# vim > ale > gofmt 도 다음과 같은 에러 메시지를 발생한다.
gofmt .
main.go:12:8: expected ';', found '|'
main.go:12:10: illegal character U+007E '~'
main.go:16:2: expected '}', found 'return'
main.go:20:2: expected declaration, found result

https://github.com/golang/lint 가보니 2021년에 deprecated 돼 관리가 안되고 있었다.
# gofmt 바이너리는 2018년에 생성된것을 사용하고 있었다.
type gofmt
gofmt is /Users/ysoftman/workspace/gopath/bin/gofmt --> 2018년도
gofmt is /opt/homebrew/bin/gofmt --> ../Cellar/go/1.22.1/bin/gofmt

# golint 는 삭제하고
rm -f $(which golint)

# 2018년도 gofmt 삭제
rm -f /Users/ysoftman/workspace/gopath/bin/gofmt

# 대안으로 https://github.com/golangci/golangci-lint 를 사용하면 된다.
golangci-lint run ./...

# vim-go 설정을 변경
let g:go_metalinter_enabled = ['vet', 'golangci-lint', 'errcheck']

# ale go linter 도 변경
let g:ale_linters = {
\ 'python': ['flake8', 'pylint'],
\ 'javascript': ['eslint'],
\ 'go': ['golangci-lint', 'gofmt']
\}


golang vim-go GOBIN error

# go 1.19.2 버전 설치 후 .go 파일을 열때 다음과 같은 에러가 발생했다.
# :messages 로 확인해보면
vim-go: 'go env GOBIN' failed
vim-go: could not determine appropriate working directory for gopls
FileNotFoundError: [Errno 2] No such file or directory: '/Users/ysoftman/.vim/plugged/youcompleteme/third_party/ycmd/third_party/go/bin/gopls'

# vim plug 를 업데이트해도 에러가 발생한다.
:PlugUpdate

# 참고로 vim-go 최신 소스를 보면 go env gobin > $GOBIN > GOPATH./bin 순으로 찾고 있다.

# 다음과 같이 설정해도 에러가 발생한다.
# GOBIN (go install 시 실행 binary 설치 경로)
go env -w GOBIN=/Users/ysoftman/workspace/gopath/gopath/bin
go env GOBIN

# 원인은 go 실행 자체가 안되는것이 문제였다.
# go 신규 버전 설치시 macOS(darwin)환경인데 linux 바이너리파일을 설치한것이 문제였다.
# go1.19.2.linux-amd64.tar.gz -> go1.19.2.darwin-amd64.tar.gz 로 변경해서 설치해고 go 가 실행된다.
# 이제 GOBIN 을 설정하지 않아도(GOPATH/bin 로 찾는다.) 에러가 없다.
go env -w GOBIN=

# vim-plug 라면 go binary 업데이트도 해주자.
:GoUpdateBinaries

# ycmd 에러 관련해서는 다음과 같이 설치하면 된다.
cd ~/.vim/plugged/youcompleteme/third_party/ycmd/
git checkout master
git pull
git submodule update --init --recursive
./build.py --go-completer

vim-go, fzf c-t 단축키 충돌

# 터미널에서 fzf 를 C-T(control + t)로 기본 사용하고 있어
# vim 환경에서도 같은 shortcut 을 사용하려고 ~/.vimrc 에 다음과 같이 설정했다.
noremap <c-t> :FZF<enter>

# 일반적인 경우에는 잘 동작하는데, *.go 파일을 열었을 경우
# 다음과 같이 godef 스택 관련 명령이 실행된다.
vim-go: godef stack empty

# godef(정의로 이동)를 할때 이동한 위치를 스택으로 쌓는데
https://github.com/fatih/vim-go-tutorial 에 보면
# c-t 는 godef 이전 위치로 이동하는 것으로 지정되어 있다.
# 사용자가 map 으로 설정했지만 .go 에서는 vim-go 의 단축키가 우선하는 것 같다.

# 이런 문제가 나뿐만은 아닌지 이슈가 등록되어 있었다.

# 해결책은 다음과 go_def 매핑을 비활성화시키는 것이다.
let g:go_def_mapping_enabled=0