Why does the formatter need to solve this and not the editor? The editor has more information available to it, like the present screen space.
Because making the line wrapping nice requires deep syntax-aware editor integration. Most languages try to be at least somewhat plain-text-editor-friendly.
Why does it need to be syntax aware?
'nice' is the key word here
I think it's just a matter of programmer habit now -- folks expect their editor to mirror the code without formatting tweaks.
It gets confusing when you realize that programmers may insert their own indentation and wrapping, and sometimes you want to make this part of the actual file, and sometimes you want to remove it before serializing.