Skip to content

Commit

Permalink
Merge pull request #241 from visualfc/rank
Browse files Browse the repository at this point in the history
gopls/internal/goxls/testdata: add rank test
  • Loading branch information
xushiwei authored Mar 15, 2024
2 parents 81f15c3 + 37d3353 commit 8d8a3aa
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 9 deletions.
7 changes: 7 additions & 0 deletions gopls/internal/goxls/testdata/addimport/addimport.gop.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- addimport --
package addimport //@addimport("", "bytes")

import "bytes"

func main() {}

3 changes: 3 additions & 0 deletions gopls/internal/goxls/testdata/addimport/addimport.gop.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package addimport //@addimport("", "bytes")

func main() {}
3 changes: 3 additions & 0 deletions gopls/internal/goxls/testdata/addimport/gop_autogen.go

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

31 changes: 31 additions & 0 deletions gopls/internal/goxls/testdata/foo/foo.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package foo //@mark(PackageFoo, "foo"),item(PackageFoo, "foo", "\"golang.org/lsptests/foo\"", "package")

type StructFoo struct { //@item(StructFoo, "StructFoo", "struct{...}", "struct")
Value int //@item(Value, "Value", "int", "field")
}

// Pre-set this marker, as we don't have a "source" for it in this package.
/* Error() */ //@item(Error, "Error", "func() string", "method")

func Foo() { //@item(Foo, "Foo", "func()", "func")
var err error
err.Error() //@complete("E", Error)
}

func _() {
var sFoo StructFoo //@complete("t", StructFoo)
if x := sFoo; x.Value == 1 { //@complete("V", Value),typdef("sFoo", StructFoo)
return
}
}

func _() {
shadowed := 123
{
shadowed := "hi" //@item(shadowed, "shadowed", "string", "var")
_ = shadowed //@complete("a", shadowed)
}
_ = shadowed
}

type IntFoo int //@item(IntFoo, "IntFoo", "int", "type")
3 changes: 3 additions & 0 deletions gopls/internal/goxls/testdata/foo/gop_autogen.go

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

79 changes: 79 additions & 0 deletions gopls/internal/goxls/testdata/func_rank/func_rank.gop.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package func_rank

import "net/http"

var stringAVar = "var" //@item(stringAVar, "stringAVar", "string", "var")
func stringBFunc() string { return "str" } //@item(stringBFunc, "stringBFunc", "func() string", "func")
type stringer struct{} //@item(stringer, "stringer", "struct{...}", "struct")

func _() stringer //@complete("tr", stringer)

func _(val stringer) {} //@complete("tr", stringer)

func (stringer) _() {} //@complete("tr", stringer)

func _() {
var s struct {
AA int //@item(rankAA, "AA", "int", "field")
AB string //@item(rankAB, "AB", "string", "field")
AC int //@item(rankAC, "AC", "int", "field")
}
fnStr := func(string) {}
fnStr(s.A) //@complete(")", rankAB, rankAA, rankAC)
fnStr("" + s.A) //@complete(")", rankAB, rankAA, rankAC)

fnInt := func(int) {}
fnInt(-s.A) //@complete(")", rankAA, rankAC, rankAB)

// no expected type
fnInt(func() int { s.A }) //TODO @complete(" }", rankAA, rankAB, rankAC)
fnInt(s.A()) //@complete("()", rankAA, rankAC, rankAB)
fnInt([]int{}[s.A]) //@complete("])", rankAA, rankAC, rankAB)
fnInt([]int{}[:s.A]) //@complete("])", rankAA, rankAC, rankAB)

fnInt(s.A.(int)) //@complete(".(", rankAA, rankAC, rankAB)

fnPtr := func(*string) {}
fnPtr(&s.A) //@complete(")", rankAB, rankAA, rankAC)

var aaPtr *string //@item(rankAAPtr, "aaPtr", "*string", "var")
var abPtr *int //@item(rankABPtr, "abPtr", "*int", "var")
fnInt(*a) //@complete(")", rankABPtr, rankAAPtr)

_ = func() string {
return s.A //@complete(" //", rankAB, rankAA, rankAC)
}
}

type foo struct {
fooPrivateField int //@item(rankFooPrivField, "fooPrivateField", "int", "field")
FooPublicField int //@item(rankFooPubField, "FooPublicField", "int", "field")
}

func (foo) fooPrivateMethod() int { //@item(rankFooPrivMeth, "fooPrivateMethod", "func() int", "method")
return 0
}

func (foo) FooPublicMethod() int { //@item(rankFooPubMeth, "FooPublicMethod", "func() int", "method")
return 0
}

func _() {
HandleFunc //@item(httpHandleFunc, "HandleFunc", "func(pattern string, handler func(http.ResponseWriter, *http.Request))", "func")
HandlerFunc //@item(httpHandlerFunc, "HandlerFunc", "func(http.ResponseWriter, *http.Request)", "type")

http.HandleFunc //@rank(" //", httpHandleFunc, httpHandlerFunc)
}

