lean4-htt/src/Lean/Server
2020-10-26 09:08:07 -07:00
..
lean4-lsp.el chore: go back to previous bootstrapping scheme where the stage N+1 stdlib is created using the stage N compiler 2020-09-24 18:57:53 +02:00
README.md feat: document Emacs setup 2020-08-31 06:50:01 -07:00
ServerBin.lean chore: remove #lang lean4 header 2020-10-25 09:54:07 -07:00
Snapshots.lean chore: remove old frontend leftovers 2020-10-26 09:08:07 -07:00

Building

(Assuming lean4 is the elan toolchain for stage 0.5)

leanmake +lean4 bin PKG=ServerBin LINK_OPTS=-rdynamic

Server code style

Comments should exist to denote specifics of our implementation but, for the most part, we shouldn't copy comments over from the LSP specification to avoid unnecessary duplication.

Connecting clients

Emacs with lsp-mode

You need to have both lsp-mode and lean4-mode installed. Then in the file lean4-lsp.el, replace $LEAN4_HOME with /path/to/lean4. Then running eval-buffer on the file should make lean4-lsp-mode available.

VSCode with lsp-sample

An easy way to get an LSP client is to build the sample extension and replace the server options in extension.ts:

  let serverOptions: ServerOptions = {
    command: "/path/to/build/bin/ServerBin",
    args: [],
    options: null
  };

or if logging LSP requests using Netcat (below):

  let serverOptions: ServerOptions = {
    command: "/usr/bin/nc",
    args: ["localhost", "12345"],
    options: null
  };

Logging LSP requests

In bash with Netcat:

mkfifo pipe
# So that the server can find and import packages
export LEAN_PATH=$LEAN4_HOME/build/$RELEASE_OR_DEBUG/stage0.5/lib/lean/
nc -l -p 12345 < pipe | tee client.log | ./build/bin/ServerBin 2> stderr | tee pipe server.log

will create three files to follow with tail -f -- client.log for client messages, server.log for server messages and stderr for server IO.stderr debugging.

In VSCode

Set $extension.trace.server to verbose as described in the Usage section of LSP Inspector.

Known issues affecting development

(Very incomplete) notes on Lean 3

How the Lean 3 server provides info for mouse hovers, tactic states, widgets states and autocompletion:

  • When compiling a file, the module manager stores snapshots of the environment and options after each command.
  • The elaborator and certain tactics also register bits of information such as the elaborated types of expressions in an info_manager.
  • When info is requested by the client, server::info at src/shell/server.cpp:613 is called. It finds the closest snapshot to the position at which info is requested and passes that to report_info at src/frontends/lean/interactive.cpp:141. report_info queries the info_manager as well as the environment at that point for relevant information.