Skip to content

Extension cannot resolve modules in custom queries #4230

Description

@Ryvian

Describe the bug

In a custom query, the extension seems to fail to import libraries, causing all imports are highlighted in error with message like could not resolve module java.

Image

Version

CodeQL extension version: 1.17.7 CodeQL CLI version: 2.23.7 Platform: linux x64

vscode version:

Version: 1.106.3 (user setup)
Commit: bf9252a2fb45be6893dd8870c0bf37e2e1766d61
Date: 2025-11-25T22:28:18.024Z
Electron: 37.7.0
ElectronBuildId: 12781156
Chromium: 138.0.7204.251
Node.js: 22.20.0
V8: 13.8.258.32-electron.0
OS: Windows_NT x64 10.0.26200

My vscode is on windows 11, and the .ql file is on WSL2 linux.

To reproduce

  1. create a directory: ql-queries . cd to the directory

  2. create a file qlpack.yml with content:

      name: ql-queries
      version: 1.0.0
      dependencies:
        codeql/java-queries: ^1.10.2
    
  3. run codeql pack install

  4. create a file query.ql with content:

    /**
     * @name aaa
     * @description Finds xxx
     * @kind path-problem
     * @problem.severity error
     * @id java/custom/xxx
     */
    
    import java
    import semmle.code.java.dataflow.DataFlow
    import semmle.code.java.dataflow.TaintTracking
    import semmle.code.java.Expr 
    import semmle.code.java.Member
    

Expected behavior
The extension reports no error and can import the modules.

Additional context
codeql is installed on WSL2 linux from the released bundle. codeql resolve packs returns:

Searching directories specified by `--additional-packs`. All directories have equal priority.
  Searching in:
    No packs were found at this location.
Searching directories specified by `--search-path`. Directories are searched in order.
Searching the root of the CodeQL distribution.
  Searching in:
      /home/me/software/codeql
    The following packs were found:
      codeql/actions-all@0.4.22: (library) /home/me/software/codeql/qlpacks/codeql/actions-all/0.4.22/qlpack.yml
      codeql/actions-queries@0.6.14: (query) /home/me/software/codeql/qlpacks/codeql/actions-queries/0.6.14/qlpack.yml
      codeql/concepts@0.0.10: (library) /home/me/software/codeql/qlpacks/codeql/concepts/0.0.10/qlpack.yml
      codeql/controlflow@2.0.20: (library) /home/me/software/codeql/qlpacks/codeql/controlflow/2.0.20/qlpack.yml
      codeql/cpp-all@6.1.1: (library) /home/me/software/codeql/qlpacks/codeql/cpp-all/6.1.1/qlpack.yml
      codeql/cpp-examples@0.0.0: (query) /home/me/software/codeql/qlpacks/codeql/cpp-examples/0.0.0/qlpack.yml
      codeql/cpp-queries@1.5.5: (query) /home/me/software/codeql/qlpacks/codeql/cpp-queries/1.5.5/qlpack.yml
      codeql/csharp-all@5.4.1: (library) /home/me/software/codeql/qlpacks/codeql/csharp-all/5.4.1/qlpack.yml
      codeql/csharp-examples@0.0.0: (query) /home/me/software/codeql/qlpacks/codeql/csharp-examples/0.0.0/qlpack.yml
      codeql/csharp-queries@1.5.1: (query) /home/me/software/codeql/qlpacks/codeql/csharp-queries/1.5.1/qlpack.yml
      codeql/dataflow@2.0.20: (library) /home/me/software/codeql/qlpacks/codeql/dataflow/2.0.20/qlpack.yml
      codeql/go-all@5.0.3: (library) /home/me/software/codeql/qlpacks/codeql/go-all/5.0.3/qlpack.yml
      codeql/go-examples@0.0.0: (query) /home/me/software/codeql/qlpacks/codeql/go-examples/0.0.0/qlpack.yml
      codeql/go-queries@1.5.0: (query) /home/me/software/codeql/qlpacks/codeql/go-queries/1.5.0/qlpack.yml
      codeql/java-all@7.8.0: (library) /home/me/software/codeql/qlpacks/codeql/java-all/7.8.0/qlpack.yml
      codeql/java-examples@0.0.0: (query) /home/me/software/codeql/qlpacks/codeql/java-examples/0.0.0/qlpack.yml
      codeql/java-queries@1.10.1: (query) /home/me/software/codeql/qlpacks/codeql/java-queries/1.10.1/qlpack.yml
      codeql/javascript-all@2.6.16: (library) /home/me/software/codeql/qlpacks/codeql/javascript-all/2.6.16/qlpack.yml
      codeql/javascript-examples@0.0.0: (query) /home/me/software/codeql/qlpacks/codeql/javascript-examples/0.0.0/qlpack.yml
      codeql/javascript-queries@2.2.1: (query) /home/me/software/codeql/qlpacks/codeql/javascript-queries/2.2.1/qlpack.yml
      codeql/mad@1.0.36: (library) /home/me/software/codeql/qlpacks/codeql/mad/1.0.36/qlpack.yml
      codeql/python-all@5.0.1: (library) /home/me/software/codeql/qlpacks/codeql/python-all/5.0.1/qlpack.yml
      codeql/python-examples@0.0.0: (query) /home/me/software/codeql/qlpacks/codeql/python-examples/0.0.0/qlpack.yml
      codeql/python-queries@1.7.1: (query) /home/me/software/codeql/qlpacks/codeql/python-queries/1.7.1/qlpack.yml
      codeql/quantum@0.0.14: (library) /home/me/software/codeql/qlpacks/codeql/quantum/0.0.14/qlpack.yml
      codeql/rangeanalysis@1.0.36: (library) /home/me/software/codeql/qlpacks/codeql/rangeanalysis/1.0.36/qlpack.yml
      codeql/regex@1.0.36: (library) /home/me/software/codeql/qlpacks/codeql/regex/1.0.36/qlpack.yml
      codeql/ruby-all@5.1.4: (library) /home/me/software/codeql/qlpacks/codeql/ruby-all/5.1.4/qlpack.yml
      codeql/ruby-examples@0.0.0: (query) /home/me/software/codeql/qlpacks/codeql/ruby-examples/0.0.0/qlpack.yml
      codeql/ruby-queries@1.5.1: (query) /home/me/software/codeql/qlpacks/codeql/ruby-queries/1.5.1/qlpack.yml
      codeql/rust-all@0.2.0: (library) /home/me/software/codeql/qlpacks/codeql/rust-all/0.2.0/qlpack.yml
      codeql/rust-queries@0.1.21: (query) /home/me/software/codeql/qlpacks/codeql/rust-queries/0.1.21/qlpack.yml
      codeql/ssa@2.0.12: (library) /home/me/software/codeql/qlpacks/codeql/ssa/2.0.12/qlpack.yml
      codeql/suite-helpers@1.0.36: (query) /home/me/software/codeql/qlpacks/codeql/suite-helpers/1.0.36/qlpack.yml
      codeql/swift-all@6.1.1: (library) /home/me/software/codeql/qlpacks/codeql/swift-all/6.1.1/qlpack.yml
      codeql/swift-queries@1.2.10: (query) /home/me/software/codeql/qlpacks/codeql/swift-queries/1.2.10/qlpack.yml
      codeql/threat-models@1.0.36: (library) /home/me/software/codeql/qlpacks/codeql/threat-models/1.0.36/qlpack.yml
      codeql/tutorial@1.0.36: (library) /home/me/software/codeql/qlpacks/codeql/tutorial/1.0.36/qlpack.yml
      codeql/typeflow@1.0.36: (library) /home/me/software/codeql/qlpacks/codeql/typeflow/1.0.36/qlpack.yml
      codeql/typeinference@0.0.17: (library) /home/me/software/codeql/qlpacks/codeql/typeinference/0.0.17/qlpack.yml
      codeql/typetracking@2.0.20: (library) /home/me/software/codeql/qlpacks/codeql/typetracking/2.0.20/qlpack.yml
      codeql/typos@1.0.36: (library) /home/me/software/codeql/qlpacks/codeql/typos/1.0.36/qlpack.yml
      codeql/util@2.0.23: (library) /home/me/software/codeql/qlpacks/codeql/util/2.0.23/qlpack.yml
      codeql/xml@1.0.36: (library) /home/me/software/codeql/qlpacks/codeql/xml/1.0.36/qlpack.yml
      codeql/yaml@1.0.36: (library) /home/me/software/codeql/qlpacks/codeql/yaml/1.0.36/qlpack.yml
      legacy-upgrades@0.0.0: (query) /home/me/software/codeql/legacy-upgrades/qlpack.yml
Searching the parent directory of the CodeQL distribution.
  Searching in:
      /home/me/software
    Some packs were hidden by previously found packs. Use --show-hidden-packs to see them.
Searching the local pack cache. This only applies when searching for a particular version of a pack specified in a lock file.
  Searching in: /home/me/.codeql/packages
  No packs were found at this location.

Activity

  1. nickrolfe commented on Dec 9, 2025

    @nickrolfe
    Contributor

    Hi @Ryvian — you say you are running the CodeQL CLI from WSL. Are you also using the WSL functionality in VS Code (e.g. running "WSL: Connect to WSL" before opening the folder)? If not, then the CodeQL extension's language server will be running using a Windows CLI, and I would not expect that to see or pick up anything under the WSL filesystem.

    To help see what's happening, I suggest opening the Output pane in VS Code, then selecting "CodeQL Language Server" in the dropdown menu, and scrolling to the top. Right at the top, you should be able to see whether it's running a Windows or Linux CLI for the language server.

    A few lines down, you should see a message containing the text

    Creating pack state at .../ql-queries, with library path [...
    

    The listed library paths will show you where it's looking for installed packages.

  2. Ryvian commented on Dec 10, 2025

    @Ryvian
    Author

    Hi @nickrolfe ! Yes I connected vscode to WSL and it seemed CodeQL language server was running on WSL because the Output of "CodeQL Language Server" was

    Starting CodeQL language server using CodeQL CLI: /home/me/.vscode-server/data/User/globalStorage/github.vscode-codeql/distribution1/codeql/codeql execute language-server --check-errors ON_CHANGE -v --log-to-stderr
    CodeQL language server started on PID: 4656
    [2025-12-09 21:51:19] This is codeql execute language-server --check-errors ON_CHANGE -v --log-to-stderr
    [2025-12-09 21:51:19] Stale frontend caches are invalidated based on fine-grained dependency tracking.
    Content-Length: 793
    ......
    

    Do you know what could go wrong? Thank you

  3. nickrolfe commented on Dec 10, 2025

    @nickrolfe
    Contributor

    Thanks — I think we can rule out WSL being the cause of the problem.

    I assume you are using a manually-downloaded CLI bundle when running on the command line, while I can see that the VS Code extension is managing its own CLI installation to use as the language server (/home/me/.vscode-server/data/User/globalStorage/github.vscode-codeql/distribution1/codeql/codeql ). I can suggest a couple of things to try:

    1. Tell the extension to use the same CLI bundle that you ran on the command line, by putting the path to the codeql executable in the codeQL.cli.executablePath setting in the VS Code settings.
    2. Alternatively, try downloading the packs via the extension.
  4. Ryvian commented on Dec 11, 2025

    @Ryvian
    Author

    Thanks! 1 solves the problem. However, the dignostics at the start was OK but after some code edits it became sluggish and failed to load hover messages when the mouse moved over code constructs. The Output of CodeQL language server is

    [Error - 11:31:15 PM] Request textDocument/inlayHint failed.
      Message: Internal error.
      Code: -32603 
    java.util.concurrent.CompletionException: java.lang.OutOfMemoryError: Java heap space
    	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source)
    	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source)
    	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.base/java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.OutOfMemoryError: Java heap space
    	at com.semmle.util.data.MultiMap.<init>(MultiMap.java:92)
    	at com.semmle.util.data.MultiMap.<init>(MultiMap.java:80)
    	at com.semmle.frontend.analysis.binding2.AliasBindingEnvironment.getAllDeclared(AliasBindingEnvironment.java:110)
    	at com.semmle.frontend.analysis.binding2.AllBinder.getAllInternal(AllBinder.java:282)
    	at com.semmle.frontend.analysis.binding2.AllBinder.lambda$new$7(AllBinder.java:62)
    	at com.semmle.frontend.analysis.binding2.AllBinder$$Lambda/0x00000001001b4a40.apply(Unknown Source)
    	at com.semmle.frontend.analysis.binding2.IncrementalBindingCache$CacheImpl.apply(IncrementalBindingCache.java:333)
    	at com.semmle.frontend.analysis.binding2.IncrementalBindingCache$CacheImpl.apply(IncrementalBindingCache.java:283)
    	at com.semmle.frontend.analysis.binding2.AbstractBindingCache$AbstractCacheImpl.get(AbstractBindingCache.java:366)
    	at com.semmle.frontend.analysis.binding2.IncrementalBindingCache$CacheImpl.get(IncrementalBindingCache.java:310)
    	at com.semmle.frontend.analysis.binding2.AllBinder.getAllVisible(AllBinder.java:138)
    	at com.semmle.frontend.analysis.binding2.AllBinder.getAllInternal(AllBinder.java:296)
    	at com.semmle.frontend.analysis.binding2.AllBinder.lambda$new$7(AllBinder.java:62)
    	at com.semmle.frontend.analysis.binding2.AllBinder$$Lambda/0x00000001001b4a40.apply(Unknown Source)
    	at com.semmle.frontend.analysis.binding2.IncrementalBindingCache$CacheImpl.apply(IncrementalBindingCache.java:333)
    	at com.semmle.frontend.analysis.binding2.IncrementalBindingCache$CacheImpl.apply(IncrementalBindingCache.java:283)
    	at com.semmle.frontend.analysis.binding2.AbstractBindingCache$AbstractCacheImpl.get(AbstractBindingCache.java:366)
    	at com.semmle.frontend.analysis.binding2.IncrementalBindingCache$CacheImpl.get(IncrementalBindingCache.java:310)
    	at com.semmle.frontend.analysis.binding2.AllBinder.getAllVisible(AllBinder.java:138)
    	at com.semmle.frontend.analysis.binding2.BindingEnvironment.getAllVisible(BindingEnvironment.java:99)
    	at com.semmle.frontend.analysis.binding2.QLBindingContext2.getAllVisible(QLBindingContext2.java:498)
    	at com.semmle.frontend.analysis.binding2.QLBindingContext2.getVisible(QLBindingContext2.java:511)
    	at com.semmle.frontend.analysis.binding2.PredicateBodyEnv.resolveCallTargetsImpl(PredicateBodyEnv.java:973)
    	at com.semmle.frontend.analysis.binding2.PredicateBodyEnv$$Lambda/0x0000000100209fc8.apply(Unknown Source)
    	at com.semmle.frontend.analysis.binding2.IncrementalBindingCache$CacheImpl.apply(IncrementalBindingCache.java:333)
    	at com.semmle.frontend.analysis.binding2.IncrementalBindingCache$CacheImpl.apply(IncrementalBindingCache.java:283)
    	at com.semmle.frontend.analysis.binding2.AbstractBindingCache$AbstractCacheImpl.get(AbstractBindingCache.java:366)
    	at com.semmle.frontend.analysis.binding2.IncrementalBindingCache$CacheImpl.get(IncrementalBindingCache.java:310)
    	at com.semmle.frontend.analysis.binding2.PredicateBodyEnv.resolveCallTargets(PredicateBodyEnv.java:339)
    	at com.semmle.frontend.ast.Call.getWeakBindings(Call.java:73)
    	at com.semmle.frontend.ast.Call.getStrongBinding(Call.java:78)
    	at com.semmle.frontend.ast.ReferenceExpr.getEntity(ReferenceExpr.java:75)
    
    [2025-12-11 23:31:58] ExternalModuleBindingPass ...
    [2025-12-11 23:31:58] ExternalModuleBindingPass time: 00:00.000
    [2025-12-11 23:31:58] CollectInstantiationsPass ...
    [2025-12-11 23:31:58] CollectInstantiationsPass time: 00:00.000
    [2025-12-11 23:32:07] ExternalModuleBindingPass ...
    [2025-12-11 23:32:07] ExternalModuleBindingPass time: 00:00.000
    [2025-12-11 23:32:07] CollectInstantiationsPass ...
    [2025-12-11 23:32:07] CollectInstantiationsPass time: 00:00.000
    Content-Length: 141
    
    {"jsonrpc":"2.0","id":51,"error":{"code":-32800,"message":"The request (id: 51, method: \u0027textDocument/hover\u0027) has been cancelled"}}
    

    Do you know how to fix it?

  5. nickrolfe commented on Dec 15, 2025

    @nickrolfe
    Contributor

    If you see this happen persistently, I'm afraid it just means the language server needs more memory than it was able to claim (that amount is derived from the total system memory).

    It looks like WSL2 memory is capped at 50% of the host memory by default and I assume the Linux kernel running inside the VM uses some of that. You might want to consider increasing the amount of memory WSL2 is allowed to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    VSCodebugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions