How to get the line number in TextEdit
I typically use the App Store app to download BBEdit since it runs for free and has all the things you would want including line numbers. If you are familiar with VSCode, that’s a solid option too, but it is not a native app like BBEdit and TextEdit are.
I’m fairly sure there is no line number function in TextEdit.

http://www.barebones.com/products/bbedit/index.html
https://code.visualstudio.com/