What to do if you notice a substantial improvement to a result in a paper whilst refereeing it?
Option (1) is definitely the professional course of action in this case. As pointed out in the remarks, it is likely to lead to an offer of co-authorship from the original author, but that is purely within the author's discretion. If you feel that your improvement is really substantial and you are worried about credit you can try to increase the chances of co-authorship by asking the editor to put you in contact with the author (after explaining the situation to the editor). You may then discuss this with the author directly and suggest co-authorship, a situation in which the author is more likely to accept (but they still may insist to refuse, in which case you should give them the idea "for free"). If your improvement is sufficiently significant and novel that not getting credit for it seems an unacceptable injustice, then what you can do is wait for the paper to be published (or accepted and online) and then write to the author with your idea of improvement and suggest co-authorship for a second paper. Here of course if they refuse you can publish alone. In any case, you should not submit your own paper without giving the original author a chance of co-authorship. That would be rather unprofessional.
Just do (1), and pat yourself on the back!
My advise: don't do 3) in any case. It is up to you to decide, not the editor. The rest depends on the paper and on the improvement.
Would you recommend to accept the paper as is? Suppose the answer is yes. Now imagine that you see this paper published, and you see how to make an improvement. Would you publish this improvement as a separate paper of your own? If yes, then do 2). If not, do 1).
You think the paper in its present state is not worth publishing but your improvement will make it worth. Then do 1). Then it is likely that the author of the paper will propose you joint authorship. And you may agree or not.
If you think that the paper does not deserve to be published (with the improvement or without). Then recommend to reject and do nothing else.