Skip to content

Commit

Permalink
gopls/internal/goxls/testdata: add overload unimported test
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Mar 21, 2024
1 parent 17f3133 commit 9cda23a
Show file tree
Hide file tree
Showing 17 changed files with 230 additions and 58 deletions.
10 changes: 10 additions & 0 deletions gopls/internal/goxls/testdata/overload/c/add.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package c

func Add = (
func(a, b int) int {
return a + b
}
func(a, b string) string {
return a + b
}
)
3 changes: 3 additions & 0 deletions gopls/internal/goxls/testdata/overload/c/gop_autogen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions gopls/internal/goxls/testdata/overload/c/method.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package c

type Foo struct {
}

func (a *Foo) MulInt(b int) *Foo { //@mark(c_foo_mulInt,"MulInt")
println "mulInt"
return a
}

func (a *Foo) MulFoo(b *Foo) *Foo { //@mark(c_foo_mulFoo,"MulFoo")
println "mulFoo"
return a
}

func (Foo).Mul = (
(Foo).MulInt
(Foo).MulFoo
)
14 changes: 14 additions & 0 deletions gopls/internal/goxls/testdata/overload/c/mul.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package c

func MulInt(a, b int) int { //@mark(c_mulInt,"MulInt")
return a * b
}

func MulFloat(a, b float64) float64 { //@mark(c_mulFloat,"MulFloat")
return a * b
}

func Mul = (
MulInt
MulFloat
)
33 changes: 33 additions & 0 deletions gopls/internal/goxls/testdata/overload/d/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package d

const GopPackage = true

type Foo struct {
}

const Gopo_Foo_Mul = ".MulInt,.MulFoo"
const Gopo_Mul = "MulInt,MulFloat"

func Add__0(a int, b int) int { //@mark(d_add__0,"Add__0")
return a + b
}

func Add__1(a string, b string) string { //@mark(d_add__1,"Add__1")
return a + b
}

func (a *Foo) MulInt(b int) *Foo { //@mark(d_foo_mulInt,"MulInt")
return a
}

func (a *Foo) MulFoo(b *Foo) *Foo { //@mark(d_foo_mulFoo,"MulFoo")
return a
}

func MulInt(a int, b int) int { //@mark(d_mulInt,"MulInt")
return a * b
}

func MulFloat(a float64, b float64) float64 { //@mark(d_mulFloat,"MulFloat")
return a * b
}
2 changes: 2 additions & 0 deletions gopls/internal/goxls/testdata/overload/gop_autogen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions gopls/internal/goxls/testdata/overload/overload.gop
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import (
"golang.org/lsptests/overload/a"
"golang.org/lsptests/overload/b"
"golang.org/lsptests/overload/c"
"golang.org/lsptests/overload/d"
)

Demo //@godef("Demo",Demo__0)
Expand Down Expand Up @@ -30,3 +32,23 @@ b.demo "hello" //@godef("demo",b_demo__3)
var n2 b.N
n2.add 100 //@godef("add",b_add__0)
n2.add "hello" //@godef("add",b_add__1)

c.mul 100, 200 //@godef("mul",c_mulInt)
c.mul 100.1, 200 //@godef("mul",c_mulFloat)

c.add 100, 200
c.add "hello", "world"

var foo c.Foo
foo.mul 100 //@godef("mul",c_foo_mulInt)
foo.mul new(c.Foo) //@godef("mul",c_foo_mulFoo)

d.mul 100, 200 //@godef("mul",d_mulInt)
d.mul 100.1, 200 //@godef("mul",d_mulFloat)

d.add 100, 200 //@godef("add",d_add__0)
d.add "hello", "world" //@godef("add",d_add__1)

