To Connect Bluestacks to Android Studio or VS Code.
Enable Android Debug Bridge (ADB) in BlueStacks:- Go to Settings / Preferences and Scroll Down to last and you find the ADB option. Just Enable it. See the Below ScreenShot.
Go to adb.exe location:- Go to adb.exe location means go to C:\Users\user-name\AppData\Local\Android\Sdk\platform-tools or press Win + R and paste it %LocalAppData%\Android\sdk\platform-tools and open command prompt or Terminal there and Execute the below Command.
adb connect localhost:5555
After running the command it shows connect to localhost:5555 means Successfully Connected.