-
Notifications
You must be signed in to change notification settings - Fork 87
Not completing external packages #32
Comments
I'm having the same issue, how frustrating. |
Are you using vim? If so, be certain you followed the installation steps precisely to the letter. |
I'm having the same issus. I'm see it's painc at [cfg.Suggest] -> [types.Eval] -> [check.rawExpr] -> [check.exprInternal] -> [check.ident] -> [check.errorf(e.Pos(), "use of package %s not in selector", obj.name)] And, I'm try install go 1.10.1 and https://github.com/nsf/gocode is OK. |
test pk2.xxx , character offset is 90
Test fmt.xxx, character offset 71
But, https://github.com/nsf/gocode it's OK!!!!
|
This is known issue. gocode make candidates from current package or standard package. So you must enable source importer with If you use vim-go, please try this. diff --git a/autoload/go/complete.vim b/autoload/go/complete.vim
index 127d57f..279b10c 100644
--- a/autoload/go/complete.vim
+++ b/autoload/go/complete.vim
@@ -9,6 +9,7 @@ function! s:gocodeCommand(cmd, args) abort
let cmd = [bin_path]
let cmd = extend(cmd, ['-sock', socket_type])
let cmd = extend(cmd, ['-f', 'vim'])
+ let cmd = extend(cmd, ['-source'])
let cmd = extend(cmd, [a:cmd])
let cmd = extend(cmd, a:args)
|
I'm using emacs and tried to add the -source flag but still no luck |
Well, -source flags must be specified for client not server. |
@mattn And what should be passed in the -source flag? The gopath? |
No extra argument for |
After I added the Seems like autocomplete for external packages was turned off by default on purpose because of this issue. |
@pragmader You will have to use the cache branch if you want to use -source without the slow down. Hopefully @mdempsky will merge it soon. |
I'm ok with applying that kind of patch to gocode's editor plugins. Send pull requests. Well, in case if upstream package repos are built from it. |
@mdempsky I have gotten feedback with completions being slow on using the |
This just started happening for me out of the blue 2 days ago. Internal types work, but as soon as I try to autocomplete for any imported packages there are no candidates. I have tried both with and without As an example, when developing a personal project (https://github.com/johanbrandhorst/certify): package certify
import "github.com/cloudflare/cfssl/signer"
import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
"net/http"
"net/url"
"github.com/cloudflare/cfssl/api/client"
"github.com/cloudflare/cfssl/auth"
"github.com/cloudflare/cfssl/csr"
"github.com/cloudflare/cfssl/signer"
)
// CFSSLIssuer implements the Issuer interface
// with a Cloudflare CFSSL CA server backend.
//
// URL is required.
type CFSSLIssuer struct {
// URL specifies the URL to the CFSSL server.
URL *url.URL
// TLSConfig allows configuration of the TLS config
// used when connecting to the CFSSL server.
TLSConfig *tls.Config
// Profile is the profile on the CFSSL server
// that should be used. If unset, the default
// profile will be used.
Profile string
// Auth optionally configures the authentication
// that should be used.
Auth auth.Provider
remote client.Remote
remoteCertPEM []byte
csrGenerator *csr.Generator
}
// Connect creates a new connection to the CFSSL server
// and sends a request to validate server availability. If not called,
// a connection will be made in the first Issue call.
func (m *CFSSLIssuer) Connect(ctx context.Context) error {
m.remote = client.NewServerTLS(m.URL.String(), m.TLSConfig)
// Add context to requests
m.remote.SetReqModifier(func(req *http.Request, _ []byte) {
*req = *req.WithContext(ctx)
})
signer.#
// Use the Info endpoint as a PING to check server availability
resp, err := m.remote.Info([]byte(`{}`))
if err != nil {
return err
}
m.remoteCertPEM = []byte(resp.Certificate)
m.csrGenerator = &csr.Generator{Validator: func(req *csr.CertificateRequest) error {
return nil
}}
return nil
}
// Issue issues a certificate with the provided options
func (m *CFSSLIssuer) Issue(ctx context.Context, commonName string, conf *CertConfig) (*tls.Certificate, error) {
if m.remote == nil {
err := m.Connect(ctx)
if err != nil {
return nil, err
}
}
// Add context to requests
m.remote.SetReqModifier(func(req *http.Request, _ []byte) {
*req = *req.WithContext(ctx)
})
csrReq := csr.CertificateRequest{
CN: commonName,
KeyRequest: csr.NewBasicKeyRequest(),
}
if conf != nil {
csrReq.Hosts = append(csrReq.Hosts, conf.SubjectAlternativeNames...)
for _, ip := range conf.IPSubjectAlternativeNames {
csrReq.Hosts = append(csrReq.Hosts, ip.String())
}
}
csrPEM, keyPEM, err := m.csrGenerator.ProcessRequest(&csrReq)
if err != nil {
return nil, err
}
req := signer.SignRequest{
Request: string(csrPEM),
Profile: m.Profile,
}
reqBytes, err := json.Marshal(&req)
if err != nil {
return nil, err
}
var certPEM []byte
if m.Auth != nil {
certPEM, err = m.remote.AuthSign(reqBytes, nil, m.Auth)
} else {
certPEM, err = m.remote.Sign(reqBytes)
}
if err != nil {
return nil, err
}
caChainPEM := append(append(certPEM, '\n'), m.remoteCertPEM...)
tlsCert, err := tls.X509KeyPair(caChainPEM, keyPEM)
if err != nil {
return nil, err
}
// This can't error since it's called in tls.X509KeyPair above successfully
tlsCert.Leaf, _ = x509.ParseCertificate(tlsCert.Certificate[0])
return &tlsCert, nil
}
2018/08/16 10:24:35 -------------------------------------------------------
2018/08/16 10:24:35 Error parsing input file (outer block):
2018/08/16 10:24:35 <GOPATH>/src/github.com/johanbrandhorst/certify/cfssl.go:50:9: expected selector or type assertion, found ';'
2018/08/16 10:24:35 <GOPATH>/src/github.com/johanbrandhorst/certify/cfssl.go:53:2: expected ';', found 'IDENT' resp
2018/08/16 10:24:35 Elapsed duration: 54.732397ms
2018/08/16 10:24:35 Offset: 0
2018/08/16 10:24:35 Number of candidates found: 0
2018/08/16 10:24:35 Candidates are:
2018/08/16 10:24:35 ======================================================= This should include all the different symbols on the I use |
The same is true of variables of imported types: 2018/08/16 10:41:31 Got autocompletion request for '<GOPATH>/src/github.com/johanbrandhorst/certify/cfssl.go'
2018/08/16 10:41:31 Cursor at: 1606
2018/08/16 10:41:31 -------------------------------------------------------
package certify
import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
"net/http"
"net/url"
"github.com/cloudflare/cfssl/api/client"
"github.com/cloudflare/cfssl/auth"
"github.com/cloudflare/cfssl/csr"
"github.com/cloudflare/cfssl/signer"
)
// CFSSLIssuer implements the Issuer interface
// with a Cloudflare CFSSL CA server backend.
//
// URL is required.
type CFSSLIssuer struct {
// URL specifies the URL to the CFSSL server.
URL *url.URL
// TLSConfig allows configuration of the TLS config
// used when connecting to the CFSSL server.
TLSConfig *tls.Config
// Profile is the profile on the CFSSL server
// that should be used. If unset, the default
// profile will be used.
Profile string
// Auth optionally configures the authentication
// that should be used.
Auth auth.Provider
remote client.Remote
remoteCertPEM []byte
csrGenerator *csr.Generator
}
// Connect creates a new connection to the CFSSL server
// and sends a request to validate server availability. If not called,
// a connection will be made in the first Issue call.
func (m *CFSSLIssuer) Connect(ctx context.Context) error {
m.remote = client.NewServerTLS(m.URL.String(), m.TLSConfig)
// Add context to requests
m.remote.SetReqModifier(func(req *http.Request, _ []byte) {
*req = *req.WithContext(ctx)
})
// Use the Info endpoint as a PING to check server availability
resp, err := m.remote.Info([]byte(`{}`))
if err != nil {
return err
}
m.remoteCertPEM = []byte(resp.Certificate)
m.csrGenerator = &csr.Generator{Validator: func(req *csr.CertificateRequest) error {
req.#
return nil
}}
return nil
}
// Issue issues a certificate with the provided options
func (m *CFSSLIssuer) Issue(ctx context.Context, commonName string, conf *CertConfig) (*tls.Certificate, error) {
if m.remote == nil {
err := m.Connect(ctx)
if err != nil {
return nil, err
}
}
// Add context to requests
m.remote.SetReqModifier(func(req *http.Request, _ []byte) {
*req = *req.WithContext(ctx)
})
csrReq := csr.CertificateRequest{
CN: commonName,
KeyRequest: csr.NewBasicKeyRequest(),
}
if conf != nil {
csrReq.Hosts = append(csrReq.Hosts, conf.SubjectAlternativeNames...)
for _, ip := range conf.IPSubjectAlternativeNames {
csrReq.Hosts = append(csrReq.Hosts, ip.String())
}
}
csrPEM, keyPEM, err := m.csrGenerator.ProcessRequest(&csrReq)
if err != nil {
return nil, err
}
req := signer.SignRequest{
Request: string(csrPEM),
Profile: m.Profile,
}
reqBytes, err := json.Marshal(&req)
if err != nil {
return nil, err
}
var certPEM []byte
if m.Auth != nil {
certPEM, err = m.remote.AuthSign(reqBytes, nil, m.Auth)
} else {
certPEM, err = m.remote.Sign(reqBytes)
}
if err != nil {
return nil, err
}
caChainPEM := append(append(certPEM, '\n'), m.remoteCertPEM...)
tlsCert, err := tls.X509KeyPair(caChainPEM, keyPEM)
if err != nil {
return nil, err
}
// This can't error since it's called in tls.X509KeyPair above successfully
tlsCert.Leaf, _ = x509.ParseCertificate(tlsCert.Certificate[0])
return &tlsCert, nil
}
2018/08/16 10:41:31 -------------------------------------------------------
2018/08/16 10:41:31 Error parsing input file (outer block):
2018/08/16 10:41:31 <GOPATH>/src/github.com/johanbrandhorst/certify/cfssl.go:59:7: expected selector or type assertion, found ';'
2018/08/16 10:41:31 <GOPATH>/src/github.com/johanbrandhorst/certify/cfssl.go:60:3: expected ';', found 'return'
2018/08/16 10:41:31 Elapsed duration: 73.65926ms
2018/08/16 10:41:31 Offset: 0
2018/08/16 10:41:31 Number of candidates found: 0
2018/08/16 10:41:31 Candidates are:
2018/08/16 10:41:31 ======================================================= Interestingly, the line before this says 2018/08/16 10:41:31 Got autocompletion request for '<GOPATH>/src/github.com/johanbrandhorst/certify/cfssl.go'
2018/08/16 10:41:31 Cursor at: 1603
2018/08/16 10:41:31 -------------------------------------------------------
package certify
import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
"net/http"
"net/url"
"github.com/cloudflare/cfssl/api/client"
"github.com/cloudflare/cfssl/auth"
"github.com/cloudflare/cfssl/csr"
"github.com/cloudflare/cfssl/signer"
)
// CFSSLIssuer implements the Issuer interface
// with a Cloudflare CFSSL CA server backend.
//
// URL is required.
type CFSSLIssuer struct {
// URL specifies the URL to the CFSSL server.
URL *url.URL
// TLSConfig allows configuration of the TLS config
// used when connecting to the CFSSL server.
TLSConfig *tls.Config
// Profile is the profile on the CFSSL server
// that should be used. If unset, the default
// profile will be used.
Profile string
// Auth optionally configures the authentication
// that should be used.
Auth auth.Provider
remote client.Remote
remoteCertPEM []byte
csrGenerator *csr.Generator
}
// Connect creates a new connection to the CFSSL server
// and sends a request to validate server availability. If not called,
// a connection will be made in the first Issue call.
func (m *CFSSLIssuer) Connect(ctx context.Context) error {
m.remote = client.NewServerTLS(m.URL.String(), m.TLSConfig)
// Add context to requests
m.remote.SetReqModifier(func(req *http.Request, _ []byte) {
*req = *req.WithContext(ctx)
})
// Use the Info endpoint as a PING to check server availability
resp, err := m.remote.Info([]byte(`{}`))
if err != nil {
return err
}
m.remoteCertPEM = []byte(resp.Certificate)
m.csrGenerator = &csr.Generator{Validator: func(req *csr.CertificateRequest) error {
r#
return nil
}}
return nil
}
// Issue issues a certificate with the provided options
func (m *CFSSLIssuer) Issue(ctx context.Context, commonName string, conf *CertConfig) (*tls.Certificate, error) {
if m.remote == nil {
err := m.Connect(ctx)
if err != nil {
return nil, err
}
}
// Add context to requests
m.remote.SetReqModifier(func(req *http.Request, _ []byte) {
*req = *req.WithContext(ctx)
})
csrReq := csr.CertificateRequest{
CN: commonName,
KeyRequest: csr.NewBasicKeyRequest(),
}
if conf != nil {
csrReq.Hosts = append(csrReq.Hosts, conf.SubjectAlternativeNames...)
for _, ip := range conf.IPSubjectAlternativeNames {
csrReq.Hosts = append(csrReq.Hosts, ip.String())
}
}
csrPEM, keyPEM, err := m.csrGenerator.ProcessRequest(&csrReq)
if err != nil {
return nil, err
}
req := signer.SignRequest{
Request: string(csrPEM),
Profile: m.Profile,
}
reqBytes, err := json.Marshal(&req)
if err != nil {
return nil, err
}
var certPEM []byte
if m.Auth != nil {
certPEM, err = m.remote.AuthSign(reqBytes, nil, m.Auth)
} else {
certPEM, err = m.remote.Sign(reqBytes)
}
if err != nil {
return nil, err
}
caChainPEM := append(append(certPEM, '\n'), m.remoteCertPEM...)
tlsCert, err := tls.X509KeyPair(caChainPEM, keyPEM)
if err != nil {
return nil, err
}
// This can't error since it's called in tls.X509KeyPair above successfully
tlsCert.Leaf, _ = x509.ParseCertificate(tlsCert.Certificate[0])
return &tlsCert, nil
}
2018/08/16 10:41:31 -------------------------------------------------------
2018/08/16 10:41:31 Elapsed duration: 119.334264ms
2018/08/16 10:41:31 Offset: 0
2018/08/16 10:41:31 Number of candidates found: 5
2018/08/16 10:41:31 Candidates are:
2018/08/16 10:41:31 func real(c ComplexType) FloatType
2018/08/16 10:41:31 func recover() interface{}
2018/08/16 10:41:31 type rune rune
2018/08/16 10:41:31 var req *invalid type
2018/08/16 10:41:31 var resp invalid type
2018/08/16 10:41:31 ======================================================= Sounds suspicious I guess? |
@mdempsky I believe the |
I have tracked this down to (in my case)
Using the source importer works, but is unacceptably slow. I've tried deleting $GOPATH/pkg and rebuilding all packages but it still can't find the imports. @ramya-rao-a is it possible to enable the use of the |
@johanbrandhorst It is possible, but like you said it slows things down, so I dont know how helpful that can be. I can have a different build out for the go plugin that uses the |
@ramya-rao-a I realised I could just rebuild the gocode binary and force source mode, so don't worry :). I will try to keep digging as to why this is happening though. Today I've managed to write a program that successfully calls gcimporter.Import and at the same time have gocode get an error on the same gcimporter.Import call. Very spooky :/. |
For emacs friends using (setf company-go-gocode-args '("-source")) Per @nsf 's comment, I will try and find some time to issue a PR against Please note that this does incur all the slowdowns that are being discussed here -- even with libraries residing in |
I have two go env in one machine, if i build gocode with Can you tell me what's going on here? |
So I wiped my entire Arch installation in an attempt to fix this.. and it worked. So it's clearly an environmental problem, though I do not know how or why. If you get desperate (like I did), recreating your entire environment might well work. Just purging all of your Go stuff and reinstalling that also might work, but I was due a reinstall anyway. |
I had the same issue. After removing old |
Any updates on this issue? What's the latest status of the cache branch? |
I will be investigating merging the cache branch soon. |
The caching branch was merged in #71. |
This is only partly related, but since switching gocode to the mdempsky version with go1.11, all external packages result in
|
@dvcrn: do you mind filing a separate issue for your case? |
Sure, will do! /e #79 |
I switched over to this fork as nsf/gocode wasn't working at all after go 1.10. Local completion works fine, as does the standard library but as soon as i try to complete an external library or type (e.g github.com/sirupsen/logrus) gocode tells me that 0 candidates were found. I tried a complete clean install but nothing seems to work.
The text was updated successfully, but these errors were encountered: