Skip to content

Cannot get completion result for local JAR file dependency in project workspace #142

@CeruleanW

Description

@CeruleanW

Environment

System: macOS
Java Version: 21.0.5 (Eclipse Adoptium 21.0.5+11-LTS)
Gradle Version: 8.14
Kotlin Version: 2.0.21

Description

I am working on a project uses JAR files compiled by other projects. I tried to create a workspace.json to declare that JAR dependency. But it cannot return completions for classes in that JAR files, when completion feature is still working for classes defined in the source code main file. Could you please help to resolve this issue?

Two approaches were used, and produced the same behavior:

  1. Using the 2.3.20-Beta1 version of kotlin-compiler-server, run completions/bootRun task with Gradle, and run the release of kotlin-lsp. Once were connected, send a request as:
curl 'http://localhost:8082/api/compiler/complete?line=25&ch=7' \
 -H 'Content-Type: application/json' \
 -H 'info-text: i am a default settings header' \
 --data-raw '{
  "args": "",
  "files": [
    {
      "name": "File.kt",
      "text": "package com.helloworld.example\n\nimport org.example.HelloWorld\n\nclass HelloWorld2 {\n    /**\n     * hello world!\n     */\n    fun helloWorld() {\n        println(\"Hello world 2!\")\n    }\n\n    fun testFn(): String {\n        return \"This is for testing only\"\n    }\n}\n\nfun main() {\n    val name = \"Kotlin\"\n    //TIP Press <shortcut actionId=\"ShowIntentionActions\"/> with your caret at the highlighted text\n    // to see how IntelliJ IDEA suggests fixing it.\n    println(\"Hello, \" + name + \"!\")\n\n    val h2 = HelloWorld2()\n    val h1 = HelloWorld()\n    h1.\n}",
      "publicId": ""
    }
  ],
  "confType": "java"
}'

The response contains only an empty array.

  1. Using VS code to load the project and install VSIX extension, it failed to provide references for the function defined in the local JAR file:
Image

Kotlin LSP Logs

When running kotlin-lsp via kotlin-lsp.sh in #1, it shows log as below:

