Building chemical complexity with ion-molecule reactions: from protostellar stages to Solar System planets and exoplanets