VS-Code local imports
When making my repo, I have a package directory (
REPO_ROOT/toybox
) and a test directory (REPO_ROOT/test
). When running the tests, I use mojo test -I .
; the -I .
tells the test runner to add the current dir (.
) to Mojo's import path while running the tests.
How do I get the same behavior for the VS-Code extension?
Right now, the extension chokes on the line from toybox import BlahBlah
, so I temporarily add a test/__init__.mojo
file while building the tests. That appeases the LSP. Then I delete that file when running the tests. Add it back and edit. Delete it and run tests. Rinse, repeat. Bleh.
For ref, here's the repo in question:
https://github.com/dimitrilw/toybox
Attached pics:
- First pic shows what VS-Code extension does when no __init__.mojo
file exists; it fails on the import line, then starts throwing other "errors" at other points in the code.
- Second pic shows LSP crash, which seems to happen often when I'm editing my tests without the init file -- or even just viewing the tests, as in this crash that just happened.
- Third pic shows what VS-Code extension does when the init file exists: proper function & no errors displayed.
The crash in second pic was unexpected, but not uncommon.![No description](https://cdn.answeroverflow.com/1240312205795266622/image.png)
![No description](https://cdn.answeroverflow.com/1240312206135136307/image.png)
![No description](https://cdn.answeroverflow.com/1240312206793510932/image.png)
0 Replies