oki this is just my opinion

I think that if a person is attacked with suicidal thoughts and is really
trying to avoid them, they are not sinning. But if they choose the suicidal thoughts over non suicidal ones, they are. Does this make sense? It matters on the intention and what they do with their free will.
I went through a very painful time once when I literally felt spiritually attacked with terrible thoughts. It did not seem that these ideas came from me at all, and it was so hard to avoid them. I really tried to block them and prayed so much..and nothing helped. Until one day, God made it all end

and I don't have these thoughts anymore, and even if I'm reminded of them, I can block them. Well..God knows I was really trying to stop thinking this way..so I'm not sure if I was sinning... I did however pray for forgiveness for this and felt extremely guilty about it all.
Hope that helps...
So to answer the OP question, I'd say that if the person doesn't
choose to think suicidal thoughts and
sincerely tries not to, then it'll be alright to take the Eucharist. But if not, they should go to confession. I'd say it's best to talk to a priest about this if it's an issue, and it wouldn't hurt to confess anyway... even if the thoughts are caused by something psychological or even demonic, we never know how much of our free will was involved!
God bless
monica