Prakriti
Hi, I'm a Mindflayer, but don't let that worry you
In that case, I think a ranged attacker can gain advantage as long as they're in a lightly obscured area and/or a long ways off. But I don't think there's any way for a melee attacker to gain the same advantage from hiding. If they jump out from behind a tree with a sword, then they are essentially un-hiding before they make their attack. They can still surprise their target, of course, but they don't get advantage.The rule is for being hidden 'you have to be unable to be seen clearly, not be totally unseen.'
Imagine a hidden sniper observing his target and then shooting from around a tree or log from 100m away. Hes able to be seen at all times (hes peering over the log or around the tree) but is still hidden at all times until the attack is resolved.