-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Try to resolve name refs during highlighting #1305
Conversation
662ef08
to
90cbd36
Compare
The end-result looks good to me! However, I think we should probably start refactoring On the high level, the situation is as follows:
I think both goto definition and highlighting want the same set of "shapes", but want to process them differently. Let's extract a helper function, with roughly the following signature enum NameRefKind {
MethodCall(hir::Function),
MacroCall(hir::MacroBYExampleDef),
FieldAcess(hir::StructField)
...
}
fn classify_name_ref(analyzer: &SourceAnalyzer, name_ref: ast::NameRef) -> NameRefKind {
...
} We should then be able to result this function in both highlighting and goto def |
Thanks for the suggestion. I'll try, but it's still not clear to me:
|
Or maybe you want to avoid future duplication? That would make sense. |
I think if we add all bells&whistles to syntax highlihting, we'd have to re-implement all of these logic:
That and the lack of index would indeed be the only differences. But not using To demonstrate the concrete problem, suppose we do use This "using public API types to build an internal implementation" problem is pretty bad long term. We already suffer from this in |
90cbd36
to
4efda37
Compare
Updated on top of #1311. I'll leave the |
Looks awesome! bors r+ |
1305: Try to resolve name refs during highlighting r=matklad a=lnicola Preview: ![image](https://user-images.githubusercontent.com/308347/58245782-3d476e00-7d5e-11e9-938c-6124471619cd.png) This is probably not the cleanest implementation, but it's not clear to me what parts of `reference_definition` we don't want to run at this point. Also, is the `SourceAnalyzer` cheap enough to construct for each `NameRef`? Not like there's any alternative at this point, though. Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
I think this breaks highlighting of function definitions. |
cc #1314 |
Build failed |
I guess, just restoring I've also realized that we don't have anything better than a smoke test here, which seems sub optimal :-) Could add a more flavorful test-case here? I think just a bigger example would work. OTOH, it would be cool to make the test itself more readable, by, for example, generating html output instead of just debug dump of highlightings. Though, this seems like a lot of effort for relatively little gain, unless we can make html-dumping code really simple. |
Hm, actually, "dump code as a sytax-highlighted HTML" is a cool feature to have regardless, so perhaps it makes sense to just do it? Doesn't seem too hard: I think one must basically wrap highlighted ranges into spans with appropriate classes |
4efda37
to
307ce79
Compare
307ce79
to
f1ec88c
Compare
Fixed. |
bors r+ |
1305: Try to resolve name refs during highlighting r=matklad a=lnicola Preview: ![image](https://user-images.githubusercontent.com/308347/58253075-43464a80-7d70-11e9-84cc-e81990f2d3eb.png) This is probably not the cleanest implementation, but it's not clear to me what parts of `reference_definition` we don't want to run at this point. Also, is the `SourceAnalyzer` cheap enough to construct for each `NameRef`? Not like there's any alternative at this point, though. Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
Build succeeded |
I'll work on it unless anybody else has already started |
That's fine by me. |
How do we do the same thing for names? |
You mean, how do we color enums differently from, say, structs? I think that should be relatively easier to do: one needs to look at the ast parent of the corresponding ast::Name |
I was thinking of variables and function definitions, but the same approach should work. |
@matklad what are those three dots underneath some letters in your screenshot? (just curious) |
@bjorn3 that's the spellchecker. By default, VS Code renderns "info" level diagnostics using short strip of dots |
Preview:
This is probably not the cleanest implementation, but it's not clear to me what parts of
reference_definition
we don't want to run at this point. Also, is theSourceAnalyzer
cheap enough to construct for eachNameRef
? Not like there's any alternative at this point, though.