Page MenuHomePhabricator

[clangd] Highlight related control flow.

Authored by sammccall on Apr 19 2020, 5:20 AM.



This means e.g. highlighting "return" will show other returns/throws
from the same function, highlighting a case will show all the
return/breaks etc.

This is a bit of an abuse of textDocument/highlight, but seems useful.

Diff Detail

Event Timeline

sammccall created this revision.Apr 19 2020, 5:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 19 2020, 5:20 AM
adamcz added inline comments.Apr 20 2020, 3:37 AM

You are checking for FunctionDecl twice


What about "goto"? It's more difficult to figure out if it breaks out of the loop or just jumps inside it, but it might still be worth highlighting it, even unconditionally (inside a loop only, not function).


That's a nice feature, but there's no test for it. Can you add it?


Can you add a test for macros? I think highlighting like ASSIGN_OR_RETURN(int x, foo()); would be great, but even if we don't support that, just having a test that we don't crash would be valuable, IMHO.

sammccall updated this revision to Diff 264734.May 18 2020, 3:19 PM
sammccall marked 6 inline comments as done.

Address comments, handle goto.


I think I worked out the right logic for where it jumps based on Bounds (which we now always compute).

Selecting the goto statement itself isn't handled here, it should be handled as a "regular" reference to the labeldecl. (But isn't yet).


Changed the sourcelocation handling to enable macros.
Now if the relevant keyword is expanded from a macro body, the macro name will he highlighted. If it's expanded from a macro arg, the arg will still be highlighted.
Added a test for both.

adamcz accepted this revision.May 19 2020, 4:37 AM
adamcz added inline comments.

nit: in a do {...} while(...) case, would we want to highlight both keywords?

(doesn't seem very important, feel free to ignore)


nit: weird line wrap here?

This revision is now accepted and ready to land.May 19 2020, 4:37 AM
sammccall marked 3 inline comments as done.May 19 2020, 8:35 AM
sammccall added inline comments.

Yeah, I just left a comment for this. You're right... but do-while is pretty rare and the code is fairly awkward. Let's see if anyone ever mentions it :-)

This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.

Hi Sam,

It looks like this is causing a failure on the Windows PS4 buildbot:

Please could you take a look? PS4 target disables RTTI, hence exceptions, by default so it is probably related to that.