first open bluestacks and go to settings > preferences > check the Enable Android Debug Bridge (ADB) and press Change path button, then select adb path.
(default location: %LocalAppData%\Android\sdk\platform-tools)
then install one apk in emulator (by click the installed apps > install apk in bluestacks home screen)
after doing this works run cmd by administrator and got to adb path then run this command:
adb connect localhost:5555
now you can open VSCodde or AndroidStudio and select BlueStacks emulator.