Manufacturer's life-cycle statements
Most manufacturers have a section on their datasheets giving the status of the part. For example TI classify their parts as:
PREVIEW: Device has been announced but is not in production. Samples may or may not be available.
ACTIVE: Product device recommended for new designs.
NRND: Not recommended for new designs. Device is in production to support existing customers, but TI does not recommend using this part in a new design.
LIFEBUY: TI has announced that the device will be discontinued, and a lifetime-buy period is in effect.
OBSOLETE: TI has discontinued the production of the device.
So you would look for an active device, not any of the other categories. Other manufacturers use other systems, but they are generally similarly easy to understand.
Choosing among active parts
There's rarely any way of telling when a device is going to move from 'active' to one of the other classes. A very profitable part will never move, whereas, a part which is developed and then doesn't sell well, might get discontinued very quickly. But there are some extra things you can do if you want to make extra sure the part will remain available
Talk to the manufacturer. Maybe they'll tell you that the part might be moving to NRND in a couple of months. Or maybe they won't, because they aren't ready to publicly announce it, or because the sales guy you're talking too simply isn't in on the discussions about what to discontinue. If you're a big customer, you're more likely to get a good answer. If you're a very big customer, they might promise to keep making if you keep buying.
Buy a popular product. Manufacturers don't discontinue chips which are bringing in lots of money. If it's selling well, it'll be available for a while. Either that, or a drop-in replacement will appear. Look for chips which all the distributors have lots of stock of, or that are general "go-to" chips for a certain type.
Consider second sourcing. Some chips are made by more than one manufacturer, e.g. LM317 voltage regulators. Prefer that chip over something more esoteric, and if TI stop making them (unlikley!) you can buy them from ON or Linear instead.
Consider replacement beforehand. Maybe you want chip X, and it's available in package A, B or C. Chip X is a bit niche, and might get discontinued, and chip Y would do the job, but costs more. Chip Y comes in package B, C or D, and the C package is pin-compatible with chip X package C. So design around package C, buy chip X, and keep chip Y as a backup plan.