Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_rowan): add the root node as an associated type on the language trait #2689

Merged
merged 1 commit into from
Jun 9, 2022

Conversation

leops
Copy link
Contributor

@leops leops commented Jun 9, 2022

Summary

This PR is part of the general goal of making the analyzer language-agnostic. It adds a Root associated type on the Language trait in rome_rowan bound to the AstNode<Language = Self> trait (as well as Clone, Debug and Eq for convenience) and corresponding to the "document root" node type for this language (eg. JsAnyRoot for JavaScript).
This lets most of the analyzer be agnostic over the language it's processing, except at the root level in the analyze function since the RuleRegistry only has a factory for JS rules at the moment. As an extension of this, the Workspace also only supports emitting code actions strongly typed to the JavaScript language for now.

@leops leops temporarily deployed to aws June 9, 2022 08:16 Inactive
@github-actions
Copy link

github-actions bot commented Jun 9, 2022

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45878 45878 0
Passed 44938 44938 0
Failed 940 940 0
Panics 0 0 0
Coverage 97.95% 97.95% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 350 350 0
Failed 5596 5595 ✅ ⏬ -1
Panics 0 1 ❌ ⏫ +1
Coverage 5.89% 5.89% 0.00%
💥 Failed to Panic (1):
subtypingWithCallSignatures4.symbols

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12391 12391 0
Failed 3866 3866 0
Panics 0 0 0
Coverage 76.22% 76.22% 0.00%

@github-actions
Copy link

github-actions bot commented Jun 9, 2022

@IWANABETHATGUY
Copy link
Contributor

@xunilrj , Is this behavior expected ?
image

@ematipico
Copy link
Contributor

@leops is there a test plan for this PR? Could you please put back that section from the template?

fn pull_actions(
&self,
params: PullActionsParams,
) -> Result<Vec<AnalyzerAction<JsLanguage>>, RomeError>;
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem correct. JsLanguage should not be inside this generic trait

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what I mentioned at the end of the PR description, basically this interface was never language-agnostic in the first place (because the analyzer currently only supports emitting code actions for JavaScript), this change only makes it explicit.
Eventually the Workspace will not directly return a list of AnalyzerAction objects, since those contain actual syntax tree instances it would be complicated to transfer those across an IPC boundary for instance, so the code action will probably get transformed into a simple text diff before being sent to the CLI or language server (which is then completely independent of the language)

pub fn pull_actions(
&self,
range: TextRange,
) -> Result<Vec<AnalyzerAction<JsLanguage>>, RomeError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. Is there a plan to make this language-agnostic?

pub(crate) struct RuleRegistry {
rules: Vec<RegistryRule>,
pub(crate) struct RuleRegistry<L: Language> {
rules: Vec<RegistryRule<L>>,
}

/// Utility macro for implementing the `with_filter` method of [RuleRegistry]
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment seems outdated now. This macro is now language specific, maybe we should call it with a different name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment is still explaining what the macro is used for, although I agree it doesn't really explain why it works like this. In a future refactor this macro will either get moved to rome_js_analyze along with all the JS lint rules or completely removed and be replaced by the analyzer codegen script, so this is basically intended as temporary helper until the analysis infrastructure is properly split out from the language rules.

@leops
Copy link
Contributor Author

leops commented Jun 9, 2022

@leops is there a test plan for this PR? Could you please put back that section from the template?

I didn't include that section because I didn't really have anything to add there, this change is done entirely at the type system level and doesn't modify any actual "program code" so it's tested by "if it builds, it works"

@leops leops force-pushed the feature/language-root-type branch from df162e4 to d2861ae Compare June 9, 2022 14:22
@leops leops temporarily deployed to aws June 9, 2022 14:22 Inactive
@cloudflare-pages
Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: d2861ae
Status: ✅  Deploy successful!
Preview URL: https://e7e592da.tools-8rn.pages.dev
Branch Preview URL: https://feature-language-root-type.tools-8rn.pages.dev

View logs

@leops leops merged commit 90cae70 into main Jun 9, 2022
@leops leops deleted the feature/language-root-type branch June 9, 2022 14:54
@xunilrj
Copy link
Contributor

xunilrj commented Jun 9, 2022

@xunilrj , Is this behavior expected?

No. I am trying to understand what is happening. :(

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

Successfully merging this pull request may close these issues.

None yet

4 participants