Skip to main content

bt-lsp

bt-lsp is the BT language server: the program behind error highlighting, completion, hover documentation, go-to-definition, rename and formatting for BT code. Studio, the VS Code extension and the JetBrains plugin start it for you (see Editor integrations). You run it yourself to check scripts in CI, or to connect an editor that supports the Language Server Protocol (LSP), such as Neovim, Helix, Emacs or Sublime Text.

Check scripts in CI​

bt-lsp --check scripts/main.bt

This checks the program that starts at that file, including everything it includes, prints each problem as FILE:LINE:COLUMN: MESSAGE, and exits:

StatusMeaning
0No errors (warnings may be printed).
1One or more errors.
2The file could not be read.

Run it from your project folder so it finds your game.json.

Connect another editor​

Configure your editor to start bt-lsp for .bt files, talking over standard input and output:

bt-lsp --stdlib-root /path/to/cturtle/stdlib

Use the stdlib folder that ships with the VS Code extension or JetBrains plugin, or the root folder of an engine source checkout that has been built at least once.

Options​

OptionDefaultDescription
--check FILECheck one program and exit (see above).
--stdlib-root DIRnoneFolder with the engine's BT libraries. Lets the server resolve include "cturtle/..." and find the engine's API declarations.
--manifest FILEThe nearest game.json above each open fileGame manifest that defines your include roots and source files.
--virtual-document-root DIRnoneFor editors that can only open real files: writes the engine's API declarations as files under DIR, so go-to-definition on an engine function opens a file.
--traceoffLog every request to standard error, for troubleshooting.
--helpPrint usage.

Engine and game APIs​

The server knows the BT standard library and every BT file in your project. Engine functions written in C (rendering, physics, input and so on) are known from a declarations file that ships with the editor extensions and with Studio.

If your game has its own native (C) packages, their declarations are written to .ctbuild/bt-catalog/ in your project when you press Play in Studio or build with ctgame in a compiled code mode. Until then the editor reports those functions as unknown. To write the declarations without Studio, run the game compiler that ships with ctgame:

ct-game-compile --catalog-module build/my_game_module.so --dump-catalog .ctbuild/bt-catalog

The server picks up the new declarations automatically. Deleting .ctbuild/bt-catalog/ is safe.

Errors​

ProblemWhat to do
bt-lsp: cannot analyze FILEThe --check file is missing or unreadable.
Every cturtle/... include is unresolvedPass --stdlib-root, or open the folder that contains your game.json.
Engine functions are unknownThe declarations file is missing: use the stdlib folder from an editor package or Studio, or pass --stdlib-root from a built engine checkout.
Your game's native functions are unknownWrite the game's declarations as shown above.
bt-lsp: could not materialize declaration module NAMEThe --virtual-document-root folder is not writable.