-
Notifications
You must be signed in to change notification settings - Fork 120
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
[Track] KCL IDE/LSP workspace design #1510
Comments
ref: https://dpe.org/how-your-monorepo-breaks-the-ide/ In Intellij IDEA we have long-standing assumption that one code file belongs to exactly one module and this module is compiled with a specific dependencies and has a specific compiler version and scpecific libiaries |
Designkcl.workReference from gopls's The kcl.work file is line oriented. Each line holds a single directive, made up of a keyword(there is only one keyword
For UserIn single workspaceMost kcl projects may not need kcl.work. They only work in one workspace and manage the directory structure through kpm.
LSP workspace is equal to In addition to In mult-workspace(Konfig)It is almost impossible to maintain the semantic information of hundreds or thousands of workspaces in memory at the same time. Also, in the Konfig repository, users may not care about the code in other projects. Therefore, we need to explicitly use kcl.work to define the active workspace. In the following project structure:
Assuming that user A maintains prog1, he/she can create a
Functions like rename and find_ref will only work in stack prod and test. It is generally inadvisable to commit go.work files into version control systems. Compatibility SolutionsWe recommend to set kcl.work or kcl.mod in the root directory to set up the workspace. But if not, use the directory of edit file. Search for compilation configuration and compilation entry in the current directory according to the following priority
For devChange on server
|
KCL IDE/LSP workspace
Main Problem
KCL's CLI specifies the compilation entry by inputting a file, files list or a configuration file by argument
-Y
But IDE and LSP dont know what to compile and analyze
Cases
Now we are facing several cases
1. Without configuration file
2. kcl.yaml
This pattern appears in the internal, closed-source konfig repository
kcl.yaml
Compile with kcl run -Y kcl.yaml
3.kcl.mod
kcl.mod
Current processing logic
Problem
For case 2 and 3, IDE/LSP will only get the correct project structure when processing
main.k
. But when processingpkg/a.k
, it will be treated as case 1, and pkg will be used as the entry for compile. At this time, the lack of information aboutkcl.mod
andmain.k
will lead to incomplete semantic information, and features such as find_ref and rename will be unavailable.In addition, when we compile with
kcl.mod
as the entry, and then openpkg/a.k
.Aactually, it has been compiled and analyzed. But according to the current logic, it will be recompiled, which will also cause performance loss in IDE.In a workspace, there are multiple entries at the same time. In order to save the status of multiple entries at the same time, LSP will also have performance loss.
#1237
## SolutionLSP set two modes: SingleEntry and MultiEntrySingleEntry: For a standard kpm package(case 3), define kcl.mod in the root directory of the package and use it as the compilation entry and configMultiEntry:Try to findkcl.mod
in the IDE workspaceThere is kcl.mod, does kcl.mod have an entries field?There is an entries field, use the entries field as the compilation entryThere is no entries field, does the workspace have main.k?There is main.k as the compilation entryNo main.k, does the workspace have other kcl files?Yes, use the workspace as the compilation entryNo, the same logic as beforeif not, does the workspace have main.k?There is main.k as the compilation entryNo main.k, does the workspace have other kcl files?Yes, use the workspace as the compilation entryNo, the same logic as beforeThe logic is consistent with previous to be compatible with the konfig repository. New KCL projects are recommended to usekcl.mod
### LSP ChangesPreviously, opened/changed a file -> found compile entry -> compile -> update GlobalStateAfter the change, Start LSP -> found compile entry -> compile -> update GlobalState -> update the GlobalState cache according to the changed file### Impact on lsp cache/incremental compilationIn the previous design, no matter what the case, the changed files are in the main pkg, and the incremental compilation of resolver/advanced_resolver is based on the premise that thechanged files are in the main pkg
.After changing the entry point, it is necessary to reconsider the processing of editing files that are not in the main pkg.For the Parse stage:The cache is a map of filename -> AST. There is no pkg, so no need to updateFor the Resolver stage:Previously, the resolver needed to clear the cache of main_pkg and the affected pkgs. After the change, it is necessary to first query which pkg the file belongs to, analyze the affected pkgs, and clear the cache of these pkgs.For Namer and Advanced Resolver:Update the pkg that was updated in the resolver stage, no changes are requiredKCL/KPM run
KCL/KPM run also has similar logic when executing, and needs to find the compilation entry and config from the input. The relevant implementation is in
https://github.com/kcl-lang/kpm/blob/2c16041e969cd2f7cdaf3af4e4d0cf7d96c67003/pkg/client/run.go#L409
and
There are two kinds of cases related to IDE
This is similar to opening an IDE WorkSpace (but without opening any files), using the current directory(workspace in IDE) as the entry
Ref
Rust Analyzer
Go:
The text was updated successfully, but these errors were encountered: