What would be the best approach for writing a lifetime visualizer?

i'm considering writing a lifetime visualizer. i'd like to ask what would be the best approach to that..
I'm thinking of 2, but maybe there is something better?

  1. trying to integrate some how with compiler, are there some kind of hooks or anything?
  2. get syn crate and parse code manually?

What do you think?