2026-01-21 12:35:18,684 [     23]   INFO - #c.j.l.i.LspClient - Server is listening on /127.0.0.1:9999
2026-01-21 12:35:19,796 [   1135]   INFO - #c.j.l.i.LspClient - A new client connected at /127.0.0.1:56535
2026-01-21 12:35:19,925 [      0] WARNING - #c.i.o.u.r.RegistryValue - Attempt to load key 'ide.new.project.model.index.case.sensitivity' for not yet loaded registry
2026-01-21 12:35:19,934 [      9] WARNING - #c.i.o.u.r.RegistryValue - Attempt to load key 'ide.workspace.model.assertions.bridges.usage' for not yet loaded registry
2026-01-21 12:35:19,937 [      1]   INFO - #c.i.p.d.t.TelemetryManager - Loaded telemetry tracer service com.intellij.platform.diagnostic.telemetry.NoopTelemetryManager
2026-01-21 12:35:19,944 [     19] WARNING - #c.i.o.u.r.RegistryValue - Attempt to load key 'ide.new.project.model.index.case.sensitivity' for not yet loaded registry
2026-01-21 12:35:20,562 [      2]   INFO - #c.i.o.u.LowMemoryWatcherManager - Use ExponentiallySmoothingTracker(90000 ms)
2026-01-21 12:35:20,566 [      6]   INFO - #c.i.o.u.LowMemoryWatcherManager - Subscribing to MemoryPool[G1 Old Gen]{max: 8589934592, threshold: 8160437760 (0.95 * max)}
2026-01-21 12:35:20,567 [      7]   INFO - #c.i.o.u.LowMemoryWatcherManager - Schedule GC-time updating: each 15000ms
2026-01-21 12:35:20,679 [     61]   INFO - initialize - Got `initialize` request from unknown
params:
{
    "capabilities": {
        "workspace": {
            "workspaceFolders": true
        },
        "textDocument": {
            "completion": {
                "completionItem": {
                    "snippetSupport": true
                },
                "contextSupport": true
            }
        }
    },
    "workspaceFolders": [
        {
            "uri": "file:///Users/ayang3/code/calamansi-components/kotlin-lsp/test-workspace3/",
            "name": "kotlin-compiler-server"
        }
    ]
}
2026-01-21 12:35:20,683 [   2113]   INFO - #c.j.l.s.a.i.c.LSServerAnalyzerImplKt - Indices storage path: /Users/ayang3/Library/Application Support/JetBrains/analyzer/workspaces/ce2cfcadfd620b109de5ceae78db433e.mv.db
2026-01-21 12:35:20,704 [     86]   INFO - initialize - Trying to import using JsonWorkspaceImporter
2026-01-21 12:35:20,705 [     21]   INFO - #c.j.l.s.a.i.c.MVSKt - Opened MVStore /Users/ayang3/Library/Application Support/JetBrains/analyzer/workspaces/ce2cfcadfd620b109de5ceae78db433e.mv.db
2026-01-21 12:35:20,968 [      4]   INFO - #c.i.w.i.i.GlobalWorkspaceModel - Project analyzer project is added to the list of initializing and open projects
2026-01-21 12:35:20,970 [      0]   INFO - #c.i.w.i.i.l.m.ModuleBridgeLoaderService - Workspace model loaded from cache.
2026-01-21 12:35:20,985 [    379]   INFO - #c.i.w.i.i.l.l.ProjectLibraryTableBridgeImpl - Initial load of project-level (project=analyzer project) libraries. There are 1 libraries to load.
2026-01-21 12:35:20,985 [    379]   INFO - #c.i.w.i.i.l.l.ProjectLibraryTableBridgeImpl - Applying project-level (project=analyzer project) libraries directly to project WSM.
2026-01-21 12:35:21,003 [    424]   INFO - #c.i.w.i.i.WorkspaceModelImpl - Project model for project analyzer project updated to version 3 in 12 ms: Sync global entities with project: analyzer project
2026-01-21 12:35:21,040 [     76]   INFO - #c.i.w.i.i.GlobalWorkspaceModel - Project analyzer project is removed from the list of initializing and open projects. Project was disposed.
2026-01-21 12:35:22,204 [   1481]   INFO - #c.j.l.s.a.i.c.IndexerKt - Scanning workspace by 6 workers took 1110 ms
2026-01-21 12:35:22,219 [   1601]   INFO - initialize - InitializeResult:
{
    "capabilities": {
        "textDocumentSync": 2,
        "completionProvider": {
            "triggerCharacters": [
                "."
            ],
            "resolveProvider": true
        },
        "hoverProvider": true,
        "signatureHelpProvider": {
            "triggerCharacters": [
                "(",
                ","
            ],
            "retriggerCharacters": [
                ","
            ],
            "workDoneProgress": false
        },
        "definitionProvider": true,
        "referencesProvider": true,
        "documentSymbolProvider": true,
        "codeActionProvider": {
            "codeActionKinds": [
                "source.organizeImports",
                "quickfix"
            ],
            "resolveProvider": false,
            "workDoneProgress": false
        },
        "documentFormattingProvider": true,
        "renameProvider": true,
        "executeCommandProvider": {
            "commands": [
                "decompile",
                "exportWorkspace",
                "applyModCommand",
                "kotlin.organize.imports",
                "jetbrains.kotlin.completion.apply"
            ]
        },
        "semanticTokensProvider": {
            "legend": {
                "tokenTypes": [
                    "namespace",
                    "class",
                    "enum",
                    "interface",
                    "struct",
                    "typeParameter",
                    "type",
                    "parameter",
                    "variable",
                    "property",
                    "enumMember",
                    "event",
                    "function",
                    "method",
                    "macro",
                    "keyword",
                    "modifier",
                    "comment",
                    "string",
                    "number",
                    "regexp",
                    "operator",
                    "decorator"
                ],
                "tokenModifiers": [
                    "declaration",
                    "definition",
                    "readonly",
                    "static",
                    "deprecated",
                    "abstract",
                    "async",
                    "modification",
                    "documentation",
                    "defaultLibrary"
                ]
            },
            "range": true,
            "full": true
        },
        "inlayHintProvider": {
            "resolveProvider": true
        },
        "diagnosticProvider": {
            "interFileDependencies": true,
            "workspaceDiagnostics": false,
            "workDoneProgress": false
        },
        "workspaceSymbolProvider": {
            "resolveProvider": false,
            "workDoneProgress": true
        },
        "workspace": {
            "workspaceFolders": {
                "supported": true,
                "changeNotifications": true
            }
        }
    },
    "serverInfo": {
        "name": "Kotlin LSP by JetBrains",
        "version": "0.1"
    }
}

Expected Behavior

Returning a non-empty array similar as:

[
  {
    "text": "sayHello()",
    "displayText": "helloWorld()",
    "tail": "Unit",
    "icon": "method"
  },
  {
    "text": "saySomthingElse()",
    "displayText": "testFn()",
    "tail": "String",
    "icon": "method"
  },
  {
    "text": "equals(",
    "displayText": "equals(other: Any?)",
    "tail": "Boolean"
  },
  {
    "text": "hashCode()",
    "displayText": "hashCode()",
    "tail": "Int",
    "icon": "method"
  },
  {
    "text": "toString()",
    "displayText": "toString()",
    "tail": "String",
    "icon": "method"
  }
]

Actual Behavior

Returning an empty array.

Additional Context

In the workspace.json file, the JAR file location is declared as a absolute path. File exists in that path. I hope its format is correct but have no documentation to follow.

Attached is the whole workspace test-workspace3.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions