Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Commit 6252729

Browse files
author
Henry Wong
authored
[elastic] Fix the compile errors after sync to the upstream. (#81)
Note: The index time increase almost 15% than #79
1 parent 0e25f39 commit 6252729

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

go/packages/golist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ var (
644644
goListLRUEntries = 16 * 32
645645
)
646646

647-
func golistDriverLRUCached(cfg *Config, rootsDirs func() map[string]string, words ...string) (*driverResponse, error) {
647+
func golistDriverLRUCached(cfg *Config, rootsDirs func() *goInfo, words ...string) (*driverResponse, error) {
648648
createGoListLRUCache.Do(func() {
649649
goListLRUCache, _ = lru.New(goListLRUEntries)
650650
})

internal/lsp/elasticserver.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ func (s *ElasticServer) RunElasticServer(ctx context.Context) error {
9393
func (s *ElasticServer) EDefinition(ctx context.Context, params *protocol.TextDocumentPositionParams) ([]protocol.SymbolLocator, error) {
9494
uri := span.NewURI(params.TextDocument.URI)
9595
view := s.session.ViewOf(uri)
96-
f, m, err := getGoFile(ctx, view, uri)
96+
f, err := getGoFile(ctx, view, uri)
9797
if err != nil {
9898
return nil, err
9999
}
100+
m, err := getMapper(ctx, f)
100101
spn, err := m.PointSpan(params.Position)
101102
if err != nil {
102103
return nil, err
@@ -117,15 +118,19 @@ func (s *ElasticServer) EDefinition(ctx context.Context, params *protocol.TextDo
117118
}
118119
qname := getQName(ctx, f, declObj, kind)
119120

120-
declSpan, err := ident.DeclarationRange().Span()
121+
decSpan, err := ident.DeclarationRange().Span()
121122
if err != nil {
122123
return nil, err
123124
}
124-
_, decM, err := getSourceFile(ctx, view, declSpan.URI())
125+
decFile, err := getGoFile(ctx, view, decSpan.URI())
125126
if err != nil {
126127
return nil, err
127128
}
128-
loc, err := decM.Location(declSpan)
129+
decM, err := getMapper(ctx, decFile)
130+
if err != nil {
131+
return nil, err
132+
}
133+
loc, err := decM.Location(decSpan)
129134
if err != nil {
130135
return nil, err
131136
}
@@ -156,15 +161,16 @@ func (s *ElasticServer) Full(ctx context.Context, fullParams *protocol.FullParam
156161
return fullResponse, nil
157162
}
158163
view := s.session.ViewOf(uri)
159-
f, _, err := getGoFile(ctx, view, uri)
164+
f, err := getGoFile(ctx, view, uri)
160165
if err != nil {
161166
return fullResponse, err
162167
}
163168
path := f.URI().Filename()
164-
if f.GetPackage(ctx) == nil {
169+
pkg, err := f.GetPackage(ctx)
170+
if err != nil {
165171
return fullResponse, err
166172
}
167-
pkgLocator, _ := collectPkgMetadata(f.GetPackage(ctx).GetTypes(), view.Folder().Filename(), s, path)
173+
pkgLocator, _ := collectPkgMetadata(pkg.GetTypes(), view.Folder().Filename(), s, path)
168174

169175
detailSyms, err := constructDetailSymbol(s, ctx, &params, &pkgLocator)
170176
if err != nil {
@@ -605,7 +611,12 @@ func getDeclObj(ctx context.Context, f source.GoFile, pos token.Pos) types.Objec
605611
case *ast.SelectorExpr:
606612
astIdent = node.Sel
607613
}
608-
return f.GetPackage(ctx).GetTypesInfo().ObjectOf(astIdent)
614+
pkg, err := f.GetPackage(ctx)
615+
if err != nil {
616+
return nil
617+
}
618+
619+
return pkg.GetTypesInfo().ObjectOf(astIdent)
609620
}
610621

611622
func constructDetailSymbol(s *ElasticServer, ctx context.Context, params *protocol.DocumentSymbolParams, pkgLocator *protocol.PackageLocator) (detailSyms []protocol.DetailSymbolInformation, err error) {

internal/lsp/protocol/elasticserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"golang.org/x/tools/internal/jsonrpc2"
7-
"golang.org/x/tools/internal/lsp/telemetry/log"
7+
"golang.org/x/tools/internal/telemetry/log"
88
)
99

1010
type ElasticServer interface {

internal/lsp/workspace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"context"
99

1010
"golang.org/x/tools/internal/lsp/protocol"
11-
"golang.org/x/tools/internal/lsp/telemetry/log"
1211
"golang.org/x/tools/internal/span"
12+
"golang.org/x/tools/internal/telemetry/log"
1313
errors "golang.org/x/xerrors"
1414
"os/exec"
1515
)

0 commit comments

Comments
 (0)