blob: 77fd55181748377090ff2a7bbec2c3d61dd878ef [file]
This test checks behavior of completion within comments.
-- flags --
-ignore_extra_diags
-- go.mod --
module golang.org/lsptests/comment
go 1.18
-- p.go --
package comment_completion
var p bool
//@complete(re"//()")
func _() {
var a int
switch a {
case 1:
//@complete(re"//()")
_ = a
}
var b chan int
select {
case <-b:
//@complete(re"//()")
_ = b
}
var (
//@complete(re"//()")
_ = a
)
}
// //@complete(re"() ", variableC)
var C string //@item(variableC, "C", "string", "var") //@complete(re"() ", variableC)
// //@complete(re"() ", constant)
const Constant = "example" //@item(constant, "Constant", "string", "const") //@complete(re"() ", constant)
// //@complete(re"() ", structType, fieldB, fieldA)
type StructType struct { //@item(structType, "StructType", "struct{...}", "struct") //@complete(re"() ", structType, fieldA, fieldB)
// //@complete(re"() ", fieldA, structType, fieldB)
A string //@item(fieldA, "A", "string", "field") //@complete(re"() ", fieldA, structType, fieldB)
b int //@item(fieldB, "b", "int", "field") //@complete(re"() ", fieldB, structType, fieldA)
}
// //@complete(re"() ", method, structRecv, paramX, resultY, fieldB, fieldA)
func (structType *StructType) Method(X int) (Y int) { //@item(structRecv, "structType", "*StructType", "var"),item(method, "Method", "func(X int) (Y int)", "method"),item(paramX, "X", "int", "var"),item(resultY, "Y", "int", "var")
// //@complete(re"() ", method, structRecv, paramX, resultY, fieldB, fieldA)
return
}
// //@complete(re"() ", newType)
type NewType string //@item(newType, "NewType", "string", "type") //@complete(re"() ", newType)
// //@complete(re"() ", testInterface, testA, testB)
type TestInterface interface { //@item(testInterface, "TestInterface", "interface{...}", "interface")
// //@complete(re"() ", testA, testInterface, testB)
TestA(L string) (M int) //@item(testA, "TestA", "func(L string) (M int)", "method"),item(paramL, "L", "var", "string"),item(resM, "M", "var", "int") //@complete(re"() ", testA, testInterface, testB)
TestB(N int) bool //@item(testB, "TestB", "func(N int) bool", "method"),item(paramN, "N", "var", "int") //@complete(re"() ", testB, testInterface, testA)
}
// //@complete(re"() ", function)
func Function() int { //@item(function, "Function", "func() int", "func") //@complete(re"() ", function)
// //@complete(re"() ", function)
return 0
}
// This tests that completing right after "//" (no space) above a declaration
// suggests the identifier name, prepending a space for proper doc comment style.
//@complete(re"//()", plainFunc)
// This tests completing with a partial prefix after "//" (no space) also
// prepends a space, covering the case where the user has typed "//Plain".
//Plain//@complete(re"//Plain()", plainFunc)
func PlainFunc() {} //@item(plainFunc, "PlainFunc", "func()", "func")
// This tests multiline block comments and completion with prefix
// Lorem Ipsum Multili//@complete(re"()Multi", multiline)
// Lorem ipsum dolor sit ametom
func Multiline() int { //@item(multiline, "Multiline", "func() int", "func")
// //@complete(re"() ", multiline)
return 0
}
// This test checks that gopls does not panic if the receiver is syntactically
// present but empty.
//
// //@complete(re"() ")
func () _() {}
// This test checks that gopls does not panic if there is a duplicate declaration.
func f() {}
// //@complete(re"() ")
func () f() {}