Kevin Burke | 68e087e | 2017-07-18 21:03:19 -0700 | [diff] [blame] | 1 | # Go Tools |
| 2 | |
Rebecca Stambler | 3949734 | 2020-12-03 17:53:26 -0500 | [diff] [blame] | 3 | [](https://pkg.go.dev/golang.org/x/tools) |
| 4 | |
Alan Donovan | b4c4500 | 2022-05-03 12:59:16 -0400 | [diff] [blame] | 5 | This repository provides the `golang.org/x/tools` module, comprising |
| 6 | various tools and packages mostly for static analysis of Go programs, |
| 7 | some of which are listed below. |
| 8 | Use the "Go reference" link above for more information about any package. |
Kevin Burke | 68e087e | 2017-07-18 21:03:19 -0700 | [diff] [blame] | 9 | |
Alan Donovan | b4c4500 | 2022-05-03 12:59:16 -0400 | [diff] [blame] | 10 | It also contains the |
| 11 | [`golang.org/x/tools/gopls`](https://pkg.go.dev/golang.org/x/tools/gopls) |
| 12 | module, whose root package is a language-server protocol (LSP) server for Go. |
| 13 | An LSP server analyses the source code of a project and |
| 14 | responds to requests from a wide range of editors such as VSCode and |
| 15 | Vim, allowing them to support IDE-like functionality. |
Kevin Burke | 68e087e | 2017-07-18 21:03:19 -0700 | [diff] [blame] | 16 | |
Alan Donovan | b4c4500 | 2022-05-03 12:59:16 -0400 | [diff] [blame] | 17 | <!-- List only packages of general interest below. --> |
Kevin Burke | 68e087e | 2017-07-18 21:03:19 -0700 | [diff] [blame] | 18 | |
Alan Donovan | b4c4500 | 2022-05-03 12:59:16 -0400 | [diff] [blame] | 19 | Selected commands: |
Kevin Burke | 68e087e | 2017-07-18 21:03:19 -0700 | [diff] [blame] | 20 | |
Alan Donovan | b4c4500 | 2022-05-03 12:59:16 -0400 | [diff] [blame] | 21 | - `cmd/goimports` formats a Go program like `go fmt` and additionally |
| 22 | inserts import statements for any packages required by the file |
| 23 | after it is edited. |
| 24 | - `cmd/callgraph` prints the call graph of a Go program. |
| 25 | - `cmd/digraph` is a utility for manipulating directed graphs in textual notation. |
| 26 | - `cmd/stringer` generates declarations (including a `String` method) for "enum" types. |
| 27 | - `cmd/toolstash` is a utility to simplify working with multiple versions of the Go toolchain. |
Kevin Burke | 68e087e | 2017-07-18 21:03:19 -0700 | [diff] [blame] | 28 | |
Alan Donovan | b4c4500 | 2022-05-03 12:59:16 -0400 | [diff] [blame] | 29 | These commands may be fetched with a command such as |
Alan Yee | b20ae4b | 2022-10-12 02:11:58 +0000 | [diff] [blame] | 30 | ``` |
| 31 | go install golang.org/x/tools/cmd/goimports@latest |
| 32 | ``` |
Kevin Burke | 68e087e | 2017-07-18 21:03:19 -0700 | [diff] [blame] | 33 | |
Alan Donovan | b4c4500 | 2022-05-03 12:59:16 -0400 | [diff] [blame] | 34 | Selected packages: |
| 35 | |
| 36 | - `go/ssa` provides a static single-assignment form (SSA) intermediate |
| 37 | representation (IR) for Go programs, similar to a typical compiler, |
| 38 | for use by analysis tools. |
| 39 | |
| 40 | - `go/packages` provides a simple interface for loading, parsing, and |
| 41 | type checking a complete Go program from source code. |
| 42 | |
| 43 | - `go/analysis` provides a framework for modular static analysis of Go |
| 44 | programs. |
| 45 | |
| 46 | - `go/callgraph` provides call graphs of Go programs using a variety |
| 47 | of algorithms with different trade-offs. |
| 48 | |
| 49 | - `go/ast/inspector` provides an optimized means of traversing a Go |
| 50 | parse tree for use in analysis tools. |
| 51 | |
| 52 | - `go/cfg` provides a simple control-flow graph (CFG) for a Go function. |
| 53 | |
| 54 | - `go/expect` reads Go source files used as test inputs and interprets |
| 55 | special comments within them as queries or assertions for testing. |
| 56 | |
| 57 | - `go/gcexportdata` and `go/gccgoexportdata` read and write the binary |
| 58 | files containing type information used by the standard and `gccgo` compilers. |
| 59 | |
| 60 | - `go/types/objectpath` provides a stable naming scheme for named |
| 61 | entities ("objects") in the `go/types` API. |
| 62 | |
| 63 | Numerous other packages provide more esoteric functionality. |
| 64 | |
Dmitri Shuralyov | 5a89a3b | 2023-06-24 20:50:29 -0400 | [diff] [blame] | 65 | <!-- Some that didn't make the cut: |
Alan Donovan | b4c4500 | 2022-05-03 12:59:16 -0400 | [diff] [blame] | 66 | |
| 67 | golang.org/x/tools/benchmark/parse |
| 68 | golang.org/x/tools/go/ast/astutil |
| 69 | golang.org/x/tools/go/types/typeutil |
Alan Donovan | b4c4500 | 2022-05-03 12:59:16 -0400 | [diff] [blame] | 70 | golang.org/x/tools/playground |
| 71 | golang.org/x/tools/present |
| 72 | golang.org/x/tools/refactor/importgraph |
| 73 | golang.org/x/tools/refactor/rename |
| 74 | golang.org/x/tools/refactor/satisfy |
| 75 | golang.org/x/tools/txtar |
| 76 | |
| 77 | --> |
| 78 | |
| 79 | ## Contributing |
| 80 | |
| 81 | This repository uses Gerrit for code changes. |
| 82 | To learn how to submit changes, see https://golang.org/doc/contribute.html. |
| 83 | |
| 84 | The main issue tracker for the tools repository is located at |
| 85 | https://github.com/golang/go/issues. Prefix your issue with "x/tools/(your |
| 86 | subdir):" in the subject line, so it is easy to find. |
| 87 | |
| 88 | ### JavaScript and CSS Formatting |
Agniva De Sarker | 65d5228 | 2019-06-26 14:28:00 +0530 | [diff] [blame] | 89 | |
| 90 | This repository uses [prettier](https://prettier.io/) to format JS and CSS files. |
| 91 | |
| 92 | The version of `prettier` used is 1.18.2. |
| 93 | |
| 94 | It is encouraged that all JS and CSS code be run through this before submitting |
| 95 | a change. However, it is not a strict requirement enforced by CI. |