ocaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove unpredictable directory-guessing from 'new' command

Simply use the first item in the configuration

+21 -35
+10 -22
lib/compiler/URI_util.ml
··· 17 17 else 18 18 attempt 19 19 20 - let next_uri 21 - ~(prefix : string option) 22 - ~(mode : [< `Random | `Sequential]) 23 - ~(forest : State.t) 24 - : string * string option 25 - = 20 + let next_uri ~(prefix : string option) ~(mode : [< `Random | `Sequential]) ~(forest : State.t) : string = 26 21 let addrs = 27 22 forest.index 28 23 |> URI.Tbl.to_seq 29 - |> Seq.filter_map 30 - (fun (uri, tree) -> 31 - let@ path = Option.map @~ Tree.get_source_path ~base: forest.config.url tree in 32 - uri, path 33 - ) 24 + |> Seq.map fst 34 25 |> List.of_seq 35 26 in 36 - let default_dir = Option.map Unix.realpath @@ List.nth_opt forest.config.trees 0 in 37 27 let keys = 38 - let@ (uri, path) = List.filter_map @~ addrs in 28 + let@ uri = List.filter_map @~ addrs in 39 29 let@ prefix', key = Option.bind @@ URI_scheme.split_addr uri in 40 - if prefix = prefix' then 41 - Some (key, Filename.dirname path) 42 - else None 30 + if prefix = prefix' then Some key else None 43 31 in 44 - let last_sequential, dir = 32 + let last_sequential = 45 33 List.fold_left 46 - (fun (acc_i, acc_dir) (i, dir) -> 47 - if i > acc_i then (i, Some dir) else (acc_i, acc_dir) 34 + (fun acc_i i -> 35 + if i > acc_i then i else acc_i 48 36 ) 49 - (0, default_dir) 37 + 0 50 38 keys 51 39 in 52 40 let next = 53 41 match mode with 54 42 | `Sequential -> last_sequential + 1 55 - | `Random -> random_not_in @@ List.map fst keys 43 + | `Random -> random_not_in keys 56 44 in 57 - (match prefix with (None | Some "") -> "" | Some prefix -> prefix ^ "-") ^ BaseN.Base36.string_of_int next, dir 45 + (match prefix with (None | Some "") -> "" | Some prefix -> prefix ^ "-") ^ BaseN.Base36.string_of_int next 58 46 59 47 let start_of_file = 60 48 let beginning = L.Position.create ~character: 0 ~line: 0 in
+5 -5
lib/frontend/Forester.ml
··· 22 22 let output_dir_name = "output" 23 23 24 24 let create_tree ~env ~dest_dir ~prefix ~template ~mode ~(forest : State.t) = 25 - let next, next_dir = URI_util.next_uri ~prefix ~mode ~forest in 25 + let next = URI_util.next_uri ~prefix ~mode ~forest in 26 26 let fname = next ^ ".tree" in 27 27 let now = Human_datetime.now () in 28 28 let template_content = ··· 34 34 in 35 35 let body = Format.asprintf "\\date{%a}\n" Human_datetime.pp now in 36 36 let create = `Exclusive 0o644 in 37 - (* If no dest_dir is passed, use the directory of the previous tree *) 37 + (* If no dest_dir is passed, use the config *) 38 38 let dir = 39 39 match dest_dir with 40 40 | Some dir -> dir 41 41 | None -> 42 - match next_dir with 43 - | Some next_dir -> next_dir 44 - | None -> Reporter.fatal Missing_argument ~extra_remarks: [Asai.Diagnostic.loctext "Unable to guess destination director for new tree; please supply one."] 42 + match forest.config.trees with 43 + | dir :: _ -> dir 44 + | [] -> Reporter.fatal Missing_argument ~extra_remarks: [Asai.Diagnostic.loctext "Unable to guess destination director for new tree; please supply one."] 45 45 in 46 46 let path = 47 47 EP.(env#fs / dir / fname)
+5 -7
lib/language_server/Code_action.ml
··· 13 13 let resolve (params : L.CodeAction.t) = params 14 14 15 15 let next_addrs ~(forest : State.t) prefix = 16 - let seq, dir = URI_util.next_uri ~prefix ~mode: `Sequential ~forest in 17 - Eio.traceln "Code_action: %a" Format.(pp_print_option pp_print_string) dir; 18 - dir, seq, fst @@ URI_util.next_uri ~prefix ~mode: `Random ~forest 16 + URI_util.next_uri ~prefix ~mode: `Sequential ~forest, URI_util.next_uri ~prefix ~mode: `Random ~forest 19 17 20 18 let create_tree_edit ~range ~uri addr dir = 21 19 L.WorkspaceEdit.create ··· 39 37 let Lsp_state.{forest; _} = Lsp_state.get () in 40 38 let config = forest.config in 41 39 let actions = 42 - let next_dir, next_sequential, next_random = next_addrs ~forest None in 43 - match next_dir with 44 - | None -> [] 45 - | Some dir -> 40 + let next_sequential, next_random = next_addrs ~forest None in 41 + match forest.config.trees with 42 + | [] -> [] 43 + | dir :: _ -> 46 44 let sequential = 47 45 L.CodeAction.create 48 46 ~title: (Format.asprintf "create new tree (sequential address)")
+1 -1
lib/language_server/Completion.ml
··· 368 368 ~filterText 369 369 () 370 370 | New_addr -> 371 - let next mode = fst @@ URI_util.next_uri ~prefix: None ~mode ~forest in 371 + let next mode = URI_util.next_uri ~prefix: None ~mode ~forest in 372 372 [ 373 373 L.CompletionItem.create ~label: "random" ~insertText: (next `Sequential) (); 374 374 L.CompletionItem.create ~label: "sequential" ~insertText: (next `Random) ()