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:
parent
4d6773f6fa
commit
b620e9ecbe
|
@ -21,9 +21,10 @@ type View struct {
|
|||
files map[source.URI]*File
|
||||
}
|
||||
|
||||
func NewView() *View {
|
||||
func NewView(rootPath string) *View {
|
||||
return &View{
|
||||
Config: &packages.Config{
|
||||
Dir: rootPath,
|
||||
Mode: packages.LoadSyntax,
|
||||
Fset: token.NewFileSet(),
|
||||
Tests: true,
|
||||
|
|
|
@ -58,7 +58,7 @@ func testLSP(t *testing.T, exporter packagestest.Exporter) {
|
|||
defer exported.Cleanup()
|
||||
|
||||
s := &server{
|
||||
view: cache.NewView(),
|
||||
view: cache.NewView(exported.Config.Dir),
|
||||
}
|
||||
// Merge the exported.Config with the view.Config.
|
||||
cfg := *exported.Config
|
||||
|
|
|
@ -42,13 +42,18 @@ func (s *server) Initialize(ctx context.Context, params *protocol.InitializePara
|
|||
if s.initialized {
|
||||
return nil, jsonrpc2.NewErrorf(jsonrpc2.CodeInvalidRequest, "server already initialized")
|
||||
}
|
||||
s.view = cache.NewView()
|
||||
s.initialized = true // mark server as initialized now
|
||||
|
||||
// Check if the client supports snippets in completion items.
|
||||
s.snippetsSupported = params.Capabilities.TextDocument.Completion.CompletionItem.SnippetSupport
|
||||
s.signatureHelpEnabled = true
|
||||
|
||||
rootPath, err := source.URI(*params.RootURI).Filename()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.view = cache.NewView(rootPath)
|
||||
|
||||
return &protocol.InitializeResult{
|
||||
Capabilities: protocol.ServerCapabilities{
|
||||
CompletionProvider: protocol.CompletionOptions{
|
||||
|
|
Loading…
Reference in New Issue