mirror of
https://github.com/golang/go
synced 2024-11-18 13:34:41 -07:00
internal/lsp: remove extra go env GOMOD
logic for single file mode
Now that the view always looks for its module, we don't need to pass in the module root path when creating a view. This allows us to remove some extra logic. Change-Id: I35ffb71ec762b2dec0b72c84195ce008f7b35872 Reviewed-on: https://go-review.googlesource.com/c/tools/+/247897 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
parent
74512f09e4
commit
d77521d074
@ -11,7 +11,6 @@ import (
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/tools/internal/gocommand"
|
||||
"golang.org/x/tools/internal/jsonrpc2"
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
@ -82,22 +81,7 @@ func (s *Server) didOpen(ctx context.Context, params *protocol.DidOpenTextDocume
|
||||
// are no views in the session. I don't know if that logic should go
|
||||
// here, or if we can continue to rely on that implementation detail.
|
||||
if _, err := s.session.ViewOf(uri); err != nil {
|
||||
// Run `go env GOMOD` to detect a module root. If we are not in a module,
|
||||
// just use the current directory as the root.
|
||||
dir := filepath.Dir(uri.Filename())
|
||||
stdout, err := (&gocommand.Runner{}).Run(ctx, gocommand.Invocation{
|
||||
Verb: "env",
|
||||
Args: []string{"GOMOD"},
|
||||
BuildFlags: s.session.Options().BuildFlags,
|
||||
Env: s.session.Options().Env,
|
||||
WorkingDir: dir,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if stdout.String() != "" {
|
||||
dir = filepath.Dir(stdout.String())
|
||||
}
|
||||
if err := s.addFolders(ctx, []protocol.WorkspaceFolder{{
|
||||
URI: string(protocol.URIFromPath(dir)),
|
||||
Name: filepath.Base(dir),
|
||||
|
Loading…
Reference in New Issue
Block a user