Shatur / neovim-cmake

CMake integration for Neovim
GNU General Public License v3.0
87 stars 19 forks source link

Allow different directory to run target from #3

Closed jxi24 closed 3 years ago

jxi24 commented 3 years ago

Describe the problem or limitation you are having With the current setup, the run command runs the target in the target directory. I have some configuration files that are to be loaded upon code startup that are based on the current directory. When locally using the code for development, I copy a basic configuration file to the CMAKE_BUILD_DIR instead of copying it to each directory in which a target exists. This then results in the run command not working, since it can't load the configuration file.

Describe the solution you'd like I would like the ability to set the working directory to run the target from.

Describe alternatives you've considered I have considered copying the needed files to each location, but this would make ensuring that the configuration file is consistent between each different target location during development. I have also considered modifying the code to store the location where the files are located and load from their based on the cmake configuration, but this would involve a lot of restructuring of the existing code.

Shatur commented 3 years ago

When locally using the code for development, I copy a basic configuration file to the CMAKE_BUILD_DIR instead of copying it to each directory in which a target exists. This then results in the run command not working, since it can't load the configuration file.

Have you considered setting CMAKE_RUNTIME_OUTPUT_DIRECTORY to CMAKE_BUILD_DIR? Since you copying configuration files there.

I would not mind adding an option to specify the startup folder, but at the moment the options are not set on a per-project. So you have to change your running path each time you change the project.

jxi24 commented 3 years ago

I have not thought about that, but I would prefer to keep my testsuite executables separate from the main executable. I understand the issue with having to do a different setup per-project. Would it be possible to do something like have a global configuration, about allow a local file maybe something like .neovim-cmake.cfg override the default settings? This way one could have project specific commands if desired, but wouldn't mess with the global setup.

Shatur commented 3 years ago

Hm... Okay! We currently have neovim.json file that contains run arguments and selected project. Perhaps we could expand it to store more settings. As startup directory or cmake options. But this will require some work :) I can do this later when I have a little free time. But if you want to contribute - please, let me know, we could discuss implementation details.

jxi24 commented 3 years ago

I wouldn't mind contributing to the project. I would be happy to discuss implementation details.

Shatur commented 3 years ago

Okay!

For now we have set of options here:

https://github.com/Shatur/neovim-cmake/blob/b03fea1308d2e99795501dbc98b878b51ef5f054/plugin/cmake.vim#L7-L12

But some of them could be platform-specific. So I would wrap all settings in neovim.json (including current settings such as selected project or parameters) in a top-level dictionary that contains os name. You could get os name from this variable:

https://github.com/Shatur/neovim-cmake/blob/b03fea1308d2e99795501dbc98b878b51ef5f054/lua/cmake/utils.lua#L1

And every time you trying to get setting - just read it from JSON, here is the function to get it content:

https://github.com/Shatur/neovim-cmake/blob/b03fea1308d2e99795501dbc98b878b51ef5f054/lua/cmake/utils.lua#L4

And set:

https://github.com/Shatur/neovim-cmake/blob/b03fea1308d2e99795501dbc98b878b51ef5f054/lua/cmake/utils.lua#L11

If requested setting doesn't exists - use according global setting. I would wrap this into a convenient class (table) and move into a separate file.

Also we should add the option that your requested. I think that it should be local-only. You should check for it here:

https://github.com/Shatur/neovim-cmake/blob/b03fea1308d2e99795501dbc98b878b51ef5f054/lua/cmake/init.lua#L52

And here:

https://github.com/Shatur/neovim-cmake/blob/b03fea1308d2e99795501dbc98b878b51ef5f054/lua/cmake/init.lua#L41

Your thoughts? Suggestions?

jxi24 commented 3 years ago

I think the first part makes sense. I would suggest modifying the get_parameters function and the set_parameters function. To first check to see if there is a neovim.json file in the project root directory. If there is, then it should load the parameters from there. If any required settings are missing, then it should load it from the global neovim.json or from the default values.

We would then just have to modify: https://github.com/Shatur/neovim-cmake/blob/b03fea1308d2e99795501dbc98b878b51ef5f054/lua/cmake/utils.lua#L92

To see if the user has the option set for a different run directory in the neovim.json file. If they have it set, then use that, otherwise use the current setup. I think that would be cleaner than doing it in both: https://github.com/Shatur/neovim-cmake/blob/b03fea1308d2e99795501dbc98b878b51ef5f054/lua/cmake/init.lua#L52 and here: https://github.com/Shatur/neovim-cmake/blob/b03fea1308d2e99795501dbc98b878b51ef5f054/lua/cmake/init.lua#L41 Since both call utils.get_current_target(...)

Does that seem like a reasonable approach?

Shatur commented 3 years ago

I agree! Just one thing:

If any required settings are missing, then it should load it from the global neovim.json or from the default values.

I would avoid using a global neovim.json. I think that having a project-specific neovim.json and default values is enough.

jxi24 commented 3 years ago

Sounds reasonable. I will begin working on it.