Skip to content

Commit

Permalink
fixes after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
ShoshinNikita committed Mar 31, 2023
1 parent a7fbd1e commit 8cc75a7
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 150 deletions.
2 changes: 1 addition & 1 deletion gopls/internal/lsp/regtest/marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func RunMarkerTests(t *testing.T, dir string) {
if _, err := fmt.Sscanf(test.minGoVersion, "go1.%d", &go1point); err != nil {
t.Fatalf("parsing -min_go version: %v", err)
}
testenv.NeedsGo1Point(t, 18)
testenv.NeedsGo1Point(t, go1point)
}
config := fake.EditorConfig{
Settings: test.settings,
Expand Down
32 changes: 19 additions & 13 deletions gopls/internal/lsp/source/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ func hover(ctx context.Context, snapshot Snapshot, fh FileHandle, pp protocol.Po

// TODO(rfindley): we could do much better for inferred signatures.
if inferred := inferredSignature(pkg.GetTypesInfo(), ident); inferred != nil {
s := inferredSignatureString(obj, qf, inferred)
if s != "" {
if s := inferredSignatureString(obj, qf, inferred); s != "" {
signature = s
}
}
Expand Down Expand Up @@ -584,7 +583,7 @@ func hoverLit(pgf *ParsedGoFile, lit *ast.BasicLit, pos token.Pos) (protocol.Ran

// inferredSignatureString is a wrapper around the types.ObjectString function
// that adds more information to inferred signatures. It will return an empty string
// if passed types.Object is not a signature.
// if the passed types.Object is not a signature.
func inferredSignatureString(obj types.Object, qf types.Qualifier, inferred *types.Signature) string {
// If the signature type was inferred, prefer the inferred signature with a
// comment showing the generic signature.
Expand All @@ -605,12 +604,17 @@ func inferredSignatureString(obj types.Object, qf types.Qualifier, inferred *typ

// objectString is a wrapper around the types.ObjectString function.
// It handles adding more information to the object string.
// If spec is non-nil, it may be used to format additional declaration
// syntax, and file must be the token.File describing its positions.
func objectString(obj types.Object, qf types.Qualifier, declPos token.Pos, file *token.File, spec ast.Spec) string {
str := types.ObjectString(obj, qf)

switch obj := obj.(type) {
case *types.Const:
declaration := obj.Val().String()
var (
declaration = obj.Val().String() // default formatted declaration
comment = "" // if non-empty, a clarifying comment
)

// Try to use the original declaration.
switch obj.Val().Kind() {
Expand All @@ -619,24 +623,23 @@ func objectString(obj types.Object, qf types.Qualifier, declPos token.Pos, file
// Also strings can be very long. So, just use the constant's value.

default:
if file == nil || spec == nil {
break
}

switch spec := spec.(type) {
case *ast.ValueSpec:
if spec, _ := spec.(*ast.ValueSpec); spec != nil {
for i, name := range spec.Names {
if declPos == name.Pos() {
if i < len(spec.Values) {
declaration = FormatNodeFile(file, spec.Values[i])
originalDeclaration := FormatNodeFile(file, spec.Values[i])
if originalDeclaration != declaration {
comment = declaration
declaration = originalDeclaration
}
}
break
}
}
}
}

comment := obj.Val().String()
// Special formatting cases.
switch typ := obj.Type().(type) {
case *types.Named:
// Try to add a formatted duration as an inline comment.
Expand All @@ -647,9 +650,12 @@ func objectString(obj types.Object, qf types.Qualifier, declPos token.Pos, file
}
}
}
if comment == declaration {
comment = ""
}

str += " = " + declaration
if declaration != comment {
if comment != "" {
str += " // " + comment
}
}
Expand Down
66 changes: 0 additions & 66 deletions gopls/internal/lsp/testdata/godef/a/g.go

This file was deleted.

67 changes: 0 additions & 67 deletions gopls/internal/lsp/testdata/godef/a/g.go.golden

This file was deleted.

2 changes: 1 addition & 1 deletion gopls/internal/lsp/testdata/summary.txt.golden
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SemanticTokenCount = 3
SuggestedFixCount = 65
FunctionExtractionCount = 27
MethodExtractionCount = 6
DefinitionsCount = 60
DefinitionsCount = 46
TypeDefinitionsCount = 18
HighlightsCount = 69
InlayHintsCount = 4
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/lsp/testdata/summary_go1.18.txt.golden
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SemanticTokenCount = 3
SuggestedFixCount = 71
FunctionExtractionCount = 27
MethodExtractionCount = 6
DefinitionsCount = 60
DefinitionsCount = 46
TypeDefinitionsCount = 18
HighlightsCount = 69
InlayHintsCount = 5
Expand Down
Loading

0 comments on commit 8cc75a7

Please sign in to comment.