Diagnostics sometimes infers certain errors in some places that can be solved with code actions. Hinting to the user of possible code actions (and using diagnostics to put the cursor there) they can easily solve some easy problems.
See this clip for an example of a error that has a code action.
https://clips.twitch.tv/BreakableAmazonianAuberginePipeHype