Stream: t-compiler/wg-rls-2.0

Topic: semantic highlighting


Pascal (May 23 2019 at 12:02, on Zulip):

hey, i wanted to look into semantic highlighting a bit (just because i was curious). i assume i'll need to get some kind of resolved identifiers map? building on the code from https://github.com/rust-analyzer/rust-analyzer/pull/1305 all i can get for bindings is that their kind is MACRO_CALL. what am I missing? :)

Laurențiu Nicola (May 23 2019 at 12:04, on Zulip):

See https://github.com/rust-analyzer/rust-analyzer/pull/1305/files#diff-7bd880cade5b808a957f2da2c32f6ecdR52

Laurențiu Nicola (May 23 2019 at 12:04, on Zulip):

You should get a reference to the macro definition

matklad (May 23 2019 at 12:04, on Zulip):

Hm, why macro calls?

matklad (May 23 2019 at 12:05, on Zulip):

I think you should check this variant: https://github.com/rust-analyzer/rust-analyzer/pull/1311/files#diff-6a30d8b895db7e4b6fba39666fe0aaabR13

matklad (May 23 2019 at 12:05, on Zulip):

Basically, if two AstPtr<ast::Pat> are the same, that's the same binding, and you can color it in the same color

matklad (May 23 2019 at 12:05, on Zulip):

does this make sense?

Pascal (May 23 2019 at 12:06, on Zulip):

re macros: I have no clue, I just wanted to know what node kind to match on so i added format!("{:?}", node.kind()) and got MACRO_CALL :shrug:

Laurențiu Nicola (May 23 2019 at 12:07, on Zulip):

Don't look at node.kind(), look at the result of classify_name_ref

Pascal (May 23 2019 at 12:07, on Zulip):

ah, so you're saying it should be in the NAME_REF case as well?

Laurențiu Nicola (May 23 2019 at 12:08, on Zulip):

NAME_REF is a reference to a ..symbol, including macros, but node doesn't contain that information

Laurențiu Nicola (May 23 2019 at 12:08, on Zulip):

NAME is a symbol declaration (or definition)

Laurențiu Nicola (May 23 2019 at 12:12, on Zulip):

What classify_name_ref does is it takes a NAME_REF and gives you back the definition of that name, like a MacroByExampleDef for macros. That ends up wrapping an AstId, which could presumably be hashed or used otherwise to assign a color

Pascal (May 23 2019 at 12:12, on Zulip):

i think i'm a bit confused how that match node.kind() works :D i'll play around with it a bit

Pascal (May 23 2019 at 12:12, on Zulip):

thanks

Laurențiu Nicola (May 23 2019 at 12:12, on Zulip):

If you're using RA in VS Code, try the "Show Syntax Tree" command

Laurențiu Nicola (May 23 2019 at 12:12, on Zulip):

node is just an AST node, without any semantic information

Pascal (May 23 2019 at 20:08, on Zulip):

super trivial first version just to see if it's doable: https://github.com/rust-analyzer/rust-analyzer/pull/1319

Pascal (May 25 2019 at 11:34, on Zulip):

@matklad hm, testing highlighting via html output will mean that for the rainbow stuff i'll need to figure out how best to get the color calc code in there. it depends on a seedable rng which is an external dependency but i might just inline it

matklad (May 25 2019 at 11:35, on Zulip):

For testing, you can only set the css class to hash, without adding any JS magic

Pascal (May 25 2019 at 11:35, on Zulip):

nah, that's too boring

matklad (May 25 2019 at 11:39, on Zulip):

Hm, you can also generate css itself on the server-side :thinking:

Pascal (May 25 2019 at 11:42, on Zulip):

good idea! that also makes implementing a --rainbow flag easier

Last update: Nov 12 2019 at 15:30UTC