How does an extension for VS Code get the install path of VS Code? - visual-studio-code

I'm developing an extension for VS code(Using javascript). Now I need the path where VS Code installed.
There is a way for windows:
var child = require('child_process');
child.exec('reg query HKEY_CLASSES_ROOT\\*\\shell\\VSCode /v Icon', function (error, strOut, strError) {
//some code...
})
But it works while user installed VS Code correctly only. If this folder was copied from other machine (it means nothing of VS Code in Registry), this function will fail.
On the other hand, it couldn't work at all on Linux or OS X.
I wonder if there are APIs which can be helpful(I found nothing), or other ways can get that path.

I don't know why are you need directory of VSCODE but I needed the directory where are my extesion.
And it can be accessed as follows:
var myExtDir = vscode.extensions.getExtension ("publisher.name").extensionPath;
Where publisher and name are in package.json

VSCode is written and uses node.js, therefore you can access both the computer, user and node environment variables.
To get the used install path of VSCode you can use the following;
process.env.VSCODE_CWD
For instance, if the first thing my extension did was;
console.log(process.env.VSCODE_CWD) it would print out the following in the debug console C:\Program Files\Microsoft VS Code (This is where I have installed VSCode to).

You can now use
const vscodeInstallPath = vscode.env.appRoot;

I thought I'd add the answer that you found yourself in case other people come looking for the same thing.
path.dirname(require.main.filename);
in Ubuntu returns (for me)
/usr/share/code/resources/app/out
and in Windows, returns
c:\Program Files\Microsoft VS Code\resources\app\out
It should return something appropriate for OSX too.
This is the folder containing bootstrap.js, which is enough to determine where the application is installed (the default locations in this instance).
In my case, I wanted the path to one of the node modules (vscode-ripgrep) which is built as part of vscode, so I have to process the path a bit more, but it does the job.

Related

VS Code move Cache location in Windows

I am trying to use models from Hugging Face, but VS code always downloads them into my very limited C: drive; C:\Users\<user>\.cache.
How can I force it to cache to a different drive?
Things I've tried:
Googling: only seen threads for Linux, whose commands do not transfer over. Could not find clear equivalent commands for Windows.
Running a new instance from terminal code --user-data-dir E:/.cache
Fully un-installing VS Code, downloading a portable version, and making a data folder (following these instructions)
All of them still result in caching to C:\Users\<user>\.cache.
From some further research, it appears this is currently not possible.
However, I've found that symlinks is a great temporary workaround. In short,
Create a folder on a drive/partition with an abundance of space, i.e. E:\TempCache
Close any instances of VS Code, if any.
Navigate to C:\Users\<username>\.cache. If there's anything in it, cut them over to E:\TempCache, and delete the whole .cache folder.
Open cmd with admin rights, and enter mklink /J "C:\Users\<name>\.cache" "E:\TempCache". This will re-create an empty .cache folder.
Next time VS Code is ran, it will automatically detect and use the .cache folder on the C drive like nothing changed.

Run dependencies in current folder instead of vscode directory

I am looking to build a VSCode Extension around a CLI tool which we have been working on. An example command would be
myCLI retrieve SourceName
This would be run from a specific directory (for example c:/workspace/myproject) which has been setup and contains a settings.json file for some config arguments.
This CLI has been designed that the methods which are called (for example 'retrieve') are exposed directly so the CLI itself is a wrapper also.
When trying to call these methods directly from a VS Code Extension, it is always checking in the C:/Program Files/Microsoft VS Code directory, which I understand is where the Extension is excuting from.
Now, the question: Is there any way for me to force that any time we call the method (for example 'retrieve') that this would look into the current workspace folder (C:/workspace/myProject) , and not the VS Code one (C:/Program Files/Microsoft VS Code)?
Notes which may change answers
CommonJS (not yet ESM)
We currently cannot pass in a full qualified path (for example C:/workspace/myProject), it is only looking for ./settings.json since it depends on where the CLI has bene run from
I want to avoid calling the CLI directly, as I would like to bring many of the CLI features into the VS Code Extension directly to improve user friendliness.

Visual Studio Code debug mode issue

I'm sorry to bother , I don't know if I can ask this
Visual Studio Code, suddenly can't use debug mode to set interrupts to test.
It seems that it is talking about the folder name problem, but after accessing the folder, it will not be renamed. How can I solve it now? I can't upload photos so I'm capturing the important parts.
i.e.: the module "queue" could not be imported because it is shadowed by:
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/queue/__init__.pyc
Please rename this file/folder so that the original module from the standard library can be imported.
Not sure how to change folder name or duplicate name, these actions are forbidden after accessing the folder, or is this some other problem?
This looks like an actual issue in VSCode - https://github.com/microsoft/debugpy/issues/886
In case you're using python 2.7, Downgrading the python VSCode extension should help.

What is the correct way to set the Glsland Validator Path on the GLSL Lint extension for VSCode on Windows (using WSL)

