Current section
Files
Jump to
Current section
Files
src/dagger/dsl/search_result.gleam
// AUTO-GENERATED BY DAGGER_GLEAM - DO NOT EDIT
import dagger/types.{type Client, type Try} as types
import dagger/interpreter
import dagger/dsl/types as t
import gleam/dynamic/decode
import gleam/list
pub fn search_result(id id: t.SearchResult) -> t.SearchResult {
let field = types.Field(name: "loadSearchResultFromID", args: [#("id", types.GDeferred(id.op))], subfields: [])
t.SearchResult(op: types.Pure([field]))
}
/// The byte offset of this line within the file.
pub fn absolute_offset(parent: t.SearchResult, client client: Client, then handler: fn(Try(Int)) -> a) -> a {
let field = types.Field(name: "absoluteOffset", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.int)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("absoluteOffset")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The path to the file that matched.
pub fn file_path(parent: t.SearchResult, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "filePath", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("filePath")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// A unique identifier for this SearchResult.
pub fn id(parent: t.SearchResult) -> t.SearchResult {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.SearchResult(op: new_op)
}
/// The first line that matched.
pub fn line_number(parent: t.SearchResult, client client: Client, then handler: fn(Try(Int)) -> a) -> a {
let field = types.Field(name: "lineNumber", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.int)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("lineNumber")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// The line content that matched.
pub fn matched_lines(parent: t.SearchResult, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "matchedLines", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("matchedLines")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Sub-match positions and content within the matched lines.
pub fn submatches(parent: t.SearchResult, select select: fn(t.SearchSubmatch) -> List(types.Field), client client: Client, then handler: fn(Try(List(t.SearchSubmatch))) -> a) -> a {
let subfields = select(t.SearchSubmatch(op: types.Pure([])))
let field = types.Field(name: "submatches", args: [], subfields: subfields)
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.list(decode.dynamic))) {
Ok(items) -> types.Pure(Ok(list.map(items, fn(_) { t.SearchSubmatch(op: types.Pure(full_query)) })))
Error(_) -> types.Pure(Error(types.DecodingError("submatches")))
}
}
)
}
handler(interpreter.run(op, client))
}