CodeQL in VSCode - solving a common problem
CodeQL, GitHub’s SAST engine, has a great VSCode extension to help you write queries.
One of the most common problems using it is that the extension can’t find the CodeQL libraries.
Solving this is pretty easy, but sometimes I forget what the problem is (as I did last night), so I’m dropping the error message here with the solution.
The error
The error you’ll see is something like this (where I’ve replaced the real user path with ~
for this example):
Resolving qlpack information using CodeQL CLI: resolve qlpacks -v --log-to-stderr --format json --additional-packs ~/...
CLI command succeeded.
[2023-11-07 16:52:05] [INCOMPATIBILITY] legacy-upgrades: not 0.0.0 {root: legacy-upgrades@0.0.0}
[2023-11-07 16:52:05] [DERIVATION] legacy-upgrades: 0.0.0 {legacy-upgrades: not 0.0.0 {root: legacy-upgrades@0.0.0}}
[2023-11-07 16:52:05] [DECISION 1] legacy-upgrades: 0.0.0
Could not find qlpack file for dbscheme semmlecode.javascript.dbscheme (codeQL.viewAstContextEditor)
Error: Could not find qlpack file for dbscheme semmlecode.javascript.dbscheme
at findDbschemePack (~/.vscode/extensions/github.vscode-codeql-1.9.4/out/extension.js:138862:9)
at getQlPackForDbscheme (~/.vscode/extensions/github.vscode-codeql-1.9.4/out/extension.js:138895:24)
at qlpackOfDatabase (~/.vscode/extensions/github.vscode-codeql-1.9.4/out/extension.js:138931:10)
at TemplatePrintAstProvider.getAst (~/.vscode/extensions/github.vscode-codeql-1.9.4/out/extension.js:144479:21)
at CachedOperation.get (~/.vscode/extensions/github.vscode-codeql-1.9.4/out/extension.js:144307:22)
at TemplatePrintAstProvider.provideAst (~/.vscode/extensions/github.vscode-codeql-1.9.4/out/extension.js:144453:52)
at withProgress.cancellable (~/.vscode/extensions/github.vscode-codeql-1.9.4/out/extension.js:160274:19)
The solution
Your VSCode workspace needs to have the CodeQL libraries in it, so that the extension can find them.
They are found on GitHub at github/codeql
. If you clone that, and then add that folder to your VSCode workspace you should be golden; you can check that the checkout is for the same version as your CodeQL CLI binary, to ensure compatibility.
You can also use the VSCode CodeQL starter workspace, which already has the libraries in it.