Skip to main content
Glass provides first-class Go support through gopls integration, offering intelligent completions, powerful refactoring tools, and extensive testing capabilities.

LSP Server: gopls

Glass uses gopls, the official Go language server.

Installation

Glass requires Go to be installed and available in PATH to install gopls automatically. If go is not found, you’ll see a notification asking you to install Go first.

Features

Intelligent Completions

Glass provides context-aware Go completions:
package main

import "strings"

func main() {
    str := "hello"
    str.| // Shows string methods
}
Completions include:
  • Method signatures with parameter types
  • Package-qualified types
  • Nested field access
Example: strings.ToUpper(s string) string

Syntax Highlighting

Glass applies semantic highlighting for Go:
import "fmt"           // Module (keyword)

type Server struct {   // Type (blue)
    port int          // Field (white)
}

const MaxSize = 100   // Constant (purple)
var counter int       // Variable (white)

func process() {      // Function (yellow)
    fmt.Println()     // Function call (yellow)
}

Inlay Hints

gopls provides inlay hints for:
func greet(name string, age int) {
    fmt.Printf("Hello %s, age %d\n", name, age)
}

greet("Alice", 30)
//    ↑name   ↑age  // Parameter name hints

result := getValue()
//      ↑ string    // Type hints

for i, v := range items {
//     ↑ Item  // Range variable type hints
}
Enabled by default in Glass’s initialization options.

Testing Support

Glass provides extensive Go testing capabilities:

Regular Tests

Run all tests in the current package:
go test ./path/to/package
Glass automatically determines the package from your file location.

Testify Suites

For projects using testify/suite:
import (
    "testing"
    "github.com/stretchr/testify/suite"
)

type ExampleSuite struct {
    suite.Suite
}

func (s *ExampleSuite) TestSomething() {  // ← Click to run
    s.Equal(1, 1)
}

func TestExampleSuite(t *testing.T) {
    suite.Run(t, new(ExampleSuite))
}
Command:
go test -v -run \^TestExampleSuite\$/\^TestSomething\$
Glass automatically detects testify suites and provides specialized tasks.

Table-Driven Tests

func TestOperation(t *testing.T) {
    testCases := []struct{
        name string
        input int
    }{
        {name: "positive", input: 5},  // ← Click to run this case
        {name: "negative", input: -5},
    }
    
    for _, tc := range testCases {
        t.Run(tc.name, func(t *testing.T) {
            // test code
        })
    }
}
Command:
go test -v -run \^TestOperation\$/\^positive\$

Benchmarks

Run benchmarks with memory profiling:
func BenchmarkOperation(b *testing.B) {  // ← Click to run
    for i := 0; i < b.N; i++ {
        operation()
    }
}
Command:
go test -benchmem -run='^$' -bench \^BenchmarkOperation\$

Fuzz Tests

Run fuzz tests (Go 1.18+):
func FuzzParse(f *testing.F) {  // ← Click to run
    f.Add("example input")
    f.Fuzz(func(t *testing.T, input string) {
        parse(input)
    })
}
Command:
go test -fuzz=Fuzz -run \^FuzzParse\$

Example Tests

Run example tests:
func Example() {  // ← Click to run
    fmt.Println("Hello, world!")
    // Output: Hello, world!
}

func ExampleGreet() {  // ← Named example
    Greet("Alice")
    // Output: Hello, Alice!
}
Command:
go test -run \^Example\$
Glass filters out TestMain functions from the test picker, as they’re infrastructure, not individual tests.

Task Variables

Glass provides these variables for Go tasks:
VariableDescriptionExample
GO_PACKAGECurrent package path./cmd/server
GO_MODULE_ROOTModule root directory/home/user/project
GO_SUBTEST_NAMESanitized subtest namehandles\\_errors
GO_TABLE_TEST_CASE_NAMETable test case namepositive\\_case
GO_SUITE_NAMETestify suite nameExampleSuite

Package Path Resolution

Glass resolves the package path relative to workspace root:
project/
├── go.mod
├── cmd/
│   └── server/
│       └── main.go  ← Editing this file
└── internal/
    └── api/
When in cmd/server/main.go:
  • GO_PACKAGE = ./cmd/server
  • GO_MODULE_ROOT = /path/to/project

Available Tasks

  • Test package: Run all tests in package
  • Test module: Run all tests in module (./...)
  • Test function: Run specific test
  • Test subtest: Run specific subtest
  • Test table case: Run specific table test case
  • Test suite method: Run testify suite test
  • Run benchmark: Run specific benchmark
  • Run fuzz test: Run specific fuzz test
  • Run example: Run example test

Configuration

Initialization Options

Glass configures gopls with:
{
  "usePlaceholders": false,
  "hints": {
    "assignVariableTypes": true,
    "compositeLiteralFields": true,
    "compositeLiteralTypes": true,
    "constantValues": true,
    "functionTypeParameters": true,
    "parameterNames": true,
    "rangeVariableTypes": true
  }
}

Custom Configuration

Override gopls settings:
{
  "lsp": {
    "gopls": {
      "initialization_options": {
        "hints": {
          "parameterNames": false  // Disable parameter hints
        },
        "analyses": {
          "unusedparams": true,
          "shadow": true
        },
        "staticcheck": true
      }
    }
  }
}

Module Detection

Glass finds your Go module by walking up the directory tree looking for go.mod:
module github.com/user/project

go 1.21

require (
    github.com/stretchr/testify v1.8.4
)
The module root is used for go generate ./... and other workspace-wide commands.

Code Actions

gopls provides numerous code actions:
  • Extract function: Extract selected code to a new function
  • Extract variable: Extract expression to a variable
  • Inline: Inline variable or function
  • Add import: Add missing imports
  • Organize imports: Sort and group imports
  • Fill struct: Complete struct literal fields
  • Implement interface: Generate interface method stubs

Diagnostic Processing

Glass processes Go diagnostics to improve readability:
// Multi-line error messages are formatted with proper paragraphs
"cannot use x (type int) as type string in assignment

You might want to convert the type first."
// Becomes properly formatted with line breaks

Troubleshooting

Ensure go is in your PATH. Glass needs the Go toolchain to:
  • Install gopls
  • Run tests
  • Generate code
  • Build binaries
Check with: go version
Verify gopls installation:
gopls version
# Or check Glass's installation:
ls ~/.local/share/zed/languages/gopls/
Reinstall if needed:
go install golang.org/x/tools/gopls@latest

Next Steps

Build docs developers (and LLMs) love