gopls/internal/analysis/fillswitch: use qualified type names

The message is now of the form "Add cases for pkg.Type" when
the type is imported from another package.

Fixes golang/go#68225

Change-Id: I310f5354d2fb519c1e85d37b313594ccd50353f0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/597275
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Alan Donovan 2024-07-09 13:49:52 +01:00
Родитель febceba19e
Коммит 71c553722e
3 изменённых файлов: 8 добавлений и 9 удалений

Просмотреть файл

@ -12,6 +12,7 @@ import (
"go/types"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/internal/typesinternal"
)
// Diagnose computes diagnostics for switch statements with missing cases
@ -125,7 +126,7 @@ func suggestedFixTypeSwitch(stmt *ast.TypeSwitchStmt, pkg *types.Package, info *
}
return &analysis.SuggestedFix{
Message: fmt.Sprintf("Add cases for %s", namedType.Obj().Name()),
Message: "Add cases for " + types.TypeString(namedType, typesinternal.NameRelativeTo(pkg)),
TextEdits: []analysis.TextEdit{{
Pos: stmt.End() - token.Pos(len("}")),
End: stmt.End() - token.Pos(len("}")),
@ -176,7 +177,7 @@ func suggestedFixSwitch(stmt *ast.SwitchStmt, pkg *types.Package, info *types.In
addDefaultCase(&buf, namedType, stmt.Tag)
return &analysis.SuggestedFix{
Message: fmt.Sprintf("Add cases for %s", namedType.Obj().Name()),
Message: "Add cases for " + types.TypeString(namedType, typesinternal.NameRelativeTo(pkg)),
TextEdits: []analysis.TextEdit{{
Pos: stmt.End() - token.Pos(len("}")),
End: stmt.End() - token.Pos(len("}")),

Просмотреть файл

@ -4,9 +4,7 @@
package fillswitch
import (
data "b"
)
import altb "b"
type typeA int
@ -36,9 +34,9 @@ func doSwitch() {
case typeAThree:
}
var b data.TypeB
switch b { // want `Add cases for TypeB`
case data.TypeBOne:
var b altb.TypeB
switch b { // want `Add cases for b.TypeB`
case altb.TypeBOne:
}
}

Просмотреть файл

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fillswitch
package b
type TypeB int