I am using the multiroot workspace functionality to view source files from my c project along with several external libraries. I am using trying to use cpptools extension for intellisense and other functionality. I would like to set default include paths at the workspace level relative to the .code-workspace file. Using ${workspaceFolder} resolves to the path of the folder containing the viewed file. Is there an environment variable that will always resolve the path of the code-workspace file? Or is the a configuration variable I can set and then use ${config:variable}?
I have tried using variables scoped per workspace as described here: https://code.visualstudio.com/docs/editor/variables-reference#_variables-scoped-per-workspace-folder. But, that did not work either. I could use absolute paths and everything would work fine, but I am trying to keep things portable so other people can check out the repository and simply open the .code-workspace file and have everything set up already.
At the time of the question the cpptools extension did not support the ${workspaceFolder:} syntax for enviroment variables. With the latest update, this is now working.
Related
I want to have a single place to store all my Visual Studio Code editor workspace files. I know I can use Workspaces: Save Workspace As to save the workspace file wherever I want, however, when I open a terminal the current working directory is the location where the workspace file is stored. I want to be able to specify (for each individual workspace) what the starting directory should be. Is that possible?
I discovered that by default the path element of the -workspace file is stored relative to the workspace file. By changing that to store the absolute path (which, I understand may not be the solution in all cases), it does work as I was intending.
I basically have a similiar question to this one:
How can i configure clang format without .clang-format file in every workspace?
I'm using the Visual Studio Code editor (version 1.43) with the Clang-Format extension developed by Xaver (https://marketplace.visualstudio.com/items?itemName=xaver.clang-format#overview)
I adjusted the clang extension settings "Clang-format: Executable" option to point to the "clang-format.exe" of my VSC installation.
Furthermore I set "Clang-format: Style" to "file".
My clang-file is currently located inside my projects source folder.
As I want to use my clang settings for every project and don't want to copy the clang file into every project workspace manually (and maybe have to change every single copy later on), I tried to make the extension use a globally located clang-file which is inside the VSCs extention folder.
So my first approach was to relocate the clang-file into the "VSC 1.43\data" directory.
My second attempt was to locate it right inside the extension folder "C:\User\VSC 1.43\data\extensions\xaver.clang-format-1.9.0" where a default file was already present.
Unfortunately both attempts seem not to work. I can invoke the formatting with "Format Document" but another clang file seems to get utilized.
Only if I put the file back into the source code directory, my clang rules are getting utilized correctly.
So basically:
MyProject\SourceCode\clang-file --> Works
VSC\data\clang-file --> Doesn't work
VSC\data\extensions\xaver.clang-format-1.9.0\clang-file --> Doesn't work
Can I tell the extension to search for the clang file inside of the extensions installation directory instead of the current workspace?
Note: I just installed the clang-format extension and adjusted the mentioned extension settings above. I did not tamper with the VSC settings.json.
Thank you in advance and best regards :)
Evox402
As specified in the documentation:
When using -style=file, clang-format for each input file will try to find the .clang-format file located in the closest parent directory of the input file. When the standard input is used, the search is started from the current directory.
Actually I believe it searches for either .clang-format or _clang_format.
This explains:
MyProject\SourceCode\clang-file --> Works
You could move the .clang-format file to MyProject, or any parent directory above that, so that it is shared between projects.
I want to use the same clang-format file for all my project since I have multiple. But I don't want to have them in every workspace and i already have a clang-format file in my home directory, how can I make this work?
Or is this impossible?
I have already seen this question:
How can i configure clang format without .clang-format file in every workspace?
but my clang-format file is like 80 lines long and I just want to edit the stuff locally on my home without having to change it in vscode as well.
Maybe this will help.
The clang-format -style=file is somewhat misleading.
file is not the path to the file you want but rather tells clang-format to use the .clang-format file it can find within the project folders - going all the way up.
And as VSCode is the case, the C++ extension is using by default the clang-format in the VSCode extensions folder.
Which should make the clang-format to go cd .. until it finds .clang-format in your workspace folder
Set "clang-format.style": "file" property to fix it.
Environment: C++ makefile project, with sources on a (slow, shared) network drive. The sources are version controlled and I don't want to add any Eclipse files in the source tree.
Problem: I want to create a local workspace which doesn't write anything to the network drive, and I can't find a way to do this. I've tried half a dozen different things, including explicitly setting the build directory, linking to the top-level src directory, adding a src directory, explicitly setting the make command, changing the default file location, and so on, but I haven't found anything that works. Any ideas?
I imported external libraries using absolute path. But I have two work environments, switching between Linux and Windows. Projects are downloaded from SVN. So I was wondering whether I can import these libraries by relative path.
You should declare a variable (Java Build Path -> Add Variable... -> Configure Variable ... -> New) to set the changing path on each system (e.g. FOO_BAR_HOME).
Than you can add the Variable to the Libraries and edit it to point to your library, like
%FOO_BAR_HOME%/lib/foobar.jar
Take a look at the existing variables for usage.
Alternative you can place the library inside the project (e.g. subfolder 'lib'). If you add the library from this location ('Add Jars...' NOT 'Add External Jars...') it will be added by relative path.
Hey I was having this issue as well, but I can offer an alternate solution for those who want to keep the required library locally but outside the directory of the Java Project.
First, add the library you want using the usual "Add External Library/Jar" method.
If you go into the home directory of your Java Project, you should see a .classpath file. Edit this with any text editor you wish, and look for the line that references the library you added. Then, say your library is called lib.jar and you have it one level outside of your project.
Lets say the line says:
<classpathentry kind="lib" path="C:/Users/Public/workspace/lib.jar"/>
Rather than moving lib.jar to your Project's directory, you can just change this line to say:
<classpathentry kind="lib" path="./../lib.jar"/>
and your Java Build path will be updated to look for it in the directory one level above the current project.
Also, to my knowledge if you're running a Mac or any Unix based OS, then the .classpath file will be hidden. In order to access it, you can try opening it from Terminal, by navigating to the directory that your Java Project uses (the actual project folder itself, not the workspace), then either vi or vim ".classpath". Keep in mind that using ls or even ls -a might not work, but trust that it will be there.
Once you've changed it to the specified location, save the file and when you go back into eclipse, the reference should still be working. Keep in mind that the "./" at the beginning is necessary. Just having "../" will not work, or at least it didn't for me.
I did it very simple. I had a lib with an absolute path in my classpath:
/home/glauco/workspace/ltClubs/lib/swingx-core-1.6.2.jar
So i just removed the absolute path from it and it works. Now it's relative xD:
lib/swingx-core-1.6.2.jar
This should be a comment on the previous answer, but the strange reputation system from this site forces me to post a new answer instead... (no comments)
You can use a relative path, but you're missing the './' in it.
Instead of
lib/swingx-core-1.6.2.jar
you should use
./lib/swingx-core-1.6.2.jar
Add the folder containing the dependencies into the JAVA project. Select and right-click the dependencies, "Add to Build Path" pops up as a context menu. This adds the dependencies using relative path instead of the absolute path.