clangd for vscode with multiple build directories - visual-studio-code

I am trying to use clangd for code completion within vscode. I am using CMake for the project setup and I am creating a compilation database. However, I have several build directories with different flags (Debug, Release...) and clangd requires to have the compilation database in the source directory. This is not possible, since compilation databases for each build type are different...
Is there any way to use clangd when you have multiple build types?

I solved this my using a VSCode cmake tools feature.
in the settings of my workspace I added
"cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json"
This copies the compile_commands.json of the build dir to workspace folder, which in my case happens to be where clangd is looking for the compile_commands.json file.
If I change the preset, the new compile_commands.json from the new is copied again so the clangd model is updated.

I typically solve this by symlinking one compilation database into the source directory. Which one depends on what I do - mostly it is the one for the "standard" build I use most often. There are other specialized builds, but I only switch to the corresponding compdb if I really need the different settings.

Related

how to configure sonarlint in VScode for C language?

I'm practising clean code and I installed sonarlint as a static testing tool to help me write clean code. after installing the editor rises this notification
SonarLint is unable to analyze C and C++ file(s) because there is no configured compilation
database.
after some searching, I found that I should add a file with a name
compile_commands.json.
this file should be exported automatically by cmake after adding this option
CMAKE_EXPORT_COMPILE_COMMANDS
where can I add this option in VScode.
this link is where the vscode redirected me to creat the required .json file
I am assuming that you are using CMake for your build. If that is the case then add the following line to the CMakeLists.txt
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Then build the project and the database will be created for you.

Eclipse CDT, stop auto find

I've recently been trying to setup a little toolchain for something with Eclipse CDT but I'm being driven insane by the default behaviors of Eclipse. It's just so against the grain of other IDEs for C/C++.
Is there anyway to disable the automatic searching of folders in the project directory for the source files? I want to manually add the files for it to compile instead of having to manually exclude all the files I don't want it to compile between multiple configurations.
you can use your own makefile instead on relying on the eclipse auto generated makefile

Should the .gradle folder be added to version control?

Gradle creates a folder called .gradle. Should I track it with my version control (i.e. git)?
More importantly, why / why not?
Should I track the .gradle directory?
No. It can safely be ignored.
Why should I ignore it?
It's purely for caching information, you don't want it in your repo because:
it can get big and be full of binary files
there can be machine specific data in there
there's a lot of churn in there (you'd be constantly committing changes to files in there)
everything in there can be completely re-generated whenever it is needed anyway
It's basically a temp directory that Gradle is dropping in the middle of your source code (why Gradle thinks that's an appropriate thing to do is a different question).
You can tell the "cache directory" nature of the directory by the name of the switch that lets you change where it goes: "--project-cache-dir".
Though I hate having binary files in my source tree, I usually just end up adding the directory to my ignore file because somewhere along the line I'll forget to use the switch from some command line or from my IDE or something and then end up having to deal with the directory anyway.
How do I ignore it?
Git users can add a line with just .gradle to the .gitgnore file and Git will ignore all files in any directory with that name.
Mercurial users will want to look up the .hgignore file.
For other version control systems, refer to the documentation - they all have a feature to support this.
The .gradle folder contains different calculated information about your gradle build (e.g. cached outputs/input information). You definitely shouldn't check that folder into your version control system.
I was new to Gradle and thought that the .gradle folder will contain generic information such as dependency mappings, etc and uploaded it on version control. I then tried setting up a new machine with a different OS flavor and Java version using code from the version control including the .gradle folder and ran into errors. Turned out that the .gradle folder contains machine specific information and is used for caching on local.
Do not include the .gradle folder in version control and try setting up a new machine with the code, the gradle daemon will do the rest.
You don't need to keep the .gradle folder.
Because once you execute gradle build command again, you can make almost the same .gradle folder again.
But when you use the gradle.setting file under .gradle you might need to move it to root folder of the project.
when we start the gradle it create the .gradle folder inside your home directory. It consist of native (information about your system) and caches. Caches further consist of plugins and all other jars dependencies.
When we build the the project first time at that time it download dependencies and plugins and cheched them here. next time when we need them it, it get from here. even when we need them in eclipse to compile the code (=>gradle eclipse), its dependencies are added from cache
As it will keep updating and adding when you run gradle. so i guess we do not added it to version control.

Eclipse showing lots of unrelated files in project explorer

I'm new to Eclipse, having done a lot of development in Visual Studio and XCode.
When I create a C++ project in my source tree the project explorer shows all the files in that folder and sub-folders. However there are lots of unrelated files that I don't want to see.
In Visual Studio and XCode I have to manually link source code to the project. This allows me to control the clutter of the project. Non-project files are "hidden" by default, because they aren't added to the project. In Eclipse everything is added by default. It seems that you can't decouple the file system's storage from the view you see in the project explorer.
Also I have a bunch of source in my tree that I don't want to compile as part of this project. Because it's for a different platform. I can't see how to remove these files from the compile list without also removing them from the file system.
Reading the docs hasn't helped much. What am I missing here?
There are 2 parts to this solution. First file name filters can be defined as described in this post:
Eclipse: how to hide custom files in Project Explorer
2nd the remaining files that I don't want compiled can be excluded by right clicking on them and Properties -> C++ build -> Exclude resource from build.
So it's more a negative space thing. In traditional systems, you have to explicitly add code to the project. In Eclipse you have to explicitly REMOVE code from the project. I prefer the old way because sometimes you want to include code from disparate regions on the disk and that just makes the all inclusive model of eclipse break. But I guess I'll cross that bridge when I get to it. sigh

Why is eclipse trying to compile files not in my build path?

I have a rather large project which contains a number of third-party dependencies which are linked via svn:externals. These include tomcat and blazeDS, which are packaged by our installer via ant. The problem is that these projects contain dozens of sample JSP pages, and eclipse chokes on them when trying to build the project, producing hundreds of errors.
Our project setup is something like this:
src/
main/
test/
third-party/
blazeDS/
tomcat/
etc.
Now, in eclipse, my project's build path is set to only include subfolders in src/main and src/test. Yet, for some reason, it still tries to build everything beneath third-party. I have clicked on third-party and selected "remove from build path", but this had no effect. I even tried adding the third-party folder to the build path, and then excluding "", "/*", and "**/*.jsp", but again, to no effect.
What is going on here?
Edit: Thanks for the suggestions, though unfortunately, they don't seem to fix the issue. I don't have the CheckStyle plugin installed (I'm using Eclipse 3.4.1 with the only custom plugins being subclipse and flex builder), and I tried disabling all extra builders except for Java, but the errors are still being thrown.
I usually have this kind of issue with CheckStyle plugin, where you need to specify in its properties (right-click on project -> Properties -> CheckStyle):
"Exclude from check Files non located in a source directory"
Otherwise it does analyze (and reports warning/errors on) files which are not candidate to be compiled in the first place.
Couple of other suggestions:
try restarting your eclipse with the -clean option (eclipse software version of 'did you reboot it ?' ;) ). Beware it can reset your workspace perspectives, so you may want to try that with a copy of your workspace instead.
try deleting your project (your workspace reference of your project, not its actual content), and reimporting it (beware of your custom launchers, they may get removed in the process).
check if you do not have any linked directory within src or test, which would point to thirdparty(/**): that would explain the unwanted compilation.
It could be that your eclipse project is configured to have extra Builders. You can check that in the project's properties (right-click on project -> Properties -> Builders).
In my case it was because there was a reference to the file (which I had excluded from the build path) in another file which was in the build path. I wanted to exclude SegModel.hpp from the build path, but in another file, I had specified template short K::KEstimate<SegModel>(SegModel& m, short stepCode);