kcl icon indicating copy to clipboard operation
kcl copied to clipboard

KCL LSP cannot find installed modules

Open vlada-dudr opened this issue 10 months ago • 7 comments

Bug Report

1. Minimal reproduce step (Required)

  1. setup kcl neovim via mason
  2. kcl mod init && kcl mod add k8s
  3. main.k:
import k8s.api.apps.v1 as k8sapps

pod = k8sapps.Deployment {
    metadata.name = "web-app"
    spec = {
        selector = {
            matchLabels = {
                app = "ngx"
            }
        }
        template.spec.containers = [{
            name = "nginx"
            image = "nginx"
            ports = [{
                containerPort = 80
                name = "http"
            }]
        }]
    }
}
  1. observe Image
  2. also when you drop into neovim terminal - we have kcl in path via mason you can see this:

Image 6) try nix-shell -p kcl

Image

2. What did you expect to see? (Required)

no errors with lsp and kclvm_cli - go cli is obviously able to find the modules in ~/.kcl

3. What did you see instead (Required)

module not found error - lsp and kclvm_cli are probably not searching in ~/.kcl for modules

4. What is your KCL components version? (Required)

# nix installed - go cli
[nix-shell:~/devel/kcl]$ kcl --version
kcl version v0.10.0

# mason install rust cli/lsp
~/devel/kcl master* ❯ kcl-language-server --version                     
kcl-language-server Version: 0.11.1-c020ab3eb4b9179219d6837a57f5d323    
Platform: x86_64-unknown-linux-gnu                                      
GitCommit: d8964b29170ba28c98a31b561a2d9525112d1f30                     
~/devel/kcl master* ❯ kcl --version                               
kclvm_cli 0.11.1

vlada-dudr avatar Feb 25 '25 19:02 vlada-dudr

There are a few questions that need to be confirmed.

  1. Did you execute kcl mod init && kcl mod add k8s first or import k8s.api.apps.v1 as k8sapps in main.k?
  2. Can you solve it by executing kcl mod init && kcl mod add k8s and restarting nvim?
  3. Does it only appear in nvim? I tried it in vscode and there was no problem. I will test it again in nvim later.

He1pa avatar Feb 27 '25 02:02 He1pa

I'm running into this as well.

I'm importing CRDs into a temp directory, using kcl import to create kcl types moving those to a project directory and then symlinking the generated types.

my kcl sets the modules to the local path of modules = { "./model"}

❯ tree
.
├── kcl.mod
├── kcl.mod.lock
├── main.k
└── model
    ├── gcp
    │   └── pubsub
    │       ├── v1beta1
    │       │   ├── pubsub_gcp_upbound_io_v1beta1_lite_reservation.k
    │       │   ├── pubsub_gcp_upbound_io_v1beta1_lite_subscription.k
    │       │   ├── pubsub_gcp_upbound_io_v1beta1_lite_topic.k
    │       │   ├── pubsub_gcp_upbound_io_v1beta1_schema.k
    │       │   ├── pubsub_gcp_upbound_io_v1beta1_subscription.k
    │       │   ├── pubsub_gcp_upbound_io_v1beta1_subscription_i_a_m_member.k
    │       │   ├── pubsub_gcp_upbound_io_v1beta1_topic.k
    │       │   └── pubsub_gcp_upbound_io_v1beta1_topic_i_a_m_member.k
    │       └── v1beta2
    │           ├── pubsub_gcp_upbound_io_v1beta2_lite_subscription.k
    │           ├── pubsub_gcp_upbound_io_v1beta2_lite_topic.k
    │           ├── pubsub_gcp_upbound_io_v1beta2_subscription.k
    │           ├── pubsub_gcp_upbound_io_v1beta2_subscription_i_a_m_member.k
    │           ├── pubsub_gcp_upbound_io_v1beta2_topic.k
    │           └── pubsub_gcp_upbound_io_v1beta2_topic_i_a_m_member.k
    ├── k8s
    │   └── apimachinery
    │       └── pkg
    │           └── apis
    │               └── meta
    │                   └── v1
    │                       ├── managed_fields_entry.k
    │                       ├── object_meta.k
    │                       └── owner_reference.k
    └── kcl.mod

[dependencies]
models = { path = "./model" }

Image

running the files works fine.

changing the prefix of the import to 'model' fixes the lsp but results in the compile errors for missing types.

mdaops avatar Mar 08 '25 09:03 mdaops

So I installed vs code to test it out. I had to install kcl language server somewhere myself, so I downloaded it and unpacked just the language server. It works. So I remove nvim Mason installed version and let neovim use the one I had for vscode. It does work also. So direct download works, Mason does not. But what is really weird - they are the same binaries. They have same md5sum. The only difference is how they are launched. Direct download just sits in my bin. With mason it is more complicate: it's own bin has symlink to bash script containing only exec path/to/kclvm/kcl-language-server "$@". So my only idea is that kcl-language-server doesn't like Mason's wrapping.

vlada-dudr avatar Mar 10 '25 20:03 vlada-dudr

Oh that's good to know! I'll give that a go tomorrow

mdaops avatar Mar 11 '25 21:03 mdaops

@vlada-dudr That's got it for me. Appreciate it!

mdaops avatar Mar 12 '25 09:03 mdaops

This may be related to the versions of kcl-language-server and kcl. Please keep them both the latest version before testing.

Peefy avatar Mar 12 '25 15:03 Peefy

As i stated earlier the problem seems to be Mason's wrapping - same version of kcl-language server works when launched directly, and doesn't when launched through Mason wrapping.

vlada-dudr avatar Mar 12 '25 16:03 vlada-dudr

@Peefy @He1pa I have the exact same issue with mason here, I'd manually use kcl instead, please let me know if it may be update

polo871209 avatar Dec 23 '25 08:12 polo871209