Skip to content

feat: Add semantic token modifier for crate root #10403

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

Merged
merged 1 commit into from
Oct 1, 2021

Conversation

lhvy
Copy link
Contributor

@lhvy lhvy commented Sep 30, 2021

Resolves #9073

I managed to implement crate root highlighting for crates mentioned specifically by name (e.g. serde in use serde::Serialize;), but not for crates referred to with crate or super. How could I implement this?

P.S. I'm participating in Hacktoberfest 2021. If this PR is up to standard and merged, I'd appreciate if the hacktoberfest-accepted label could be added. Thanks!

@Veykril
Copy link
Member

Veykril commented Sep 30, 2021

Huh that seems odd, crate and super should go through that code path as well 🤔 Ah nevermind they don't

@Veykril
Copy link
Member

Veykril commented Sep 30, 2021

So super and crate land in here https://github.com/rust-analyzer/rust-analyzer/blob/4f3ce62b0daeaca48cb8c7f3d26712a402c5c9b7/crates/ide/src/syntax_highlighting/highlight.rs#L184-L218
I think we just wanna skip them like we do for self here so that they are being handled as NameRefs and then change the highlight back to HlTag::Keyword as is done for self with SelfParam here
https://github.com/rust-analyzer/rust-analyzer/blob/4f3ce62b0daeaca48cb8c7f3d26712a402c5c9b7/crates/ide/src/syntax_highlighting/highlight.rs#L310-L314

@lhvy lhvy force-pushed the crate-root-token branch from e5a803c to a0bdcf3 Compare October 1, 2021 09:20
@lhvy lhvy force-pushed the crate-root-token branch from a0bdcf3 to dbb0237 Compare October 1, 2021 10:52
@lhvy lhvy marked this pull request as ready for review October 1, 2021 11:01
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

Thanks!
bors r+

// self is handled as either a Name or NameRef already
T![self] => return None,
// crate is handled just as a token if it's in an `extern crate`
T![crate] if parent_matches::<ast::ExternCrate>(&token) => h,
Copy link
Member

Choose a reason for hiding this comment

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

good catch 👍

@Veykril Veykril changed the title Add semantic token modifier for crate root feat: Add semantic token modifier for crate root Oct 1, 2021
@Veykril
Copy link
Member

Veykril commented Oct 1, 2021

We tagged the repo with hacktoberfest now so the label shouldn't be necessary anymore, if it is for some reason just drop a comment here

@bors
Copy link
Contributor

bors bot commented Oct 1, 2021

@bors bors bot merged commit 47c079a into rust-lang:master Oct 1, 2021
@lhvy lhvy deleted the crate-root-token branch October 1, 2021 11:27
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.

Add semantic token modifier for crate root
2 participants