var foo2 d.Foo
foo2.mul 100 //@godef("mul",d_foo_mulInt)
foo2.mul new(d.Foo) //@godef("mul",d_foo_mulFoo)
96 changes: 96 additions & 0 deletions gopls/internal/goxls/testdata/overload/overload.gop.golden
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,102 @@ func b.GopDemo()
```

[`b.GopDemo` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/b#GopDemo)
-- c_add-hoverdef --
```go
func c.Add__1(a string, b string) string
```

[`c.Add__1` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#Add__1)
-- c_add__0-hoverdef --
```go
func c.Add__0(a int, b int) int
```

[`c.Add__0` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#Add__0)
-- c_foo_mulFoo-hoverdef --
```go
func (*c.Foo).MulFoo(b *c.Foo) *c.Foo
```

[`(c.Foo).MulFoo` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#Foo.MulFoo)
-- c_foo_mulInt-hoverdef --
```go
func (*c.Foo).MulInt(b int) *c.Foo
```

[`(c.Foo).MulInt` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#Foo.MulInt)
-- c_foo_mul__0-hoverdef --
```go
func (*c.Foo).MulInt(b int) *c.Foo
```

[`(c.Foo).MulInt` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#Foo.MulInt)
-- c_foo_mul__1-hoverdef --
```go
func (*c.Foo).MulFoo(b *c.Foo) *c.Foo
```

[`(c.Foo).MulFoo` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#Foo.MulFoo)
-- c_mulFloat-hoverdef --
```go
func c.MulFloat(a float64, b float64) float64
```

[`c.MulFloat` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#MulFloat)
-- c_mulInt-hoverdef --
```go
func c.MulInt(a int, b int) int
```

[`c.MulInt` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#MulInt)
-- c_mul__0-hoverdef --
```go
func c.MulInt(a int, b int) int
```

[`c.MulInt` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#MulInt)
-- c_mul__1-hoverdef --
```go
func c.MulFloat(a float64, b float64) float64
```

[`c.MulFloat` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/c#MulFloat)
-- d_add__0-hoverdef --
```go
func d.Add__0(a int, b int) int
```

[`d.Add__0` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/d#Add__0)
-- d_add__1-hoverdef --
```go
func d.Add__1(a string, b string) string
```

[`d.Add__1` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/d#Add__1)
-- d_foo_mulFoo-hoverdef --
```go
func (*d.Foo).MulFoo(b *d.Foo) *d.Foo
```

[`(d.Foo).MulFoo` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/d#Foo.MulFoo)
-- d_foo_mulInt-hoverdef --
```go
func (*d.Foo).MulInt(b int) *d.Foo
```

[`(d.Foo).MulInt` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/d#Foo.MulInt)
-- d_mulFloat-hoverdef --
```go
func d.MulFloat(a float64, b float64) float64
```

[`d.MulFloat` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/d#MulFloat)
-- d_mulInt-hoverdef --
```go
func d.MulInt(a int, b int) int
```

[`d.MulInt` on pkg.go.dev](https://pkg.go.dev/golang.org/lsptests/overload/d#MulInt)
-- pkg_add__0-hoverdef --
```go
func (*pkg.N).Add__0(a int)
Expand Down
24 changes: 24 additions & 0 deletions gopls/internal/goxls/testdata/overload/overload_unimport.gop.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
func _() {
c.add //@unimported("add", c_add_unimported)
c.mul //@unimported("mul", c_mul_unimported)
c.mulInt //@unimported("mulInt", c_mulInt_unimported)
c.MulInt //@unimported("MulInt", c_MulInt_unimported)
}

func _() {
d.add //@unimported("add", d_add_unimported)
d.mul //@unimported("mul", d_mul_unimported)
d.mulInt //@unimported("mulInt", d_mulInt_unimported)
d.MulInt //@unimported("MulInt", d_MulInt_unimported)
}


/* c.add */ //@item(c_add_unimported, "add", "Go+ overload func\n\nfunc (from \"golang.org/lsptests/overload/c\")", "func")
/* c.mul */ //@item(c_mul_unimported, "mul", "Go+ overload func\n\nfunc (from \"golang.org/lsptests/overload/c\")", "func")
/* c.mulInt */ //@item(c_mulInt_unimported, "mulInt", "Go+ alias func\n\nfunc (from \"golang.org/lsptests/overload/c\")", "func")
/* c.MulInt */ //@item(c_MulInt_unimported, "MulInt", "func (from \"golang.org/lsptests/overload/c\")", "func")