Trying to play around with shaders on the browser and just installed the GLSL Lint extension for VSCode, which apparently needs to know the path to a glslangValidator binary before working properly.
Said binary can (I'm assuming) be found here: https://github.com/KhronosGroup/glslang/releases/tag/master-tot
However, I've already tried multiple combinations of installation paths, both within Linux and Windows, to no avail: the extension keeps spewing an ENOENT error as can be seen in the picture below:
Considering my setup (Using VS Code on Windows with WSL), where exactly should I place this binary file so that GLSL Lint can properly find it?
I tried, for example, both ~/glslang/bin/glslangValidator and C:\\Users\\{User}\\AppData\\Local\\Packages\\TheDebianProject.DebianGNULinux_31v5hhsz12ds6\\LocalState\\rootfs\\home\\glslang\\bin\\glslangValidator (among other installation paths), but so far none worked.
What am I missing?
I just figured it out--the problem is that using VSCode with WSL will change the file system that the path should be written in. Instead of downloading the windows binary glslangValidator.exe, you should download the linux binary glslangValidator. Check this link and copy the url of the latest release, then download it like so:
cd ~ # Or wherever you want it
wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-linux-Release.zip
unzip glslang-master-linux-Release.zip -d glslang
Then, you need to set the glslangValidatorPath to the WSL path:
"glsllint.glslangValidatorPath": "/home/<username>/glslang/bin/glslangValidator"
*Of course, replace <username> with your username, and if you installed it in a different directory, use that path instead.
I'm using Windows and installed glslang in my root path. After that I set the path parameter like this and it worked:
"glsllint.glslangValidatorPath": "C:/glslang/bin/glslangValidator.exe"
Alternatively, you could add C:/glslang/bin to your PATH variable.
I am using Windows
The following helped me: change the extension of the vertex shader file to ".vert" and the extension of the fragment shader file to ".frag".

xcopy is not recognized as an internal or external command, operable program or batch file

I have a problem using 'xcopy' command.
I'm building a C# project with msbuild. At the end of the build, a batch file is called to copy my assemblies from Debug/Release to some other folders.
Here is the problem, my build fail and the error log is 'xcopy is not recognized as an internal or external command, operable program or batch file'.
The path is correctly set, xcopy do works from a windows command line and from the visual studio command line (the one set with the project environment).
I tried to set the path in the batch file but it doesn't help.
Any suggestion?
I'm using windows 7
Cheers :)
I encountered the same problem.
It seems to be a problem with the path environment variable within Visual Studio.
When I added a "path" statement to the beginning of my build event, it produced the following output:
PATH=
This seems to indicate that the path is empty within the VS build environment.
When I specify the full path to xcopy like this, the problem went away:
%systemroot%\System32\xcopy ...
I'm not sure what caused Visual Studio to lose it's path.
Set Environment variable PATH = %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
This is not a problem with Windows 7 or 8. It's actually a problem with applications that update environment variables such as PATH.
The PATH is stored in the Registry as an "Expandable string value" (REG_EXPAND_SZ), but a lot of applications write it back to the Registry as a "String Value" (REG_SZ). If your path contains anything like %SYSTEMROOT%, this will not be expanded into C:\Windows (or whatever yours is) if the path is stored in a REG_SZ.
The fix is simply to edit your path manually from the control panel. You need to make a change (eg add a ; to the end of the path) and then apply it. This will fix up your path in the Registry to be a REG_EXPAND_SZ.
(Go to the System Control Panel and select Advanced System Settings. Edit the Path Environment variable in the lower box, and that should fix it.
You can tell whether your path is broken in this way by opening a command prompt and typing PATH. Your path will be listed. If you can see anything enclosed in % % then your path is not being expanded.
It happened to me after I updated one of my Visual Studio extensions, during which Visual Studio was closed and reopened by the updater. I could no longer properly build my project. I closed Visual Studio and reopened it and the problem went away.
I just experienced this for the first time with a batch file I use to copy an Access front-end app to the user's local machines. Their environment is a mix of Windows 7 & 8 and 32-64 bit machines. I noticed that the xcopy.exe was both in the System32 and the SysWOW64 folders and I wondered if there was some conflict. So -- I copied the xcopy.exe into the folder where the batch file resides and it now seems to be working. Just thought I'd share this.
Eileen
I also had a problem with xcopy (same error message) - with a very simple batch program that I use to backup files to a removable drive. Have been using that program for at least 5 years with never a problem. Then yesterday xcopy is unknown to Win7. The replacement of xcopy with %systemroot%\System32\xcopy at each instance solved the problem. Very strange.
Go to environment variable and correct PATh including ; in last.
It will work, this is not at all related to OS or Technology.
It's working for me, Not even need to restart OS, Just open new command prompt.
[Fixed for me]
After adding the correct paths to "Path" environmental variable it still doesn't work (for cmd and VisualStudio) (even after restarting the PC).
The problem was in broken register parameter:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
ParameterName=PATHEXT
I had the value .wlua;.|exe. Maybe was broken after installing something.
Everything works again after changing it to:
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
Hope this helps if nothing other works.