Skip to content

Commit

Permalink
Merge pull request #234 from mercari/fix_candidates_match
Browse files Browse the repository at this point in the history
Fix Candidates method file match
  • Loading branch information
shuheiktgw committed Aug 20, 2024
2 parents bec3655 + 75852c1 commit c201922
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion resolver/candidates.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c ValueCandidates) Filter(typ *Type) ValueCandidates {

func (r *Resolver) Candidates(loc *source.Location) []string {
for _, file := range r.files {
if strings.HasSuffix(file.GetName(), loc.FileName) {
if strings.HasSuffix(loc.FileName, file.GetName()) {
protoPkgName := file.GetPackage()
switch {
case loc.Message != nil:
Expand Down
2 changes: 1 addition & 1 deletion source/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (f *File) buildLocation(ctx *findContext) *Location {

// FindLocationByPos returns the corresponding location information from the position in the source code.
func (f *File) FindLocationByPos(pos Position) *Location {
ctx := &findContext{fileName: f.fileNode.Name()}
ctx := &findContext{fileName: f.Path()}
for _, decl := range f.fileNode.Decls {
ctx := ctx.child()
switch n := decl.(type) {
Expand Down
20 changes: 10 additions & 10 deletions source/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestFile_FindLocationByPos(t *testing.T) {
Col: 47,
},
expected: &source.Location{
FileName: "service.proto",
FileName: "testdata/service.proto",
Service: &source.Service{
Name: "FederationService",
Method: &source.Method{
Expand All @@ -54,7 +54,7 @@ func TestFile_FindLocationByPos(t *testing.T) {
Col: 16,
},
expected: &source.Location{
FileName: "service.proto",
FileName: "testdata/service.proto",
Service: &source.Service{
Name: "FederationService",
Method: &source.Method{
Expand All @@ -72,7 +72,7 @@ func TestFile_FindLocationByPos(t *testing.T) {
Col: 20,
},
expected: &source.Location{
FileName: "service.proto",
FileName: "testdata/service.proto",
Message: &source.Message{
Name: "Post",
Option: &source.MessageOption{
Expand All @@ -92,7 +92,7 @@ func TestFile_FindLocationByPos(t *testing.T) {
Col: 29,
},
expected: &source.Location{
FileName: "service.proto",
FileName: "testdata/service.proto",
Message: &source.Message{
Name: "Post",
Option: &source.MessageOption{
Expand All @@ -114,7 +114,7 @@ func TestFile_FindLocationByPos(t *testing.T) {
Col: 39,
},
expected: &source.Location{
FileName: "service.proto",
FileName: "testdata/service.proto",
Message: &source.Message{
Name: "Post",
Option: &source.MessageOption{
Expand All @@ -136,7 +136,7 @@ func TestFile_FindLocationByPos(t *testing.T) {
Col: 47,
},
expected: &source.Location{
FileName: "service.proto",
FileName: "testdata/service.proto",
Message: &source.Message{
Name: "GetPostResponse",
Field: &source.Field{
Expand All @@ -154,7 +154,7 @@ func TestFile_FindLocationByPos(t *testing.T) {
Col: 15,
},
expected: &source.Location{
FileName: "service.proto",
FileName: "testdata/service.proto",
Message: &source.Message{
Name: "GetPostResponse",
Option: &source.MessageOption{
Expand All @@ -176,7 +176,7 @@ func TestFile_FindLocationByPos(t *testing.T) {
Col: 24,
},
expected: &source.Location{
FileName: "service.proto",
FileName: "testdata/service.proto",
Message: &source.Message{
Name: "GetPostResponse",
Option: &source.MessageOption{
Expand All @@ -198,7 +198,7 @@ func TestFile_FindLocationByPos(t *testing.T) {
Col: 34,
},
expected: &source.Location{
FileName: "service.proto",
FileName: "testdata/service.proto",
Message: &source.Message{
Name: "GetPostResponse",
Option: &source.MessageOption{
Expand All @@ -220,7 +220,7 @@ func TestFile_FindLocationByPos(t *testing.T) {
Col: 26,
},
expected: &source.Location{
FileName: "service.proto",
FileName: "testdata/service.proto",
Message: &source.Message{
Name: "Post",
Option: &source.MessageOption{
Expand Down

0 comments on commit c201922

Please sign in to comment.