https://github.com/Workiva/go-datastructures/tree/master/bitarray中定义的's'在哪里?
Where is 's' defined in https://github.com/Workiva/go-datastructures/tree/master/bitarray?
我没有看到 s
的定义。古鲁不会告诉我。我得到的只是 "no object for identifier" 但它知道它旁边的 k
。这是链接代码的典型片段:
func getIndexAndRemainder(k uint64) (uint64, uint64) {
return k / s, k % s
}
一个字母的变量名肯定会让 grep 变得更难。我已经寻找了常见的嫌疑人:var s uint64
、s := ...
,但什么也没有。显然它需要是在某处定义的全局值。
这给我留下了两个问题:
s
来自哪里?
- 不在这里问我怎么找到它?
编辑:
对于偶然发现此问题的其他人。
Guru 使我失败了,因为我没有通过将 git 克隆放在 /some/path/src 下并将 GOPATH
设置为 [=46 来在适当的 Go 工作区下检查包的源代码=].因此,虽然我认为 GOPATH=. guru definition s
会起作用,但 GOPATH
却被忽略了。 guru 可以找到 k
因为它在文件中,但它不知道如何在其他文件中查找。
我的 grep 失败原因 const
使用简单的 =
而不是 :=
。以后grepping的时候会记住这个
定义在go-datastructures/bitarray/block.go
:
// s denotes the size of any element in the block array.
// For a block of uint64, s will be equal to 64
// For a block of uint32, s will be equal to 32
// and so on...
const s = uint64(unsafe.Sizeof(block(0)) * 8)
由于变量 s
没有在函数中定义,也没有以包名或别名作为前缀,它必须是 bitarray
的全局变量(变量或常量)包。
知道后,我检查了文件夹 go-datastructures/bitarray
中没有后缀 _test
的每个文件,并寻找 s
的顶级声明。
定义在go-datastructures/bitarray/block.go, line #33:
const s = uint64(unsafe.Sizeof(block(0)) * 8)
"Modern" IDE 具有 Go 支持的通常能够转到您的光标所在的符号/标识符的定义或您单击的内容。例如,在 Atom with the Go-plus 插件中,您可以通过在单击时按住 CTRL 键来转到定义。
这些 IDE 使用 godef open source tool to find the definition source file and line, you may also use it directly. You can find the godef documentation here: https://godoc.org/github.com/rogpeppe/godef
另一个工具,guru 也可以跟踪它的定义。 guru 和 godef 都在 Atom 中工作,并且能够跳到 block.go,到 s
的定义。但是使用 "armored" IDE 更容易,只需单击一下即可。
另请注意,使用 grep
和模式的成功是有限的,因为变量和常量声明可以分组,以下也是有效的声明:
var (
longer = 3
s = uint64(3)
)
或:
var (
s = someExpression
longer = 3
)
或:
const (
p = uint64(iota)
s
x
)
我没有看到 s
的定义。古鲁不会告诉我。我得到的只是 "no object for identifier" 但它知道它旁边的 k
。这是链接代码的典型片段:
func getIndexAndRemainder(k uint64) (uint64, uint64) {
return k / s, k % s
}
一个字母的变量名肯定会让 grep 变得更难。我已经寻找了常见的嫌疑人:var s uint64
、s := ...
,但什么也没有。显然它需要是在某处定义的全局值。
这给我留下了两个问题:
s
来自哪里?- 不在这里问我怎么找到它?
编辑: 对于偶然发现此问题的其他人。
Guru 使我失败了,因为我没有通过将 git 克隆放在 /some/path/src 下并将 GOPATH
设置为 [=46 来在适当的 Go 工作区下检查包的源代码=].因此,虽然我认为 GOPATH=. guru definition s
会起作用,但 GOPATH
却被忽略了。 guru 可以找到 k
因为它在文件中,但它不知道如何在其他文件中查找。
我的 grep 失败原因 const
使用简单的 =
而不是 :=
。以后grepping的时候会记住这个
定义在go-datastructures/bitarray/block.go
:
// s denotes the size of any element in the block array.
// For a block of uint64, s will be equal to 64
// For a block of uint32, s will be equal to 32
// and so on...
const s = uint64(unsafe.Sizeof(block(0)) * 8)
由于变量 s
没有在函数中定义,也没有以包名或别名作为前缀,它必须是 bitarray
的全局变量(变量或常量)包。
知道后,我检查了文件夹 go-datastructures/bitarray
中没有后缀 _test
的每个文件,并寻找 s
的顶级声明。
定义在go-datastructures/bitarray/block.go, line #33:
const s = uint64(unsafe.Sizeof(block(0)) * 8)
"Modern" IDE 具有 Go 支持的通常能够转到您的光标所在的符号/标识符的定义或您单击的内容。例如,在 Atom with the Go-plus 插件中,您可以通过在单击时按住 CTRL 键来转到定义。
这些 IDE 使用 godef open source tool to find the definition source file and line, you may also use it directly. You can find the godef documentation here: https://godoc.org/github.com/rogpeppe/godef
另一个工具,guru 也可以跟踪它的定义。 guru 和 godef 都在 Atom 中工作,并且能够跳到 block.go,到 s
的定义。但是使用 "armored" IDE 更容易,只需单击一下即可。
另请注意,使用 grep
和模式的成功是有限的,因为变量和常量声明可以分组,以下也是有效的声明:
var (
longer = 3
s = uint64(3)
)
或:
var (
s = someExpression
longer = 3
)
或:
const (
p = uint64(iota)
s
x
)