godef

command module
v0.0.0-...-2a32863 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2024 License: BSD-3-Clause Imports: 34 Imported by: 0

README

godef

godef is a tool for finding the definition of a symbol in Go source code. It can read input from a file, stdin, or the current acme window and provide information about the symbol's definition, type, and other relevant details. It supports various output formats and debugging features.

Installation

To install godef, you need to have Go installed. Then, use the following command:

go install github.com/jjuliano/godef@latest

Usage

godef [flags] [expr]
Flags
  • -i: Read file from stdin.
  • -o int: File offset of identifier in stdin.
  • -debug: Enable debug mode.
  • -t: Print type information.
  • -a: Print public type and member information.
  • -A: Print all type and member information.
  • -f string: Go source filename.
  • -acme: Use current acme window.
  • -json: Output location in JSON format (ignores -t flag).
  • -cpuprofile string: Write CPU profile to this file.
  • -memprofile string: Write memory profile to this file.
  • -trace string: Write trace log to this file.
Examples
Find the definition of a symbol in a file
godef -f example.go -o 123
Read from stdin
cat example.go | godef -i -o 123
Use in an acme window
godef -acme
Output in JSON format
godef -f example.go -o 123 -json
Debugging

To enable debugging, use the -debug flag. This will print additional debug information to help diagnose issues.

Profiling

To profile the CPU or memory usage of godef, use the -cpuprofile and -memprofile flags respectively. These will write profile data to the specified files.

godef -f example.go -o 123 -cpuprofile cpu.prof
godef -f example.go -o 123 -memprofile mem.prof
Tracing

To enable tracing, use the -trace flag. This will write trace data to the specified file.

godef -f example.go -o 123 -trace trace.out

To view the trace, use the following command:

go tool trace view trace.out

License

This project is licensed under the BSD-3-Clause license. See the LICENSE file for details.

Documentation

Overview

Godef prints the source location of definitions in Go programs.

Usage:

godef [-t] [-a] [-A] [-o offset] [-i] [-f file] [-acme] [expr]

Options:

-f file
	Specifies the source file in which to evaluate expr.
-o offset
	If expr is not given, specifies a location within file, which should be within or adjacent to an identifier or field selector.
-t
	Prints the type of the expression.
-a
	Prints all the public members (fields and methods) of the expression, along with their locations.
-A
	Prints private members as well as public members.
-i
	Reads the source from standard input; file must still be specified to locate other files in the same source package.
-acme
	Reads the offset, file name, and contents from the current acme window.

Expr must be an identifier or a Go expression terminated with a field selector.

Example:

$ cd $GOROOT
$ godef -f src/pkg/xml/read.go 'NewParser().Skip'
src/pkg/xml/read.go:384:18
$

Directories

Path Synopsis
go
ast
Package ast declares the types used to represent syntax trees for Go packages.
Package ast declares the types used to represent syntax trees for Go packages.
parser
A parser for Go source files.
A parser for Go source files.
printer
Package printer implements printing of AST nodes.
Package printer implements printing of AST nodes.
scanner
Package scanner implements a scanner for Go source text.
Package scanner implements a scanner for Go source text.
sym
The sym package provides a way to iterate over and change the symbols in Go source files.
The sym package provides a way to iterate over and change the symbols in Go source files.
token
This package defines constants representing the lexical tokens of the Go programming language and basic operations on tokens (printing, predicates).
This package defines constants representing the lexical tokens of the Go programming language and basic operations on tokens (printing, predicates).
types
Types infers source locations and types from Go expressions.
Types infers source locations and types from Go expressions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL