gopls/internal/mcp: report one-based reference line numbers formatReferences currently embeds zero-based LSP line numbers in its human-readable output. This causes, for example, a declaration on the third source line to be reported as being on line 2. Convert reference line numbers to one-based values for display while retaining zero-based indexing when reading the corresponding source line. Update the MCP marker tests accordingly. Change-Id: I9b7675756e8b828ac7f00fbe371d7e908cfe426c Reviewed-on: https://go-review.googlesource.com/c/tools/+/805820 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Madeline Kalil <mkalil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
diff --git a/gopls/internal/mcp/references.go b/gopls/internal/mcp/references.go index d49bce1..2e82a42 100644 --- a/gopls/internal/mcp/references.go +++ b/gopls/internal/mcp/references.go
@@ -62,7 +62,7 @@ } else { continue } - fmt.Fprintf(&builder, "The reference is located on line %v, which has content `%s`\n", r.Range.Start.Line, lineContent) + fmt.Fprintf(&builder, "The reference is located on line %v, which has content `%s`\n", r.Range.Start.Line+1, lineContent) builder.WriteString("\n") } return textResult(builder.String()), nil
diff --git a/gopls/internal/test/marker/testdata/mcptools/references.txt b/gopls/internal/test/marker/testdata/mcptools/references.txt index 0172076..455e59b 100644 --- a/gopls/internal/test/marker/testdata/mcptools/references.txt +++ b/gopls/internal/test/marker/testdata/mcptools/references.txt
@@ -38,13 +38,13 @@ The object has 3 references. Their locations are listed below Reference 1 Located in the file: $WORKDIR/a/a.go -The reference is located on line 2, which has content `func Foo() {} //@loc(Foo, "Foo")` +The reference is located on line 3, which has content `func Foo() {} //@loc(Foo, "Foo")` Reference 2 Located in the file: $WORKDIR/a/a.go -The reference is located on line 5, which has content `Foo()` +The reference is located on line 6, which has content `Foo()` Reference 3 Located in the file: $WORKDIR/b/b.go -The reference is located on line 5, which has content `a.Foo()` +The reference is located on line 6, which has content `a.Foo()`
diff --git a/gopls/internal/test/marker/testdata/mcptools/symbol_references.txt b/gopls/internal/test/marker/testdata/mcptools/symbol_references.txt index b08a0a2..fdfc08b 100644 --- a/gopls/internal/test/marker/testdata/mcptools/symbol_references.txt +++ b/gopls/internal/test/marker/testdata/mcptools/symbol_references.txt
@@ -40,19 +40,19 @@ The object has 3 references. Their locations are listed below Reference 1 Located in the file: $WORKDIR/a/a.go -The reference is located on line 2, which has content `func Foo() {}` +The reference is located on line 3, which has content `func Foo() {}` Reference 2 Located in the file: $WORKDIR/a/a.go -The reference is located on line 5, which has content `Foo()` +The reference is located on line 6, which has content `Foo()` Reference 3 Located in the file: $WORKDIR/b/b.go -The reference is located on line 5, which has content `a.Foo()` +The reference is located on line 6, which has content `a.Foo()` -- @aBar -- The object has 1 references. Their locations are listed below Reference 1 Located in the file: $WORKDIR/a/a.go -The reference is located on line 10, which has content `func (T) Bar() {}` +The reference is located on line 11, which has content `func (T) Bar() {}`