| 1 |
This test is ported from the old marker tests. |
| 2 |
It tests hover and definition for cgo declarations. |
| 3 |
|
| 4 |
-- flags -- |
| 5 |
-cgo |
| 6 |
|
| 7 |
-- go.mod -- |
| 8 |
module cgo.test |
| 9 |
|
| 10 |
go 1.18 |
| 11 |
|
| 12 |
-- cgo/cgo.go -- |
| 13 |
package cgo |
| 14 |
|
| 15 |
/* |
| 16 |
#include <stdio.h> |
| 17 |
#include <stdlib.h> |
| 18 |
|
| 19 |
void myprint(char* s) { |
| 20 |
printf("%s\n", s); |
| 21 |
} |
| 22 |
*/ |
| 23 |
import "C" |
| 24 |
|
| 25 |
import ( |
| 26 |
"fmt" |
| 27 |
"unsafe" |
| 28 |
) |
| 29 |
|
| 30 |
func Example() { //@loc(cgoexample, "Example"), item(cgoexampleItem, "Example", "func()", "func") |
| 31 |
fmt.Println() |
| 32 |
cs := C.CString("Hello from stdio\n") |
| 33 |
C.myprint(cs) |
| 34 |
C.free(unsafe.Pointer(cs)) |
| 35 |
} |
| 36 |
|
| 37 |
func _() { |
| 38 |
Example() //@hover("ample", "Example", hoverExample), def("ample", cgoexample), complete(re"()ample", cgoexampleItem) |
| 39 |
} |
| 40 |
|
| 41 |
-- @hoverExample -- |
| 42 |
```go |
| 43 |
func Example() |
| 44 |
``` |
| 45 |
|
| 46 |
--- |
| 47 |
|
| 48 |
[`cgo.Example` on pkg.go.dev](https://pkg.go.dev/cgo.test/cgo#Example) |
| 49 |
-- usecgo/usecgo.go -- |
| 50 |
package cgoimport |
| 51 |
|
| 52 |
import ( |
| 53 |
"cgo.test/cgo" |
| 54 |
) |
| 55 |
|
| 56 |
func _() { |
| 57 |
cgo.Example() //@hover("ample", "Example", hoverImportedExample), def("ample", cgoexample), complete(re"()ample", cgoexampleItem) |
| 58 |
} |
| 59 |
-- @hoverImportedExample -- |
| 60 |
```go |
| 61 |
func cgo.Example() |
| 62 |
``` |
| 63 |
|
| 64 |
--- |
| 65 |
|
| 66 |
[`cgo.Example` on pkg.go.dev](https://pkg.go.dev/cgo.test/cgo#Example) |