While it's not a long-term solution in itself, asking a person and having them talk about how they feel greatly reduces their feelings of isolation and distress, which in turn significantly reduces the immediate risk of suicide.
People who do care may be reluctant to be direct in talking about suicide because it's something of a taboo subject.
In the medium and longer term, it's important to seek help to resolve the problems as soon as possible; be they emotional or psychological. Previous attemptors are more likely to attempt suicide again, so it's very important to get unresolved issues sorted out with professional help or counselling as necessary.
Some issues may never be completely resolved by counselling, but a good counsellor should be able to help a person deal with them constructively at present, and to teach them better coping skills and better methods of dealing with problems which arise in the future.