跳转到内容

Go

此内容尚不支持你的语言。

Open a folder with a go.mod and Ferris IDEA starts gopls for code insight, offers go test as a run configuration with a result tree, and debugs programs and tests with Delve. Go support is Works.

  • Go, with go on the PATH.

  • gopls:

    Terminal window
    go install golang.org/x/tools/gopls@latest

    The install command Ferris IDEA names in language_servers, version 1.6.0.

  • Delve for debugging. Ferris IDEA looks for dlv in FERRIS_IDEA_DLV, on the PATH, in $GOBIN, $GOPATH/bin and ~/go/bin:

    Terminal window
    go install github.com/go-delve/delve/cmd/dlv@latest
  • Developer Mode on macOS for debugging: sudo DevToolsSecurity -enable.

Completion, navigation, find usages, rename, hierarchies, diagnostics and quick fixes come from gopls, with parameter-name hints turned on. Reformat Code (⌥⌘L) asks gopls, which formats the way gofmt does.

  1. Open the project. The run list shows go test (go test -json ./...) under “Detected from build files”.

  2. In *_test.go files the gutter shows ▶ on every TestXxx function.

  3. Run › Run Current File (⌃⇧R):

    Caret in Command
    a file of package main go run <file>
    a test function go test -json -run '^TestName$' <package>
    elsewhere in a _test.go file go test -json <package>
  4. The JSON output of go test fills the result tree; see Run tests.

  1. Set a breakpoint on a line with a statement (⌘F8).
  2. Run › Debug Current File (⌃⇧D) on a package main file, or with the caret in a test. Delve builds and starts the program.
  3. Step and evaluate as in Debug a program. An exception breakpoint for Go with “uncaught” stops on a panic that nothing recovers, with its message. Delve cannot stop on every panic, so “caught” only gets a note in the debug console and the session goes on.

To debug a running Go program, use Attach to Process with its process id, or a headless Delve server on the loopback interface.

  • “Cannot debug Go: Delve is not installed …”: run the go install command above, or set FERRIS_IDEA_DLV to the dlv program.
  • A breakpoint stays hollow with “could not find statement at …”: the line has no statement, for example a closing brace; move it to a line with code.
  • “Cannot debug: this Mac needs Developer Mode”: run sudo DevToolsSecurity -enable once.
Keyboard of
ActionShortcut
Code › Reformat Code⌥⌘LCtrlAltL
Run › Debug Current File⌃⇧Dno shortcut
Run › Run Current File⌃⇧RCtrlShiftF10
Run › Toggle Line Breakpoint⌘F8CtrlF8

debug_start takes go_test to debug one test.

  • debug_attachchangesdry run by defaultdebugAttach a debugger to a running program: native (lldb-dap), python (debugpy), node (js-debug), java (JDWP) or go (Delve), by pid or debug port.
  • debug_startchangesdry run by defaultdebugtrusted-projectStart a debug session: native programs with lldb-dap, Go with Delve (go_test for tests), Python with debugpy, Node.js/TypeScript scripts or an npm_script with js-debug, or a Kotlin main_class.
  • format_filechangesdry run by defaultwritetrusted-projectFormat a workspace file (or a range) as Reformat Code does.
  • run_commandchangesdry run by defaultruntrusted-projectRun one program with arguments in the workspace (no shell).
  • run_markersreadsdry run by defaultThe run markers (gutter ▶) of a file with 1-based line and the run configuration each starts: Java/Kotlin main and JUnit tests (single method via Maven or Gradle), Vitest/Jest describe/it/test, pytest, Go and Rust tests, and the main of Go programs, Rust binaries and examples, and Python scripts (kind main).