Open arkanoid87 opened 2 years ago
Generating source in a cache just seems like a terrible idea. It's a cache, it can disappear with unknown lifetime.
The complexity of managing an index where live edits are happening to the source data is challenging enough, making that source data further transient or the transient nature of it ambiguous by having mixed use cache... I'm tired even thinking about it.
Unless someone (not it!) put in an incredible amount of work figuring out a reasonable data model and management of IO to support indexing transient data cleanly I wouldn't accept the complexity.
The error is either because:
The Futhark generated nim file is a cache. If not present in cache folder or if outdated is re-generated: https://github.com/PMunch/futhark/blob/875a7f5cf727483bc4c4d394f7d3c23699002aa8/src/futhark.nim#L466 It just exist to speed up things afaik.
Said that, I don't know enough details to say that using a cache folder this way is wrong, but I'd like to know if you think that a library should keep it's own cache for this purpose.
As @arkanoid87 said, the file is a cache file. The macro itself can take quite a long time to generate code, something which would be annoying to have to do every time your rebuild. The cache file also allows editors to see this as a pure import and not time out, allowing them to work at all with Futhark (tested with NimLSP). If the file doesn't exist it is re-generated, or if the user changes anything about the import it also re-generates.
NimLSP doesn't seem to struggle with this, as long as you compile it once so the cache files are built then NimLSP will see them and allow you to follow definitions into the cache file, and get hover information etc.
Not entirely sure what nim check does differently, but it shouldn't be that hard to make it work. In the meantime I guess I could add a flag to Futhark which tells it to look in another folder than the cache folder for its cache files, so that VSCode users will be able to more easily use it.
In the readme are instructions as to how to setup the extension dev environment, the slowest thing about it is likely waiting for downloads, but it's dead simple.
Anyhow, I'd open up a debug version of the extension with some console log statements for the nim check call. Just make sure all the flags you expect are there when nim check is called on the output.
A less convincing way to verify it is what's the command you use to compile your project? If it takes a bunch of flags and those aren't in the config then there not being given to nim check.
@saem the code in first comment replicates the problem in vscode without any config.nims or command line option
just with nim c -r vscodecache.nim
you get working runtime but error in vscode/nim check, and with nim check vscodecache.nim
you get the error I see with vscode extension.
consider that <cache>/vscodecache_d
folder must before running
Implied paths work differently between nim compile and nim check, I found out because I ran into the issue a while back (can't recall more).
I've found this problem while working with Futhark: https://github.com/PMunch/futhark/issues/12
Futhark generates a nim file in querySetting(nimcacheDir) at compile time, and then import it
It works, but vscode extensions error out due to nim check trying to import it from *_check cache folder, instead of [_d|_r]
I've created a minimal test to replicate the problem
vscodecache.nim
nim c -r vscodecache.nim
vscode error == nim check vscodecache.nim
not sure if the fix should be in futhark or here, but it's worth discussing for libraries like Futhark that works by generating custom nim files in cache folder.