relay/completion

Argument completion for prompts and resource templates (completion/complete).

completion(handler) binds one handler for the server; it receives the context and a Request naming the prompt or template, the argument being completed, its partial value and the values of the other arguments. A handler’s error is hidden from the client, which sees the JSON-RPC internal error. Attach it with relay/server.with_completion; a client asks with relay/client.complete.

import gleam/list
import gleam/string
import relay/completion

pub fn languages() -> completion.Completion(Nil) {
  completion.completion(fn(_context, request: completion.Request) {
    ["gleam", "erlang", "elixir"]
    |> list.filter(string.starts_with(_, request.value))
    |> completion.values
    |> Ok
  })
}

Types

A completion handler.

pub type Completion(context) =
  @internal Completion(context)

What is being completed: a prompt’s argument or a resource template’s variable.

pub type Reference {
  PromptReference(name: String)
  ResourceReference(uri_template: String)
}

Constructors

  • PromptReference(name: String)
  • ResourceReference(uri_template: String)

One completion/complete request. context holds the values of the other arguments the client already knows. Read fields by label.

pub type Request {
  Request(
    reference: Reference,
    argument: String,
    value: String,
    context: dict.Dict(String, String),
  )
}

Constructors

  • Request(
      reference: Reference,
      argument: String,
      value: String,
      context: dict.Dict(String, String),
    )

Completion values. The wire carries at most 100; total and has_more tell the client about the rest.

pub type Values {
  Values(
    values: List(String),
    total: option.Option(Int),
    has_more: option.Option(Bool),
  )
}

Constructors

Values

pub fn completion(
  complete: fn(context, Request) -> Result(Values, error),
) -> Completion(context)

A completion handler. An Error reaches the client as the JSON-RPC internal error.

pub fn values(values: List(String)) -> Values

The first 100 values, with no total.

✨ Search Document