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
Automatic (Recommended)
System Installation
Glass automatically installs gopls if not found:
- Checks if
go is available in PATH
- Runs:
go install golang.org/x/tools/gopls@latest
- Stores in:
~/.local/share/zed/languages/gopls/
- Names binary:
gopls_{version}_go_{go_version}
Version detection:
- Tracks both gopls and Go compiler versions
- Reinstalls if Go version changes
- Keeps old versions during updates
Install gopls yourself:go install golang.org/x/tools/gopls@latest
Glass will detect and use the version in your $GOPATH/bin.
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:
Methods & Functions
Struct Fields
Package Imports
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) stringtype Config struct {
Host string
Port int
}
func setup() {
cfg := Config{
| // Suggests Host and Port with types
}
}
Shows: Host string, Port intAuto-completes:
- Standard library packages
- Local packages
- Vendor packages
- Module dependencies
With package documentation.
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
Package Tests
Specific Test
Subtests
Run all tests in the current package:go test ./path/to/package
Glass automatically determines the package from your file location. func TestExample(t *testing.T) { // ← Click to run
if 2+2 != 4 {
t.Error("math is broken")
}
}
Command:go test -run \^TestExample\$
Glass uses regex anchors to match exact test names.func TestFeature(t *testing.T) {
t.Run("handles errors", func(t *testing.T) { // ← Click to run
// test code
})
}
Command:go test -v -run '^TestFeature$/^handles\\_errors$'
Special characters are automatically escaped.
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\$
testCases := map[string]struct{
input string
output string
}{
"uppercase": {input: "hello", output: "HELLO"}, // ← Click
"lowercase": {input: "WORLD", output: "world"},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
// test code
})
}
Glass detects both map and slice table tests.
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:
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:
| Variable | Description | Example |
|---|
GO_PACKAGE | Current package path | ./cmd/server |
GO_MODULE_ROOT | Module root directory | /home/user/project |
GO_SUBTEST_NAME | Sanitized subtest name | handles\\_errors |
GO_TABLE_TEST_CASE_NAME | Table test case name | positive\\_case |
GO_SUITE_NAME | Testify suite name | ExampleSuite |
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
- Run package:
go run . in package directory
- Generate:
go generate for current package
- Generate all:
go generate ./... for module
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
gopls Not Starting
Import Errors
Test Not Found
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
For missing dependencies:go mod tidy
go mod download
For local packages:go mod edit -replace github.com/myorg/mymodule=../mymodule
Ensure test files:
- End with
_test.go
- Are in the same package
- Have functions starting with
Test, Benchmark, Example, or Fuzz
Check test discovery:
Next Steps