func _() {
handleFunc //@item(httpHandleFunc1, "handleFunc", "Go+ alias func\n\nfunc(pattern string, handler func(http.ResponseWriter, *http.Request))", "func")
HandleFunc //@item(httpHandleFunc2, "HandleFunc", "func(pattern string, handler func(http.ResponseWriter, *http.Request))", "func")
HandlerFunc //@item(httpHandlerFunc, "HandlerFunc", "func(http.ResponseWriter, *http.Request)", "type")

http.handleFunc //@rank(" //", httpHandleFunc1, httpHandleFunc2, httpHandlerFunc)
}

func _() {
var _ int = foo{}. //@rank(" //", rankFooPrivField, rankFooPubField),rank(" //", rankFooPrivMeth, rankFooPubMeth),rank(" //", rankFooPrivField, rankFooPrivMeth)
}

5 changes: 5 additions & 0 deletions gopls/internal/goxls/testdata/func_rank/gop_autogen.go

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

18 changes: 18 additions & 0 deletions gopls/internal/goxls/testdata/overload/overload_rank.gop.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import (
"golang.org/lsptests/overload/a"
)

func _() {
demo //@item(apkgDemo1, "demo", "Go+ overload funcs\n\n- func()\n- func(n int) int\n- func(n1 int, n2 int)\n- func(s ...string)", "func")
Demo //@item(apkgDemo2, "Demo", "Go+ overload funcs\n\n- func()\n- func(n int) int\n- func(n1 int, n2 int)\n- func(s ...string)", "func")

a.demo //@rank(" //", apkgDemo1, apkgDemo2)
}

func _() {
add //@item(apkgAdd1, "add", "Go+ overload funcs\n\n- func(a int)\n- func(a ...string)", "method")
Add //@item(apkgAdd2, "Add", "Go+ overload funcs\n\n- func(a int)\n- func(a ...string)", "method")

var n N
n.add //@rank(" //", apkgAdd1, apkgAdd2)
}
6 changes: 3 additions & 3 deletions gopls/internal/goxls/testdata/summary.txt.golden
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
-- summary --
CallHierarchyCount = 0
CodeLensCount = 4
CompletionsCount = 1
CompletionsCount = 18
CompletionSnippetCount = 12
UnimportedCompletionsCount = 0
DeepCompletionsCount = 0
FuzzyCompletionsCount = 1
RankedCompletionsCount = 8
RankedCompletionsCount = 15
CaseSensitiveCompletionsCount = 0
DiagnosticsCount = 0
FoldingRangesCount = 0
SemanticTokenCount = 0
SuggestedFixCount = 0
MethodExtractionCount = 0
DefinitionsCount = 23
TypeDefinitionsCount = 0
TypeDefinitionsCount = 1
HighlightsCount = 0
InlayHintsCount = 0
RenamesCount = 0
Expand Down
6 changes: 3 additions & 3 deletions gopls/internal/goxls/testdata/summary_go1.18.txt.golden
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
-- summary --
CallHierarchyCount = 0
CodeLensCount = 4
CompletionsCount = 1
CompletionsCount = 18
CompletionSnippetCount = 12
UnimportedCompletionsCount = 0
DeepCompletionsCount = 0
FuzzyCompletionsCount = 1
RankedCompletionsCount = 8
RankedCompletionsCount = 15
CaseSensitiveCompletionsCount = 0
DiagnosticsCount = 0
FoldingRangesCount = 0
SemanticTokenCount = 0
SuggestedFixCount = 0
MethodExtractionCount = 0
DefinitionsCount = 23
TypeDefinitionsCount = 0
TypeDefinitionsCount = 1
HighlightsCount = 0
InlayHintsCount = 0
RenamesCount = 0
Expand Down
6 changes: 3 additions & 3 deletions gopls/internal/goxls/testdata/summary_go1.21.txt.golden
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
-- summary --
CallHierarchyCount = 0
CodeLensCount = 4
CompletionsCount = 1
CompletionsCount = 18
CompletionSnippetCount = 12
UnimportedCompletionsCount = 0
DeepCompletionsCount = 0
FuzzyCompletionsCount = 1
RankedCompletionsCount = 8
RankedCompletionsCount = 15
CaseSensitiveCompletionsCount = 0
DiagnosticsCount = 0
FoldingRangesCount = 0
SemanticTokenCount = 0
SuggestedFixCount = 0
MethodExtractionCount = 0
DefinitionsCount = 23
TypeDefinitionsCount = 0
TypeDefinitionsCount = 1
HighlightsCount = 0
InlayHintsCount = 0
RenamesCount = 0
Expand Down

0 comments on commit 8d8a3aa

Please sign in to comment.