KCL LSP cannot find installed modules
Bug Report
1. Minimal reproduce step (Required)
- setup kcl neovim via mason
kcl mod init && kcl mod add k8s- 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"
}]
}]
}
}
- observe
- also when you drop into neovim terminal - we have kcl in path via mason you can see this:
6) try
nix-shell -p kcl
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
There are a few questions that need to be confirmed.
- Did you execute kcl mod init && kcl mod add k8s first or import k8s.api.apps.v1 as k8sapps in main.k?
- Can you solve it by executing kcl mod init && kcl mod add k8s and restarting nvim?
- Does it only appear in nvim? I tried it in vscode and there was no problem. I will test it again in nvim later.
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" }
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.
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.
Oh that's good to know! I'll give that a go tomorrow
@vlada-dudr That's got it for me. Appreciate it!
This may be related to the versions of kcl-language-server and kcl. Please keep them both the latest version before testing.
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.
@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