-module(asset). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -define(FILEPATH, "src/asset.gleam"). -export([update_text/2, main/0]). -export_type([error/0, edit/0, assertion_position/0, option_constructor/0, module_info/0, option_import/0, assertion_function/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -type error() :: {parsing_failed, glance:error()} | no_import_found. -type edit() :: {edit, integer(), integer(), binary()}. -type assertion_position() :: statement | expression | inside_assertion. -type option_constructor() :: some_constructor | none_constructor. -type module_info() :: {module_info, binary(), glance:span(), gleam@option:option(option_import()), binary()}. -type option_import() :: {option_import, binary(), gleam@option:option(binary()), gleam@option:option(binary())}. -type assertion_function() :: be_error | be_false | be_none | be_ok | be_some | be_true | equal | fail | not_equal. -file("src/asset.gleam", 263). -spec pipe_args(glance:expression(), list(glance:field(glance:expression()))) -> list(glance:field(glance:expression())). pipe_args(Left, Args) -> [{unlabelled_field, Left} | Args]. -file("src/asset.gleam", 270). -spec called_function(glance:expression()) -> {ok, {gleam@option:option(binary()), binary()}} | {error, nil}. called_function(Function) -> case Function of {field_access, _, {variable, _, Module}, Name} -> {ok, {{some, Module}, Name}}; {variable, _, Name@1} -> {ok, {none, Name@1}}; _ -> {error, nil} end. -file("src/asset.gleam", 478). -spec replace_or_return(binary(), glance:span(), assertion_position()) -> {binary(), list(edit())}. replace_or_return(Text, Location, Position) -> case Position of expression -> {<<""/utf8>>, [{edit, erlang:element(2, Location), erlang:element(3, Location), Text}]}; statement -> {<<""/utf8>>, [{edit, erlang:element(2, Location), erlang:element(3, Location), Text}]}; inside_assertion -> {Text, []} end. -file("src/asset.gleam", 489). -spec wrap_assert(binary(), assertion_position()) -> binary(). wrap_assert(Assert_, Position) -> case Position of expression -> <<<<"{ "/utf8, Assert_/binary>>/binary, " }"/utf8>>; inside_assertion -> <<<<"{ "/utf8, Assert_/binary>>/binary, " }"/utf8>>; statement -> Assert_ end. -file("src/asset.gleam", 501). -spec option_constructor(option_constructor(), module_info()) -> {binary(), list(edit())}. option_constructor(Constructor, Info) -> {Import_@1, Edits} = case erlang:element(4, Info) of none -> Import_ = {option_import, <<"option"/utf8>>, none, none}, {Import_, [{edit, 0, 0, <<"import gleam/option\n"/utf8>>}]}; {some, I} -> {I, []} end, Name@2 = case Constructor of none_constructor -> case erlang:element(4, Import_@1) of none -> <<(erlang:element(2, Import_@1))/binary, ".None"/utf8>>; {some, Name} -> Name end; some_constructor -> case erlang:element(3, Import_@1) of none -> <<(erlang:element(2, Import_@1))/binary, ".Some"/utf8>>; {some, Name@1} -> Name@1 end end, {Name@2, Edits}. -file("src/asset.gleam", 732). -spec count_indentation(binary(), integer()) -> integer(). count_indentation(Text, Count) -> case gleam_stdlib:string_ends_with(Text, <<" "/utf8>>) of false -> Count; true -> count_indentation(gleam@string:drop_end(Text, 1), Count + 1) end. -file("src/asset.gleam", 756). -spec slice(binary(), integer(), integer()) -> binary(). slice(String, Start, End) -> Length = case End of -1 -> erlang:byte_size(String) - Start; _ -> End - Start end, binary:part(String, Start, Length). -file("src/asset.gleam", 606). -spec do_get_src(binary(), glance:span()) -> binary(). do_get_src(Src, Location) -> slice(Src, erlang:element(2, Location), erlang:element(3, Location)). -file("src/asset.gleam", 578). -spec pipe_to_call(binary(), glance:expression(), glance:expression()) -> binary(). pipe_to_call(Src, Left, Right) -> {Function@1, Arguments@1} = case Right of {call, _, Function, Arguments} -> {Function, Arguments}; _ -> {Right, []} end, Arguments@2 = [{unlabelled_field, Left} | Arguments@1], Argument_strings = gleam@list:map( Arguments@2, fun(Argument) -> case Argument of {labelled_field, Label, Item} -> <<<