···1717 else
1818 attempt
19192020-let next_uri
2121- ~(prefix : string option)
2222- ~(mode : [< `Random | `Sequential])
2323- ~(forest : State.t)
2424- : string * string option
2525- =
2020+let next_uri ~(prefix : string option) ~(mode : [< `Random | `Sequential]) ~(forest : State.t) : string =
2621 let addrs =
2722 forest.index
2823 |> URI.Tbl.to_seq
2929- |> Seq.filter_map
3030- (fun (uri, tree) ->
3131- let@ path = Option.map @~ Tree.get_source_path ~base: forest.config.url tree in
3232- uri, path
3333- )
2424+ |> Seq.map fst
3425 |> List.of_seq
3526 in
3636- let default_dir = Option.map Unix.realpath @@ List.nth_opt forest.config.trees 0 in
3727 let keys =
3838- let@ (uri, path) = List.filter_map @~ addrs in
2828+ let@ uri = List.filter_map @~ addrs in
3929 let@ prefix', key = Option.bind @@ URI_scheme.split_addr uri in
4040- if prefix = prefix' then
4141- Some (key, Filename.dirname path)
4242- else None
3030+ if prefix = prefix' then Some key else None
4331 in
4444- let last_sequential, dir =
3232+ let last_sequential =
4533 List.fold_left
4646- (fun (acc_i, acc_dir) (i, dir) ->
4747- if i > acc_i then (i, Some dir) else (acc_i, acc_dir)
3434+ (fun acc_i i ->
3535+ if i > acc_i then i else acc_i
4836 )
4949- (0, default_dir)
3737+ 0
5038 keys
5139 in
5240 let next =
5341 match mode with
5442 | `Sequential -> last_sequential + 1
5555- | `Random -> random_not_in @@ List.map fst keys
4343+ | `Random -> random_not_in keys
5644 in
5757- (match prefix with (None | Some "") -> "" | Some prefix -> prefix ^ "-") ^ BaseN.Base36.string_of_int next, dir
4545+ (match prefix with (None | Some "") -> "" | Some prefix -> prefix ^ "-") ^ BaseN.Base36.string_of_int next
58465947let start_of_file =
6048 let beginning = L.Position.create ~character: 0 ~line: 0 in
+5-5
lib/frontend/Forester.ml
···2222let output_dir_name = "output"
23232424let create_tree ~env ~dest_dir ~prefix ~template ~mode ~(forest : State.t) =
2525- let next, next_dir = URI_util.next_uri ~prefix ~mode ~forest in
2525+ let next = URI_util.next_uri ~prefix ~mode ~forest in
2626 let fname = next ^ ".tree" in
2727 let now = Human_datetime.now () in
2828 let template_content =
···3434 in
3535 let body = Format.asprintf "\\date{%a}\n" Human_datetime.pp now in
3636 let create = `Exclusive 0o644 in
3737- (* If no dest_dir is passed, use the directory of the previous tree *)
3737+ (* If no dest_dir is passed, use the config *)
3838 let dir =
3939 match dest_dir with
4040 | Some dir -> dir
4141 | None ->
4242- match next_dir with
4343- | Some next_dir -> next_dir
4444- | None -> Reporter.fatal Missing_argument ~extra_remarks: [Asai.Diagnostic.loctext "Unable to guess destination director for new tree; please supply one."]
4242+ match forest.config.trees with
4343+ | dir :: _ -> dir
4444+ | [] -> Reporter.fatal Missing_argument ~extra_remarks: [Asai.Diagnostic.loctext "Unable to guess destination director for new tree; please supply one."]
4545 in
4646 let path =
4747 EP.(env#fs / dir / fname)
+5-7
lib/language_server/Code_action.ml
···1313let resolve (params : L.CodeAction.t) = params
14141515let next_addrs ~(forest : State.t) prefix =
1616- let seq, dir = URI_util.next_uri ~prefix ~mode: `Sequential ~forest in
1717- Eio.traceln "Code_action: %a" Format.(pp_print_option pp_print_string) dir;
1818- dir, seq, fst @@ URI_util.next_uri ~prefix ~mode: `Random ~forest
1616+ URI_util.next_uri ~prefix ~mode: `Sequential ~forest, URI_util.next_uri ~prefix ~mode: `Random ~forest
19172018let create_tree_edit ~range ~uri addr dir =
2119 L.WorkspaceEdit.create
···3937 let Lsp_state.{forest; _} = Lsp_state.get () in
4038 let config = forest.config in
4139 let actions =
4242- let next_dir, next_sequential, next_random = next_addrs ~forest None in
4343- match next_dir with
4444- | None -> []
4545- | Some dir ->
4040+ let next_sequential, next_random = next_addrs ~forest None in
4141+ match forest.config.trees with
4242+ | [] -> []
4343+ | dir :: _ ->
4644 let sequential =
4745 L.CodeAction.create
4846 ~title: (Format.asprintf "create new tree (sequential address)")
+1-1
lib/language_server/Completion.ml
···368368 ~filterText
369369 ()
370370 | New_addr ->
371371- let next mode = fst @@ URI_util.next_uri ~prefix: None ~mode ~forest in
371371+ let next mode = URI_util.next_uri ~prefix: None ~mode ~forest in
372372 [
373373 L.CompletionItem.create ~label: "random" ~insertText: (next `Sequential) ();
374374 L.CompletionItem.create ~label: "sequential" ~insertText: (next `Random) ()