Skip to content
Adam
Tools

The language server

adam lsp: Adam's own checks in any editor that speaks LSP.

The server

adam lsp serves the Language Server Protocol on stdin / stdout, so any editor that speaks LSP gets Adam's checks; it serves until the client says exit. The Adam editor is one such client (The Adam editor).

Checks as you type

The server checks a document with the compiler's own front end, the open buffers standing in for their files, and each import with a current .acu read from it (Compiled units), so a check never parses every source again. A run of edits is one check: a changed document is checked once no message is waiting, and its errors, warnings and hints are published at their words (Diagnostics). The server watches the files its checks read (the modules, the paths their directives name, project.toml) and checks an open document again when one of them changes on disk. The client's target (initializationOptions.target, or settings.target later) stands in where the main module names no @target, as -t does for a build (Targets).

Hover and doc comments

A hover shows the declaration's heading and its /// doc comment as Markdown; on a keyword, a builtin type, a directive or an intrinsic it shows what the language defines it to be. A doc comment's @param, @returns, @raises, @see, @deprecated, @since and @example lines become their own parts of the hover; an @example is shown as Adam code.

lsp_doc_comment.adam
module exe lsp_doc_comment;

/// Clamps a value into a range.
///
/// @param AValue the value to clamp
/// @param ALow the smallest value returned
/// @param AHigh the largest value returned
/// @returns AValue, or the nearer bound when it lies outside the range
/// @example
///   Clamp(15, 0, 10)
func Clamp(const AValue: int64; const ALow: int64; const AHigh: int64): int64;
begin
  if AValue < ALow then
    return ALow;
  end;
  if AValue > AHigh then
    return AHigh;
  end;
  return AValue;
end;

begin
  println("{}", Clamp(15, 0, 10));
end.

Go to definition jumps to the declaration a name means, in an open buffer, a source file or a unit read from its .acu. The outline lists a module's imports, declarations, sections and tests with each type's members; workspace symbols search every module of the open documents' checks, and the public names of the std and runtime units they import. The call hierarchy shows who calls a routine and what it calls, over every module of the open documents' checks.

Writing code

Completion lists the names in scope at the cursor, innermost first, then the imports, the runtime, the type words, the keywords and statement snippets; after . or -> it lists what the left side has (fields, properties, methods, choice values, a unit's public names). Inlay hints put each parameter's name before the argument it binds, from the signature the check bound the call to; an argument that is already the parameter's own name gets none.

Formatting

Formatting lays a buffer out from its checked tree: one declaration or statement per line, the block levels, the spacing around operators, long lines broken. It changes only the gaps between tokens and never a comment, and it refuses a buffer with a syntax error.

↑ ↓ moveEnter openEsc close