View Source GenLSP.Test (gen_lsp v0.10.0)

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.

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.

Shuts down an LSP client.

Shuts down an LSP server.

Link to this section Types

@opaque client()

The test client data structure.

@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_error(id, pattern, timeout \\ Application.get_env(:ex_unit, :assert_receive_timeout))

View Source (macro)

Assert on the error 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

id = 3

request(client, %{
  method: "textDocument/documentSymbol",
  id: id,
  jsonrpc: "2.0",
  params: %{
    textDocument: %{
      uri: "file://file/doesnt/matter.ex"
    }
  }
})

assert_error(^id, %{
  "code" => -32601,
  "message" => "Method Not Found"
})
Link to this macro

assert_notification(method, pattern, timeout \\ Application.get_env(:ex_unit, :assert_receive_timeout))

View Source (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_request(client, method, timeout \\ Application.get_env(:ex_unit, :assert_receive_timeout), callback)

View Source (macro)

Assert on a request that was sent from the server.

usage

Usage

assert_request(client, "client/registerCapability", 1000, fn params ->
  assert params == %{
           "registrations" => [
             %{
               "id" => "file-watching",
               "method" => "workspace/didChangeWatchedFiles",
               "registerOptions" => %{
                 "watchers" => [
                   %{
                     "globPattern" => "{lib|test}/**/*.{ex|exs|heex|eex|leex|surface}"
                   }
                 ]
               }
             }
           ]
         }

  nil
end)
Link to this macro

assert_result(id, pattern, timeout \\ Application.get_env(:ex_unit, :assert_receive_timeout))

View Source (macro)

Assert on the successful 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

id = 1

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

assert_result(^id, %{
  "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)
@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: %{}
})
@spec request(client(), Jason.Encoder.t()) ::
  {:ok, any()} | {:error, :closed | {:timeout, binary()} | :inet.posix()}

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}"}
})

Starts a new server.

usage

Usage

import GenLSP.Test

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

shutdown_client!(client)

View Source
@spec shutdown_client!(client :: client()) :: :ok

Shuts down an LSP client.

Link to this function

shutdown_server!(server)

View Source
@spec shutdown_server!(server :: server()) :: :ok

Shuts down an LSP server.