/* d.add */ //@item(d_add_unimported, "add", "Go+ overload func\n\nfunc (from \"golang.org/lsptests/overload/d\")", "func")
/* d.mul */ //@item(d_mul_unimported, "mul", "Go+ overload func\n\nfunc (from \"golang.org/lsptests/overload/d\")", "func")
/* d.mulInt */ //@item(d_mulInt_unimported, "mulInt", "Go+ alias func\n\nfunc (from \"golang.org/lsptests/overload/d\")", "func")
/* d.MulInt */ //@item(d_MulInt_unimported, "MulInt", "func (from \"golang.org/lsptests/overload/d\")", "func")
4 changes: 2 additions & 2 deletions gopls/internal/goxls/testdata/summary.txt.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CallHierarchyCount = 0
CodeLensCount = 4
CompletionsCount = 36
CompletionSnippetCount = 12
UnimportedCompletionsCount = 0
UnimportedCompletionsCount = 8
DeepCompletionsCount = 0
FuzzyCompletionsCount = 1
RankedCompletionsCount = 15
Expand All @@ -13,7 +13,7 @@ FoldingRangesCount = 0
SemanticTokenCount = 0
SuggestedFixCount = 0
MethodExtractionCount = 0
DefinitionsCount = 23
DefinitionsCount = 33
TypeDefinitionsCount = 2
HighlightsCount = 0
InlayHintsCount = 0
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/goxls/testdata/summary_go1.18.txt.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CallHierarchyCount = 0
CodeLensCount = 4
CompletionsCount = 36
CompletionSnippetCount = 12
UnimportedCompletionsCount = 0
UnimportedCompletionsCount = 8
DeepCompletionsCount = 0
FuzzyCompletionsCount = 1
RankedCompletionsCount = 15
Expand All @@ -13,7 +13,7 @@ FoldingRangesCount = 0
SemanticTokenCount = 0
SuggestedFixCount = 0
MethodExtractionCount = 0
DefinitionsCount = 23
DefinitionsCount = 33
TypeDefinitionsCount = 2
HighlightsCount = 0
InlayHintsCount = 0
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/goxls/testdata/summary_go1.21.txt.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CallHierarchyCount = 0
CodeLensCount = 4
CompletionsCount = 36
CompletionSnippetCount = 12
UnimportedCompletionsCount = 0
UnimportedCompletionsCount = 8
DeepCompletionsCount = 0
FuzzyCompletionsCount = 1
RankedCompletionsCount = 15
Expand All @@ -13,7 +13,7 @@ FoldingRangesCount = 0
SemanticTokenCount = 0
SuggestedFixCount = 0
MethodExtractionCount = 0
DefinitionsCount = 23
DefinitionsCount = 33
TypeDefinitionsCount = 2
HighlightsCount = 0
InlayHintsCount = 0
Expand Down
3 changes: 0 additions & 3 deletions gopls/internal/goxls/testdata/unimported/export_test.gop

This file was deleted.

23 changes: 0 additions & 23 deletions gopls/internal/goxls/testdata/unimported/unimported.gop.in

This file was deleted.

16 changes: 0 additions & 16 deletions gopls/internal/goxls/testdata/unimported/unimported_cand_type.gop

This file was deleted.

9 changes: 0 additions & 9 deletions gopls/internal/goxls/testdata/unimported/x_test.gop

This file was deleted.

2 changes: 1 addition & 1 deletion gopls/internal/lsp/source/completion/completion_gox.go
Original file line number Diff line number Diff line change
Expand Up @@ -2471,7 +2471,7 @@ func gopForEachPackageMember(content []byte, f func(tok token.Token, id *ast.Ide
break FindType
}
}
f(token.FUNC, decl.Name, typ, false)
f(token.FUNC, decl.Name, typ, true)
}
}
}
Expand Down

0 comments on commit 9cda23a

Please sign in to comment.