internal/lsp: use rootURI as config.Dir in packages.Load

This change was inspired by https://golang.org/cl/153777.

Fixes golang/go#29174

Change-Id: I9d9a8b95e984c8e70160d199cd1efc5aa2964ef7
Reviewed-on: https://go-review.googlesource.com/c/153863
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2018-12-12 13:57:52 -05:00
parent 4d6773f6fa
commit b620e9ecbe
3 changed files with 9 additions and 3 deletions

View File

@ -21,9 +21,10 @@ type View struct {
files map[source.URI]*File files map[source.URI]*File
} }
func NewView() *View { func NewView(rootPath string) *View {
return &View{ return &View{
Config: &packages.Config{ Config: &packages.Config{
Dir: rootPath,
Mode: packages.LoadSyntax, Mode: packages.LoadSyntax,
Fset: token.NewFileSet(), Fset: token.NewFileSet(),
Tests: true, Tests: true,

View File

@ -58,7 +58,7 @@ func testLSP(t *testing.T, exporter packagestest.Exporter) {
defer exported.Cleanup() defer exported.Cleanup()
s := &server{ s := &server{
view: cache.NewView(), view: cache.NewView(exported.Config.Dir),
} }
// Merge the exported.Config with the view.Config. // Merge the exported.Config with the view.Config.
cfg := *exported.Config cfg := *exported.Config

View File

@ -42,13 +42,18 @@ func (s *server) Initialize(ctx context.Context, params *protocol.InitializePara
if s.initialized { if s.initialized {
return nil, jsonrpc2.NewErrorf(jsonrpc2.CodeInvalidRequest, "server already initialized") return nil, jsonrpc2.NewErrorf(jsonrpc2.CodeInvalidRequest, "server already initialized")
} }
s.view = cache.NewView()
s.initialized = true // mark server as initialized now s.initialized = true // mark server as initialized now
// Check if the client supports snippets in completion items. // Check if the client supports snippets in completion items.
s.snippetsSupported = params.Capabilities.TextDocument.Completion.CompletionItem.SnippetSupport s.snippetsSupported = params.Capabilities.TextDocument.Completion.CompletionItem.SnippetSupport
s.signatureHelpEnabled = true s.signatureHelpEnabled = true
rootPath, err := source.URI(*params.RootURI).Filename()
if err != nil {
return nil, err
}
s.view = cache.NewView(rootPath)
return &protocol.InitializeResult{ return &protocol.InitializeResult{
Capabilities: protocol.ServerCapabilities{ Capabilities: protocol.ServerCapabilities{
CompletionProvider: protocol.CompletionOptions{ CompletionProvider: protocol.CompletionOptions{