Skip to content

Conversation

@loadre
Copy link
Contributor

@loadre loadre commented Feb 12, 2025

closes #35

Copy link
Owner

@chshersh chshersh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff!

I left a few minor comments. Since we're improving the quality of the project, I proposed to make a few more tiny changes 😅

Comment on lines +25 to +26
| File { name; _ } -> name
| Dir { name; _ } -> name
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually the main motivation behind doing this minor refactoring.

The internal contents of constructors like File and Dir might change by adding and removing some fields (I already expect a few possible changes). But these changes will be decoupled from functions that don't affect them, so it'll be easier to perform them.

Even such minor things matter when a project grows.

let rec sort_tree = function
| File (name, contents, ft) -> File (name, contents, ft)
| Dir (name, (lazy children)) ->
| File _ as f -> f
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice usage of alias patterns 💯

lib/fs/fs.ml Outdated
in
let dirname = Filename.basename path in
Dir (dirname, children)
Dir { name = dirname; children }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just rename dirname above to name to leverage punning and write just Dir { name; children }.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, let's do one more step and move this new name before if.
This way we can reuse it in both Dir and File cases.

and current offsets. *)
module Filec = Filec

(** A definition of a file tree. *)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor addition while we're on this: let's improve docs by adding a note saying something like that contents and file_type are stored separately as two lazy values so we can quickly understand the file type and use a proper icon without reading the whole contents.

Just a note for future selves so we don't forget the motivation 😅

lib/tui/tui.ml Outdated
match tree with
| Fs.File (path, _, _) ->
| Fs.File { name = path; _ } ->
Printf.eprintf "Given path '%s' is not a directory!" path;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually fine if you don't use name = path and just use name. Makes the code consistent with others.

I now think that path might not be the most accurate variable here.

@chshersh chshersh added type: refactoring Improving the code quality w/o changing functionality component: chore Utils of labels labels Feb 12, 2025
Copy link
Owner

@chshersh chshersh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, thanks!

@chshersh chshersh merged commit e85d1a8 into chshersh:main Feb 13, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: chore Utils of labels type: refactoring Improving the code quality w/o changing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor the file tree type

2 participants