Skip to content

Commit

Permalink
Improve gogoproto compatibility logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kralicky committed Nov 22, 2023
1 parent 6c86de1 commit 85ba7ce
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 35 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/bufbuild/protocompile v0.4.0
github.com/bufbuild/protovalidate-go v0.3.4
github.com/gogo/protobuf v1.3.2
github.com/google/cel-go v0.18.1
github.com/kralicky/gpkg v0.0.0-20220311205216-0d8ea9557555
github.com/mattn/go-tty v0.0.5
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
Expand All @@ -32,8 +30,6 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kralicky/gpkg v0.0.0-20220311205216-0d8ea9557555 h1:w/v9aYd9gdL0pEofCiOM7MWNroB9+HWxHT29Wj2NMYc=
github.com/kralicky/gpkg v0.0.0-20220311205216-0d8ea9557555/go.mod h1:EJrGSfmocDg2CBjHDm3zy9oxNKCSGhf+MNTiN1DRbKA=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down
6 changes: 0 additions & 6 deletions pkg/lsp/compat.go

This file was deleted.

31 changes: 7 additions & 24 deletions pkg/lsp/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/bufbuild/protocompile"
"github.com/bufbuild/protocompile/linker"
gogo "github.com/gogo/protobuf/proto"
"github.com/kralicky/protols/pkg/format"
"golang.org/x/tools/gopls/pkg/lsp/cache"
"golang.org/x/tools/gopls/pkg/lsp/protocol"
Expand Down Expand Up @@ -287,6 +286,13 @@ func (r *Resolver) findFileByPathLocked(path string, whence protocompile.ImportC
}
}

if filepath.Base(path) == "gogo.proto" {
if result, err := r.checkGoModule("github.com/gogo/protobuf/gogoproto/gogo.proto", whence); err == nil {
lg.Debug("resolved to special case (go module: gogo.proto)")
return result, nil
}
}

lg.Debug("could not resolve path")
return protocompile.SearchResult{}, os.ErrNotExist
}
Expand All @@ -295,29 +301,6 @@ func (r *Resolver) checkWellKnownImportPath(path string) (protocompile.SearchRes
if strings.HasPrefix(path, "google/") {
return r.checkGlobalCache(path)
}
if filepath.Base(path) == "gogo.proto" {
descriptorBytes := gogo.FileDescriptor("gogo.proto")
if descriptorBytes != nil {
fd, err := DecodeRawFileDescriptor(descriptorBytes)
if err != nil {
return protocompile.SearchResult{}, err
}
*fd.Name = path
syntheticURI := url.URL{
Scheme: "proto",
Path: path,
Fragment: r.folder.Name,
}
uri := span.URI(syntheticURI.String())
r.filePathsByURI[uri] = path
r.fileURIsByPath[path] = uri
r.importSourcesByURI[uri] = SourceWellKnown
return protocompile.SearchResult{
ResolvedPath: protocompile.ResolvedPath(path),
Proto: fd,
}, nil
}
}
return protocompile.SearchResult{}, os.ErrNotExist
}

Expand Down

0 comments on commit 85ba7ce

Please sign in to comment.