I'm presuming you are trying to do this as user pi, but the same method applies for anyone. As others have said, running VS code as root probably isn't a great idea. Instead you want to give the VS code user access to the relevant directories.
Get the permissions and ownership set on the directory you want. For example:
> stat /var/www
File: /var/www
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 803h/2051d Inode: 1716748 Links: 4
Access: (0755/drwxr-xr-x) Uid: ( 1028/ foo) Gid: ( 1028/ foo)
Access: 2021-02-01 10:08:08.000000000 -0500
Modify: 2021-02-01 10:08:08.000000000 -0500
Change: 2021-02-23 16:41:13.431801967 -0500
Birth: 2018-04-12 12:27:12.113737308 -0400
In this case it is owned by user foo, group foo, permission mode is 0755 meaning anyone can read but only the owner can write. Change this to allow other users in group foo to write:
sudo chmod 775 /var/www
Now, add user pi to the foo group:
sudo usermod -G foo pi
This will be effective when pi next logs in. In theory since it increases access it opens up a vulnerability -- but chances are there was no one in group foo besides user foo, so this is in theory only. To check that:
> grep foo /etc/group
foo:x:1028:pi
The users in the group, except for foo, are shown after the last colon.
An alternative is to change the group ownership of the directory:
> chgrp pi /var/www
Again, since foo still has write access, nothing else will have changed besides granting it to those in group pi -- which is probably just pi.
You can read more about the commands used via (eg.) man chgrp.