[Feature] Include script in comment
krisavi opened this issue · 6 comments
Is your feature request related to a problem? Please describe.
My code is including libraries depending on the function. So if I want to have VS Code kOS language server not to nag about errors I have to include something like run once "0:/lib/launch.ks".
and run once "0:/boot/boot.ks".
.
Describe the solution you'd like
It would be nice if I could just do something like // #include lib/launch.ks
as a comment to include functions from this specific file (functionality would work only in editor). In my case there is a function I have, that during boot copies required libraries to the "1:/". kOS language server on the other hand does not seem to like when I put it to run once "1:/launch.ks".
or run once "1:/lib/launch.ks".
If I want to keep the script as it is, then when I should restart the kOS computer, it tries to include them from 0:, which is KSP and not always reachable, that ends up with error. If those includes would be only as a comment in the editor, then I can still make it to load files from the ship hard disk in case of power loss on the ship itself.
Describe alternatives you've considered
I guess other way that could work is if the editor would accept any drive number and still search in correct folder. I know it might cause problems when you forget to actually copy the files to the right folder, so maybe a config option in VS code, so you can turn on or off that kind of functionality. In that case the "0:/lib/launch.ks" and "1:/lib/launch.ks" would both resolve to same folder and load the functions from it.
Additional Comment
Currently while I write code I have the run once code in the header to include the function information, but when I switch to format that goes to ship I strip those lines to save room. Only case I would need to access KSC after launch is to update the libraries, but for that I have specific function that I run while there is connection to KSC to trigger compilation, comparison of file sizes and uploading to conserve as much space as possible on kOS hard drive.
Thanks for the feature request! I definitely think this would be doable and useful! I'm currently in the process of adding configurations to the lints but I can try to tackle this next.
In the meantime a hack that will work to get a similar behavior would be something like this
if false {
runOnce("lib.ks").
}
This essentially takes advantage of the fact the server is to dumb to detect this will never run but will act like lib.ks
was imported.
I found that if false {}
works fine yes as well.
Not sure if it should be closed, as it is still feature request, clicked on the close and comment earlier as my issue itself got fixed.
Thought about improving the PR I made to include the // #include "path"
to include stuff in a way it will not be included in end code in ksp as code I have uses the compile on prelaunch and it strips all the comments.
This is definitely still worthy of a PR. I think it make sense as I doubt the server will be able to determine all the cases where globals are available in the current file.