emacs go 开发环境

11 篇文章 1 订阅

gocode+auto-complete搭建emacs的go语言自动补全功能

 

下面是我的配置,写给自己看的

(add-to-list 'load-path "/home/wangjunsheng/go/emacs/go-mode")
(require 'go-mode)
(define-key go-mode-map [(meta ?g)] 'godef-jump)

(custom-set-variables '(gofmt-command "goimports"))
(define-key go-mode-map "\C-c\C-f" 'gofmt)


(add-to-list 'load-path "/home/wangjunsheng/.emacs.d")
(require 'go-autocomplete)
(require 'auto-complete-config)
(ac-config-default)

 

(setq ac-use-menu-map t)
(define-key ac-menu-map "\C-n" 'ac-next)
(define-key ac-menu-map "\C-p" 'ac-previous)

 

如果 godef 无法跳转 可以加入 -debug 参数看看 原因

比如下面是成功的

godef -debug -f root_run.go mqttpubsub.NewBackend
2019/02/20 15:45:18 exprType tuple:false pkg: *ast.SelectorExpr mqttpubsub.NewBackend [
2019/02/20 15:45:18 exprType tuple:false pkg: *ast.Ident mqttpubsub [
2019/02/20 15:45:18 exprType tuple:false pkg: *ast.ImportSpec "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub" [
2019/02/20 15:45:18 ] -> 0x0, Type{package "" *ast.ImportSpec "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub"}
2019/02/20 15:45:18 ] -> 0x1a6004b0, Type{package "" *ast.ImportSpec "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub"}
2019/02/20 15:45:18 member Type{package "" *ast.ImportSpec "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub"} 'NewBackend' {
2019/02/20 15:45:18 } -> &{func NewBackend 0x1a5619e0 <nil> <nil>}
2019/02/20 15:45:18 exprType tuple:false pkg: *ast.Ident NewBackend [
2019/02/20 15:45:18 exprType tuple:false pkg: *ast.FuncType func(c newMQTT.BackendConfig) (*Backend, error) [
2019/02/20 15:45:18 ] -> 0x0, Type{type "" *ast.FuncType func(c newMQTT.BackendConfig) (*Backend, error)}
2019/02/20 15:45:18 ] -> 0x1a530330, Type{func "" *ast.FuncType func(c newMQTT.BackendConfig) (*Backend, error)}
2019/02/20 15:45:18 ] -> 0x1a530330, Type{func "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub" *ast.FuncType func(c newMQTT.BackendConfig) (*Backend, error)}
/home/wangjunsheng/go/gopath/src/github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub/backend.go:38:6

 

 再比如下面这个不成功的例子

godef -debug -f root_run.go mqttpubsub.NewBackend
2019/02/20 15:23:05 exprType tuple:false pkg: *ast.SelectorExpr mqttpubsub.NewBackend [
2019/02/20 15:23:05 exprType tuple:false pkg: *ast.Ident mqttpubsub [
2019/02/20 15:23:05 exprType tuple:false pkg: *ast.ImportSpec "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub" [
2019/02/20 15:23:05 ] -> 0x0, Type{package "" *ast.ImportSpec "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub"}
2019/02/20 15:23:05 ] -> 0x194f8000, Type{package "" *ast.ImportSpec "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub"}
2019/02/20 15:23:05 member Type{package "" *ast.ImportSpec "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub"} 'NewBackend' {
2019/02/20 15:23:06 	/home/wangjunsheng/go/gopath/src/github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub/metrics.go:7:2: cannot find identifier for package "github.com/prometheus/client_golang/prometheus": cannot find package "github.com/prometheus/client_golang/prometheus" in any of:
	/home/wangjunsheng/go/go/src/github.com/prometheus/client_golang/prometheus (from $GOROOT)
	/home/wangjunsheng/go/gopath/src/github.com/prometheus/client_golang/prometheus (from $GOPATH)
2019/02/20 15:23:06 } -> <nil>
2019/02/20 15:23:06 ] -> 0x0, Type{bad "" <nil> }
2019/02/20 15:23:06 exprType tuple:false pkg: *ast.SelectorExpr mqttpubsub.NewBackend [
2019/02/20 15:23:06 exprType tuple:false pkg: *ast.Ident mqttpubsub [
2019/02/20 15:23:06 exprType tuple:false pkg: *ast.ImportSpec "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub" [
2019/02/20 15:23:06 ] -> 0x0, Type{package "" *ast.ImportSpec "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub"}
2019/02/20 15:23:06 ] -> 0x194f8000, Type{package "" *ast.ImportSpec "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub"}
2019/02/20 15:23:06 member Type{package "" *ast.ImportSpec "github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub"} 'NewBackend' {
2019/02/20 15:23:06 	/home/wangjunsheng/go/gopath/src/github.com/brocaar/lora-gateway-bridge/internal/legacy/backend/mqttpubsub/metrics.go:7:2: cannot find identifier for package "github.com/prometheus/client_golang/prometheus": cannot find package "github.com/prometheus/client_golang/prometheus" in any of:
	/home/wangjunsheng/go/go/src/github.com/prometheus/client_golang/prometheus (from $GOROOT)
	/home/wangjunsheng/go/gopath/src/github.com/prometheus/client_golang/prometheus (from $GOPATH)
2019/02/20 15:23:06 } -> <nil>
2019/02/20 15:23:06 ] -> 0x0, Type{bad "" <nil> }
godef: no declaration found for mqttpubsub.NewBackend

借助日志,我们可以看到是因为没有相应的 go 第三方库导致的。 下载这些库可以解决问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值