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

Issue with directory-wide nim config scripts #29

Open
Wazubaba opened this issue Jun 22, 2020 · 4 comments
Open

Issue with directory-wide nim config scripts #29

Wazubaba opened this issue Jun 22, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@Wazubaba
Copy link

Hi, I noticed that while a per-module config script is properly used (ex: myscript.nims works for myscript.nim), the dir-wide versions (config.nims or nim.config) are not processed. This causes incorrect error highlighting for a lot of things, including the unit-tests generated by nimble since this plugin is not passing the imports to nim-suggest as far as I can tell. It also results in broken imports not being highlighted as well.

@alaviss
Copy link
Owner

alaviss commented Jun 23, 2020

Can I have the directory structure of your project, as well as the output of :echo nim#suggest#FindInstance() once you opened a file in the project?

@alaviss alaviss added the bug Something isn't working label Jun 23, 2020
@Wazubaba
Copy link
Author

The config.nims file contains switch("path", "..")

/README.md
/multilang.nim
/multilang.nimble
/tests/
      /config.nims
      /test.nim
      /tree1.ini
      /tree2.ini
      /tree3.ini
{'addCallback': function('<SNR>43_instance_addCallback'), 'job': 3, 'start': function('<SNR>43_instance_start'), 'file': '/home/wazubaba/dev/code/nim/lib/native/multilang/multil
ang.nim', 'stop': function('<SNR>43_instance_stop'), 'cmd': 'nimsuggest', 'oneshots': [], 'on_exit': function('<SNR>44_bufCb', [{'cb': function('<SNR>43_instanceHandler'), 'buff
er': {'buffer': '', 'process': function('<SNR>44_process')}}]), 'on_stdout': function('<SNR>44_bufCb', [{'cb': function('<SNR>43_instanceHandler'), 'buffer': {'buffer': '', 'pro
cess': function('<SNR>44_process')}}]), 'message': function('<SNR>43_instance_message'), 'project': function('<SNR>43_instance_project'), 'isRunning': function('<SNR>43_instance
_isRunning'), 'cb': function('<SNR>42_onEvent'), 'query': function('<SNR>43_instance_query'), 'port': 51455, 'isReady': function('<SNR>43_instance_isReady'), 'contains': functio
n('<SNR>43_instance_contains'), 'on_stderr': function('<SNR>44_bufCb', [{'cb': function('<SNR>43_instanceHandler'), 'buffer': {'buffer': '', 'process': function('<SNR>44_process
')}}]), 'args': ['--autobind', '--address:localhost']}

@alaviss
Copy link
Owner

alaviss commented Jun 24, 2020

I think I know why this doesn't work, though I must say this kind of folder structure is a bit unconventional...

Does everything work if you open a file in tests directly from a fresh neovim session? I think I got a fix if that case work.

EDIT: I know exactly why this doesn't work now, fix follow soon.

alaviss added a commit that referenced this issue Jun 25, 2020
Previously, when traversing a project directory to look for a potential
project file, we just ignored the global config files. This was done
because we can't deduce the true project file from these configuration.

However the fact that that the project file cannot be outside of this
directory was overlooked, and cause issues with unconventional project
layout as with #29.
@alaviss
Copy link
Owner

alaviss commented Jun 25, 2020

With the commit I merged, directly opening tests/test.nim will work.

However if you're working on multilang.nim and you decided to switch to tests/test.nim within the same neovim session, this will not work out of the box. The reason is due to how project management is done:

If a nimsuggest session is activated for multilang.nim, then any file opened within the same folder will reuse that session. Ie.

/README.md
/multilang.nim <- opened, spawned a nimsuggest instance on /
/multilang.nimble
/tests/
      /config.nims
      /test.nim <- if gonna be opened, will reuse the nimsuggest instance
      /tree1.ini
      /tree2.ini
      /tree3.ini

This is based on the simple fact that multilang.nim can import any file in tests/ due to tests/ being a subfolder, thus we assume that anything in tests/ is a part of multilang project and we should reuse the spawned nimsuggest instance to avoid (potentially) recompiling everything.

Of course, this is false for your project in particular, as tests/ is actually a project on it's own (for example if you import a file in tests/ from / it will error out because the inner config.nims won't be used). Currently I can only offer these walkarounds:

  • Don't use config.nims and use import ".." / multilang instead.
  • Use the standard src/ subfolder scheme that's the default for new nimble projects.

I'm considering whether this sort of "subproject within project" should be supported by default, since it doesn't respect the hierarchy of a Nim project. Though I'll tell you now that there's a high chance of ootb support given my goal for this plugin is to be foolproof...

@alaviss alaviss added enhancement New feature or request and removed bug Something isn't working labels Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants