Visual Studio Code clangd extension configuration - visual-studio-code

I am trying to integrate clangd with VS Code using vscode-clangd extension, but I am having problem with configuring include paths...
I created additional config in VS Code settings:
"clangd.path": "path_to_clangd/bin/clangd",
"clangd.arguments": [
"-compile-commands-dir=path_to_commands/compile_commands.json"
]
but the extension reports lots of missing includes errors.
I have also tried:
"-compile-commands-dir=path_to_commands"
but this also didn't work.
Does anyone knows how to configure this extension at all? I am unable to find any documentation at this point.
Regards

Your path should be directory to compile_commands.json, not file, and you need to restart the clangd by the vscode-clangd extension
settings.json
{
"cmake.buildDirectory": "${workspaceFolder}/debug",
"clangd.arguments": [
"-background-index",
"-compile-commands-dir=debug"
],
}
Restart
change a bit of .clang-tidy file under your project root directory, if no, create one with something
the vscode-clangd will prompt you to restart the clangd
check the clangd process, it should something similar to
❯ ps -Af | grep clangd
awei 285478 282126 0 10:42 ? 00:00:03 /opt/llvm-10.0.0/bin/clangd -background-index -compile-commands-dir=debug

This is my answer, it works:
"clangd.path": "/Users/jiewang/Library/Application Support/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/11.0.0/clangd_11.0.0/bin/clangd",
"clangd.arguments": [
"--compile-commands-dir=${workspaceFolder}/build",
"--completion-style=detailed",
"--header-insertion=never"
],

It seems that the compile_commands.json has to be in the Folder root directory for the extension to find it.
I just add a symlink:
ln -s /path-to-build-dir/compile_commands.json /path-to-src-root-dir/

Related

Visual Studio Code clangd Find all references only works for local folder

I have a project with source files in multiple folders. I am using clangd as my language server. I have a single cmake file at the top of my source folder (I actually don't use cmake to build my project, I only use it to generate the compile_commands.json to allow clangd to know the include directories and the other files in the project). My cmake file looks like this:
cmake_minimum_required (VERSION 2.12)
project (Template)
# Generate compile commands database
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
add_library (Template_Lib afw/afw_can_manager.c
afw/can_router.c
afw/can_router_config.c
afw/hw_user.c
afw/VIN_check.c
afw/model_wrapper.c
app_config/output_table.c
model/Model_ert_rtw/Model.c
model/Model_ert_rtw/Model_data.c
constant_data/codegen_source/constant_data.c
application/j1939_data_integrity.c
application/service.c
application/user_interface.c
MTCT/J1939_var.c
MTCT/rtU_rtY.c
MTCT/Rx_gen.c
MTCT/RX_sig.c
MTCT/Tx_gen.c
MTCT/DM1_table.c
MTCT/nvam_config.c)
target_include_directories (CM2723_Template_Lib PUBLIC pfw
application
app_config
afw
constant_data/codegen_source
model
model/Model_ert_rtw
MTCT)
From the CMakeLists.txt, you can see the project structure. You can also see that there is no other build files in the subdirectory. When opening a file in a subdirectory (e.g. application/user_interface.c), the include files are found in the other directories so the generated command_compile.json located at the top level of the source directories. But if I try a Find all references for a function, it will find the function references in files located in the same directory but it won't find the ones in other directories (e.g. afw directory).
command_compile.json looks like this (removed paths and replaced with ...):
[
{
"directory": ".../source/build",
"command": "C:\\PROGRA~2\\MIB055~1\\2022\\BUILDT~1\\VC\\Tools\\Llvm\\x64\\bin\\clang.exe -I.../source/pfw -I.../source/application -I.../source/app_config -I.../source/afw -I.../source/constant_data/codegen_source -I.../source/model -I.../source/model/Model_ert_rtw -I.../source/MTCT -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -o CMakeFiles\\Template_Lib.dir\\afw\\afw_can_manager.c.obj -c ...\\source\\afw\\afw_can_manager.c",
"file": "...\\source\\afw\\afw_can_manager.c"
},
{
"directory": ".../source/build",
"command": "C:\\PROGRA~2\\MIB055~1\\2022\\BUILDT~1\\VC\\Tools\\Llvm\\x64\\bin\\clang.exe -I.../source/pfw -I.../source/application -I.../source/app_config -I.../source/afw -I.../source/constant_data/codegen_source -I.../source/model -I.../source/model/Model_ert_rtw -I.../source/MTCT -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -o CMakeFiles\\Template_Lib.dir\\afw\\can_router.c.obj -c ...\\source\\afw\\can_router.c",
"file": "...\\source\\afw\\can_router.c"
},
...
]
As an example, when looking for all the references to the function application_specific_initialize from the file application/user_interface.c, I get:
But when I search for the function name as a string, it is also found in afw/model_wrapper.c which is a valid function call but in a different folder (disregard the wrong matches):
To include the other directories in the search, add their absolute paths (${workspaceFolder} is a predefined variable in VS Code) to either your user (ctrl+,) or workspace (.vscode/settings.json) settings via clangd.fallbackFlags:
{
"clangd.fallbackFlags": [
"-I",
"${workspaceFolder}/afw",
// etc...
]
}
Then restart the clangd language server.

"liveSass.command.watchMySass not found" and "Extension host terminated unexpectedly” in vs code on windows 10

Problem
"liveSass.command.watchMySass not found" and "Extension host terminated unexpectedly” in vs code on windows 10 while using live-sass-compiler extension.
Failed attempts:
manually deleted the extension from the .vscode folder and reinstalled it as per #219
[Antivirus/defender] tried excluding the extensionHostProcess.js file at C:\Users\ (user file name e.g- hp...etc) \AppData\Local\Programs\Microsoft VSCode\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js as per #94858
Disabled all extensions and tried running as per #94807
Tried restoring quarantined files from antivirus/defender
Tried all the aforementioned steps again after reinstalling vs code.
downloaded vscode - January 2020 (version 1.42) build as per https://stackoverflow.com/a/61133333/11045279
Error log
c:\Users\ADITYA\.vscode\extensions\ritwickdey.live-sass-3.0.0\node_modules\sasslib\sass.sync.js:61
var Module=typeof Module!=="undefined"?Module:{};var moduleOverrides={};var key;
for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}
Module["arguments"]=[];
Module["thisProgram"]="./this.program";
Module["quit"]=(function(status,toThrow){throw toThrow});Module["preRun"]=[];Module["postRun"]=[];
var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;
var ENVIRONMENT_IS_SHELL=false;
if(Module["ENVIRONMENT"]){if(Module["ENVIRONMENT"]==="WEB"){ENVIRONMENT_IS_WEB=true}
else if(Module["ENVIRONMENT"]==="WORKER"){ENVIRONMENT_IS_WORKER=true}
else if(Module["ENVIRONMENT"]==="NODE"){ENVIRONMENT_IS_NODE=true}
else if(Module["ENVIRONMENT"]==="SHELL"){ENVIRONMENT_IS_SHELL=true}
else{throw new Error("Module['ENVIRONMENT'] value is not valid. must be one
of: WEB|WORKER|NODE|SHELL.")}}else{ENVIRONMENT_IS_WEB=typeof
window==="object";ENVIRONMENT_IS_WORKER=typeof importSc
Error: Import "node_modules/bootstrap/scss/bootstrap" could not be resolved.
at File.load (D:\Projects\vscode-ext-color-highlight\node_modules\file-importer\index.js:130:1)
at D:\Projects\vscode-ext-color-highlight\node_modules\file-importer\index.js:136:1
at FSReqCallback.oncomplete (fs.js:165:21)
abstractExtensionService.ts:155 Extension host terminated unexpectedly. Code: 7 Signal: null
Thanks.
Here's the fix so you don't have the nightmare I've been having.
Uninstall live sass and close VScode.
For Windows, type the following into file explorer:
%USERPROFILE%.vscode\extensions
Then delete the folder for live sass. Should be called something like:
ritwickdey.live-sass-3.0.0
Open VScode, reinstall live sass.
Done
The problem that's not about installation problem, that's need to open VS Code editor and then create new file with SCSS format. For example, style.scss, and please wait for second and then you see watch sass in below of vscode.

Error with static compilation Qt with postgresql driver

I have installed through Mainteinance Tool Qt 5.12.5 and the sources. I have the next directories:
C:\Qt\5.12.5\Src
C:\Qt\Tools\mingw730_32\
C:\Qt\Tools\mingw730_64\
On the other hand, I have read that downloable Postgres version is compiled with MSVC, and I must to compile my own version. I have do it following link, and now I have a postgresql version in c:\pgsql
Finally I have added c:\pgsql to user Path
Next step, I have opened PowerShell in Admin mode and I´ve gone to C:\Qt\5.12.5\Src\.
Next, set the env path for this PowerShell session:
$env:Path += ";C:\Qt\Tools\mingw730_64\bin\;C:\Qt\5.12.5\Src;C:\pgsql\include\;C:\pgsql\lib\;C:\pgsql\bin\" (setting the pgsql path again....)
After that, I execute configure.bat like that:
configure -v -static -release -static-runtime -platform win32-g++ -prefix C:\Qt\5.12.5\Estatico\ -opensource -confirm-license -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -no-openssl -opensource -confirm-license -skip webengine -make libs -nomake tools -nomake examples -nomake tests -sql-psql
But I have get this error:
ERROR: Feature 'sql-psql' was enabled, but the pre-condition 'libs.psql' failed.
Searching in config.log I can read those lines:
loaded result for library config.qtbase_sqldrivers.libraries.psql
Trying source 0 (type pkgConfig) of library psql ...
pkg-config use disabled globally.
=> source produced no result.
Trying source 1 (type psqlConfig) of library psql ...
pg_config not found.
=> source produced no result.
Trying source 2 (type psqlEnv) of library psql ...
None of [liblibpq.dll.a liblibpq.a libpq.dll.a libpq.a libpq.lib] found in [] and global paths.
=> source produced no result.
Trying source 3 (type psqlEnv) of library psql ...
=> source failed condition '!config.win32'.
test config.qtbase_sqldrivers.libraries.psql FAILED
What can I do or what is the properly way to do that?
Thank you in advance.
UPDATE
There are similar question here but it hasn´t been solved, and those question ask about Visual Studio.
I want to compile it under mingw.
The solution suggested by #Soheil Armin doesn´t work too
The solution suggested by #Soheil Armin works fine, but I need to delete the entire source tree and reinstall it as he suggested. If not, a new configure won't work.
Also, the ^ character can be saved:
configure <your parameters>
PSQL_LIBS="C:\pgsql\lib\libpq.a"
-I "C:\pgsql\include"
-L "C:\pgsql\lib"
You need to explicitly define library paths of Postgres.
configure <your parameters> ^
PSQL_LIBS="C:\pgsql\lib\libpq.a" ^
-I "C:\pgsql\include" ^
-L "C:\pgsql\lib"

How do I get flake8 to reliably ignore rules in VS Code?

Two things that annoy me. First is the warning Flake8 gives me when I type more than 80 characters on a line. Second is the warnings I get when I haven't yet used a module name that I imported. I've looked at all the documentation on using Flake8 in the terminal. No use.
flake8 --ignore=E402
flake8 --max-line-length=120
This doesn't work. At least VS Code doesn't show any effect.
Add your arguments to your USER SETTINGS json file like this:
"python.linting.flake8Args": [
"--max-line-length=120",
"--ignore=E402,F841,F401,E302,E305",
],
note that flake8 uses
"python.linting.flake8Args": [
whereas black seems to use:
"python.formatting.blackArgs": [
if you're using both (or toggling) these settings maybe helpful:
{
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"120"
],
"python.linting.flake8Args": [
"--max-line-length=120",
"--ignore=E402",
],
"python.pythonPath": "venv/bin/python"
}
In my case (vscode 1.72.2, flake 5.0.4) it only worked by adding:
"flake8.args": [
"--max-line-length=120"
]
in the settings.json
I prefer editing the Workspace settings, namely <root project folder>/.vscode/settings.json, because I store it in version control. This way it is backed up and everyone working on the project will get it.
What was suggested in most of the other answers:
"python.linting.flake8Args": [
"--max-line-length=120",
],
had no effect for me.
I ran into this problem recently. I ran into problems because I was setting the argument to --config flake8.cfg instead of --config=flake8.cfg. Under the hood, vscode puts the CLI argument in quotes. Adding "--config flake8.cfg" to the flake8 command seems to confuse flake8 into thinking that it's looking at a file path and not a CLI argument.
The solution for me was to either set the args as --config=flake8.cfg (with the equals sign) or the args up into separate items in the array:
"python.linting.flake8Args": [
"--config",
"flake8.cfg"
]
The solution proposed by reka18 is great and was no doubt written specifically for the original question.
From a more general stand point, I would advise against using this kind of trick
if you work on a project that has dedicated configuration files.
You are guaranteed to run into incomprehensible configuration conflicts
and will possibly ignore rules that were purposefully enforced by the project.
In this case, you should use the following instead:
assuming the file is named .flake8 and is present at the project's root folder
// .vscode/settings.json
"python.linting.flake8Args": ["--config", ".flake8"],
Using --config .flake8 ensures only this file will be read (See official doc).
So it is important to use this option, even though it is a default value. Otherwise, a custom user configuration in a parent folder could accidentally be used.
To extend (change) the default Flake8 line length I added the following in my VS Code workspace: project.code-workspace:
{
...
"settings": {
"flake8.args": [
"--max-line-length=120",
]
}
}

fuseki load graph - s-put not found

I am trying to load a graph in fuseki. The server is working as it should.
But when I try s-put inside the fuseki folder it tells me s-put is not found?!
hdeus$ ls
DEPENDENCIES config.ttl s-delete
Data fuseki s-get
LICENSE fuseki-server s-head
NOTICE fuseki-server.bat s-post
ReleaseNotes.txt fuseki-server.jar s-put
config-examples.ttl fuseki_config.ttl s-query
config-inf-tdb.ttl log4j.properties s-update
config-tdb.ttl pages s-update-form
hdeus$ sudo ./s-put http://localhost:3030/ds/data default Data/books.ttl
sudo: ./s-put: command not found
Any idea what the problem might be? I tried copy/paste s-put from the ls output but stil nothing... I am working in mac os X
Is the file executable? If you unpacked from the zip file, you need to set the s-* executable. Also, you need ruby installed.