Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: KCL Extension is not able to see package imports and relative imports beyond repo root (at least for Path based kcl mod add and for Git based too) #64

Open
dd84ai opened this issue Jan 9, 2025 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@dd84ai
Copy link

dd84ai commented Jan 9, 2025

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  • i published Git based package https://github.com/darklab8/infra
  • i have installed wget -q https://kcl-lang.io/script/install-kcl-lsp.sh -O - | /bin/bash
    • kcl-language-server version shows Version: 0.11.0-c020ab3eb4b9179219d6837a57f5d323, Platform: x86_64-unknown-linux-gnu, GitCommit: bc74f86d4af33d0e3591c7dcda748535ab436469
  • i have running vscode 1.96.2 with KCL extension
  • git clone [email protected]:darklab8/fl-darkstat.git
  • kcl mod init
  • i installed infra package in https://github.com/darklab8/fl-darkstat as kcl mod add git://github.com/kcl-lang/konfig --tag v0.4.0
  • i created file fl-darkstat/kcls/workflows/test.k with content
import infra.kcls.github_action as gh
import konfig.models.commons.resource as rs
import yaml

_name = "Install Autogit"

yaml.dump_to_file(gh.GHAction {
    name = _name
    runs = {
        steps = [
            gh.Step {
                name: _name
                shell: "bash"
                run = r"go install github.com/darklab8/autogit/v2@latest"
            }
        ]
    }
}, ".github/workflows/test2.yml", ignore_private=True, ignore_none=True)

schema InstallAutogit(gh.Step):
    name: str = _name
    uses: str = r"darklab8/infra/.github/actions/install-autogit@master"

a = rs.RESOURCE {
    $type = "smth"
}

Screenshot_20250109_021844
import of my own package, and of test package konfig installed via kcl mod add git://github.com/kcl-lang/konfig --tag v0.4.0
and of relative imports, all not recognizing. Red lines in vscode with error pkgpath konfig.models.commons.resource not found in the program(CannotFindModule)

At the same time i am able to build file correctly with command kcl kcls/workflows/test.k

(venv) naa@naa-MS-7C89:~/repos/pet_projects/fl-darkstat$ kcl kcls/workflows/test.k
task: [kcl:build] kcl kcls/workflows/test.k

a:
  type: smth

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

i expectex to see syntax colored package imports and recognized type si use from it.

3. What did you see instead (Required)

errors like pkgpath konfig.models.commons.resource not found in the program(CannotFindModule) in all imported packages

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

kcl-language-server version is 0.11.0-c020ab3eb4b9179219d6837a57f5d323
kcl itself is installed by go as go install kcl-lang.io/cli/cmd/kcl@latest, kcl version 0.11.0-linux-amd64

5. Extra info.

Imports at the level of extension look to me working only if u use absolute and relative imports for the code in the same repository.
it is not working only for installed git based packages so far, and for relative imports to go travel further than from root repo.

@dd84ai dd84ai changed the title Bug: KCL Extension is not able to see any imports. Bug: KCL Extension is not able to see package imports and relative imports beyond repo root Jan 9, 2025
@dd84ai
Copy link
Author

dd84ai commented Jan 9, 2025

Same issue persists when i create main.k or any other named file in fl-darkstat repo at any level except root.
fl-darkstat/check/check.k had error
fl-darkstat/main.k does not have importing problems

Also i tried using Path based kcl mod add ../infra, the same issue

@He1pa He1pa self-assigned this Jan 9, 2025
@He1pa He1pa added the bug Something isn't working label Jan 9, 2025
@dd84ai
Copy link
Author

dd84ai commented Jan 9, 2025

fl-darkstat/gh/main.k

import infra.models.smth as smth
import yaml

yaml.encode("smth")

stuff = smth.Check {
    smth = "123"
}

_name = "Install Autogit"

i have initialized fl-darkstat/kcl.mod

[package]
name = "darkstat"
edition = "v0.11.0"
version = "0.0.1"

[dependencies]
infra = { path = "../infra", version = "0.0.1" }

fl-darkstat/kcl.mod.lock

[dependencies]
  [dependencies.infra]
    name = "infra"
    full_name = "infra_0.0.1"
    version = "0.0.1"

repository infra located locally has
infra/models/smth.k


schema Check:
    smth: str

I still get this importing error with Path based kcl mod installing
image

I tried relative paths too
image
all imports work by kcl app (visible in screenshot), but not importable/recongizable by vscode extension

@dd84ai dd84ai changed the title Bug: KCL Extension is not able to see package imports and relative imports beyond repo root Bug: KCL Extension is not able to see package imports and relative imports beyond repo root (at least for Path based kcl mod add and for Git based too) Jan 9, 2025
@dd84ai
Copy link
Author

dd84ai commented Jan 9, 2025

I will note, that vscode extension is able to see things correctly if code is imported by relative or absolute paths within same repository
Screenshot_20250109_033115
The issue is present only for cross repository imports

I tend to open different repositories as

@dd84ai
Copy link
Author

dd84ai commented Jan 9, 2025

As extra information, imported information sometimes appears as almost working
image
i am able sometimes see Type definitions of my Schemas
despite the errors still present for import being present
image

(venv) naa@naa-MS-7C89:~/repos/pet_projects/darkstat$ kcl check/check.k 
description: '123'

console invocation still has all working.

if i move code from darkstat/check/check.k to darkstat/check.k, to root of repo, it right away becomes behaving correctly
Screenshot_20250109_092636

@dd84ai
Copy link
Author

dd84ai commented Jan 9, 2025

Note

Workaround is found

Important discovery. I created for experiment kcl.mod in a subfolder darkstat/check in addition , where my check.k file is.
and added packages from infra repo as ../../infra
And extension was able to see things correctly ^_^
image

Previously i initialized kcl.mod only in the root of repo, darkstat/kcl.mod, and vscode is opened from the same root of repo
So we can assume extension is able to recognize installed packages only for some reason if kcl.mod is located at the same folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants