Skip to content

Commit

Permalink
internal/lsp: use rootURI as config.Dir in packages.Load
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
stamblerre committed Dec 12, 2018
1 parent 4d6773f commit b620e9e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion internal/lsp/cache/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/lsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit b620e9e

Please sign in to comment.