Run dependencies in current folder instead of vscode directory - visual-studio-code

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.

Related

how to import a Cmake Project which used .sh scripts for build to Vscode?

I have a legacy code base which has CMake configuration and .sh files which calls build commands with respect to build type ( release, relwithdebinfo etc.) as well as does a lot of things.
I have to work over codebase. So far I used STM32CubeIDe. I imported the project as existing Makefile project and then I changed C/C++ Build directory to where makefile outputs converted.
So whenever I did a change on the code, I hit the build command over UI and it calls make command at where I modifed the path above.
This is working but In case of a need of debug then I had to use .elf outputs and OZONE J link Debug program.
I have to do build+debug in same environment but eclipse is slow and making me struggle.
How can I make VSCode host to my legacy code in order to build and debug and also navigate in code i.e go to the definition of code in VSCode, not only building.
Please navigate me if anything needs to share from existing code base, if there is still unclear.

Best practice for centralised management of Visual Studio Code extensions

We're trying to maintain a single set of Visual Studio Code extensions within our organisation, managed centrally. In our ideal scenario all end users have the same extensions installed, those extensions are updated on their behalf, and they are not able to install additional extensions.
We had achieved this to date by:
Installing extensions to a directory under C:\Program Files and setting the (undocumented) VSCODE_EXTENSIONS environment variable to point to that location.
Configuring a scheduled task (run as SYSTEM) that executes a powershell script with a list of extension_ids that calls code install-extension <extension_id> on each.
This solution worked until a breaking change in v1.74 expected to be able to write a new extensions.json file to the extensions directory.
Whilst we can get around this by creating a extensions.json file in that directory, I don't want to go too far down the wrong path. Is there a preferred method for centrally managing extensions for Visual Studio Code?

How to override Visual Studio Code source

I want to be able to extend/override some of the VS Code source in my extension, but I'm not sure how to do so. Is this possible?
Extensions (as the name says) can extend the functionality of the host application (here vscode), but they are separate code parts which have no access to the host application code and structures (except those particularly exported for use by extensions).
If you want to modify vscode source code then clone the repo, change the code and build your own vscode application.

How does an extension for VS Code get the install path of VS 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.

How to determine if a build is from the editor or command line?

I am building a C++ solution with Visual Studio 2005.
Sometimes I open the solution in Visual Studio and build it from within the development environment. Other times I build it from the command line using msbuild.exe. I'm wondering if there is a way that I can determine which of these two types of builds I'm using at compile time (for example, a macro or something like like that). I want to change the path of my output files based on this determination. So, if I'm building from within Visual Studio I would put my output files in FolderA but if I'm building from the command line I would put my output files in FolderB. Is this possible?
Perhaps you can pass in a command-line parameter when building from the command-line that would indicate you are building the solution from the command-line. Otherwise, you can assume you are building from within Visual Studio.
I don't have the answer to your general question, but in order to change the output path, have you thought of adding project configurations ? You could copy project configurations and update the output path of the new ones.