Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple language and configuration from the Topiary library #643

Closed
wants to merge 33 commits into from

Conversation

Xophmeister
Copy link
Member

@Xophmeister Xophmeister commented Oct 10, 2023

  • topiary/src/configuration.rs: Definitions and implementations of configuration serialisation (TOML) format, plus default configuration (read at build time).

    • Migrate all code to CLI
    • Refactor CLI to use new configuration
    • Tie-up loose ends in engine that refer to configuration (just comments AFAIK)
  • Error handling: Move serde deserialisation error handler to CLI (CLI already has this.)

  • topiary/src/language.rs: Definitions and implementations of Language, with mappings to Tree-sitter grammars, and SupportedLanguage subset.

    • Minimalise Language type for use in library.
    • Migrate what was removed, with SupportedLanguage to CLI. (Note: At which point the distinction between Language and SupportedLanguage can be collapsed.)
    • Refactor CLI to use new language types. (Note: There may be efficiencies to be had with current CLI language handling.)
    • Refactor library to use minimal Language type.
  • topiary/src/lib.rs: Main entrypoint for the public API of the library. Ensure it matches with the changes described above; tying-up remaining loose ends.

  • topiary/src/tree_sitter.rs: Tree-sitter interface for library. Ensure it matches with the changes described above; tying-up remaining loose ends.

Resolves #606

@Xophmeister
Copy link
Member Author

Xophmeister commented Oct 12, 2023

Note: The significant cuts to this repo, in 14e756f, seem to really be playing havoc with rust-analyzer while the code is in a broken state. This is making progress slow-going 😞

(Additionally, I believe there is something wrong with the Nix development shell. I'm getting toolchain mismatches all over the place and no amount of cargo cleaning is helping...)

@Xophmeister
Copy link
Member Author

I have fixed the rust-analyzer problem 🎉 Now I can actually make some progress!

Copy link
Member Author

@Xophmeister Xophmeister left a comment

Choose a reason for hiding this comment

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

Looks like I can review my own PR, but I cannot approve it 😅

Topiary has accumulated a lot of tech debt in order to push features. While this refactor is quite "ruthless" in what it cuts, I think it's a good first step to start paying off that debt 👍 I've only given the code a cursory look through, but it looks mostly fine.

General comments:

  • It's a shame we've had to (temporarily) remove the Playground and all the work that went into it. I understand and accept the justification, but I think it's worth doing the following in conjunction with this PR:

    1. Tag the previous commit on main with something like playground or old-playground, so it can be found easily.
    2. Create a new issue that calls for the playground to be reinstated, pointing to that tag (for reference) and documenting the reasons why it was removed by this PR, so a more long-term solution can be sought.

    The Playground is a great advocate/demo for new-comers, so (imo) reinstating it should be a matter of utmost priority.

  • I may have misunderstood, but I thought removing tree-sitter-facade as a dependency was one of the aims of this PR? It's still in there and being used.

  • Not for this PR -- it's already gone on long enough -- but I think there's still plenty of scope for refactors and code improvements, to make Topiary more maintainable. (The work that went into this decoupling PR is a testament to how much debt had accumulated!) Perhaps we can look into this and plan some issues around it.

    Also, as contributors, we should actively encourage the "Scouts Rule": Leave the code better than you found it. (Perhaps we can put it in CONTRIBUTING.md or a code of conduct doc...) It pays dividends, over time, despite the making PRs somewhat non-unitary.

@@ -30,28 +23,20 @@ let
"topiary"
"topiary-queries"
"topiary-cli"
"topiary-playground"
"tests"
];
};

nativeBuildInputs = with pkgs;
[
binaryen
Copy link
Member Author

Choose a reason for hiding this comment

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

I think binaryen is a WASM-thing, too.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if the sample tester (and all the input/expected pairs) should be part of topiary-queries, rather than topiary-cli?...

topiary/Cargo.toml Show resolved Hide resolved
topiary/src/language.rs Show resolved Hide resolved
@@ -23,7 +23,6 @@ prettydiff = { workspace = true }
regex = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
toml = { workspace = true }
tree-sitter-facade = { workspace = true }
unescape = { workspace = true }
Copy link

@aminya aminya Jan 12, 2024

Choose a reason for hiding this comment

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

I see that the tree-sitter-language dependencies are still required in the core engine. Maybe not the goal of this PR, but it would be great to be able to abstract the language as well so that it can be passed as a function argument without needing to build the languages we do not need.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is absolutely the plan! Thanks for your feedback!

@Xophmeister
Copy link
Member Author

Obsoleted by #672

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Completely remove all non formatting tasks from the topiary crate
3 participants