# Go

Import `bobzhang/codemirror-lang/modes/go` for a stateful Go highlighter on JS,
Native, and Wasm GC. Use `tokenize_spans` for styles and half-open UTF-16
offsets. Use `tokenize` when you also need each token’s text.

```mbt check
///|
test {
  let lines = @go.tokenize_spans("package main\r\n变量😀x++\n")
  assert_eq(lines[0][0], { start: 0, end: 7, style: Some("keyword"), })
  assert_eq(lines[1][0], { start: 0, end: 5, style: Some("variable"), })
  assert_eq(lines[2], [])
}
```

Reuse a state across lines to continue comments and strings. Call `indent`
before `tokenize_line` to preview indentation for the next line.

```mbt check
///|
test {
  let state = @go.State::new()
  ignore(state.tokenize_line("/* start"))
  assert_eq(state.indent("end */ x"), None)
  let tokens = state.tokenize_line("end */ x")
  assert_eq(tokens[0].text, "end */")
  assert_eq(tokens[0].style, Some("comment"))
}
```
