GenLSP.Test (gen_lsp v0.0.5)

Conveniences for testing GenLSP processes.

Link to this section Summary

Types

The test client data structure.

The test server data structure.

Functions

Simple helper to determine whether the LSP process is alive.

Assert on a notification that was sent from the server.

Assert on the response of a request that was sent with GenLSP.Test.request/2.

Starts a new LSP client for the given server.

Send a notification from the client to the server.

Send a request from the client to the server.

Starts a new server.

Link to this section Types

Link to this opaque

client()

(opaque)
@opaque client()

The test client data structure.

Link to this opaque

server()

(opaque)
@opaque server()

The test server data structure.

Link to this section Functions

@spec alive?(server()) :: boolean()

Simple helper to determine whether the LSP process is alive.

Link to this macro

assert_notification(method, pattern, timeout \\ 100)

(macro)

Assert on a notification that was sent from the server.

The second argument is a pattern, similar to ExUnit.Assertions.assert_receive/3.

usage

Usage

import GenLSP.Test

notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})

assert_notification("window/logMessage", %{
  "message" => "[MyLSP] LSP Initialized!",
  "type" => 4
})
Link to this macro

assert_result(id, pattern, timeout \\ 100)

(macro)

Assert on the response of a request that was sent with GenLSP.Test.request/2.

The second argument is a pattern, similar to ExUnit.Assertions.assert_receive/3.

usage

Usage

import GenLSP.Test

request(client, %{
  method: "initialize",
  id: 1,
  jsonrpc: "2.0",
  params: %{capabilities: %{}, rootUri: "file://#{root_path}"}
})

assert_result(1, %{
  "capabilities" => %{
    "textDocumentSync" => %{
      "openClose" => true,
      "save" => %{
        "includeText" => true
      },
      "change" => 1
    }
  },
  "serverInfo" => %{"name" => "Credo"}
})
@spec client(server()) :: client()

Starts a new LSP client for the given server.

The "client" is equivalent to a text editor.

usage

Usage

import GenLSP.Test

server = server(MyLSP, some_arg: some_arg)
client = client(server)
Link to this function

notify(map, body)

@spec notify(client(), Jason.Encoder.t()) :: :ok

Send a notification from the client to the server.

usage

Usage

import GenLSP.Test

notify(client, %{
  method: "initialized",
  jsonrpc: "2.0",
  params: %{}
})
Link to this function

request(map, body)

@spec request(client(), Jason.Encoder.t()) :: {:ok, any()}

Send a request from the client to the server.

The response from the server will be sent as a message to the current process and can be asserted on using GenLSP.Test.assert_result/3.

usage

Usage

import GenLSP.Test

request(client, %{
  method: "initialize",
  id: 1,
  jsonrpc: "2.0",
  params: %{capabilities: %{}, rootUri: "file://#{root_path}"}
})
Link to this function

server(mod, opts \\ [])

Starts a new server.

usage

Usage

import GenLSP.Test

server = server(MyLSP, some_arg: some_arg)