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

Option to link compile_commands.json to current directory #36

Closed
ayles opened this issue Apr 8, 2023 · 17 comments
Closed

Option to link compile_commands.json to current directory #36

ayles opened this issue Apr 8, 2023 · 17 comments
Assignees
Labels
enhancement New feature or request

Comments

@ayles
Copy link

ayles commented Apr 8, 2023

Would be great to have smth like that

@ayles ayles added the enhancement New feature or request label Apr 8, 2023
@Civitasv
Copy link
Owner

This plugin use symlink to achieve that, why not use .clangd?

@ayles
Copy link
Author

ayles commented Apr 14, 2023

But switches between release types are initiated by plugin. It is inconvenient to change path to compilation database every time by hand

@Civitasv
Copy link
Owner

Make sense, I will see how i can implement it.

@iFuSiiOnzZ
Copy link

iFuSiiOnzZ commented Apr 18, 2023

Something like this in init.lua:125, inside on_success function after running the CMake command. What I can't figure out how to delete the file when exiting the editor.

local compile_commands = config.build_directory.filename .. "/compile_commands.json"
local cmd = "[ -e " .. compile_commands .. " ] && cp " .. compile_commands .. " ."

local handle = io.popen(cmd)
handle:close()

@iFuSiiOnzZ
Copy link

Platform independent solution.

diff --git a/lua/cmake-tools/init.lua b/lua/cmake-tools/init.lua
index 7293c22..6cf7518 100644
--- a/lua/cmake-tools/init.lua
+++ b/lua/cmake-tools/init.lua
@@ -127,6 +127,13 @@ function cmake.generate(opt, callback)
       if type(callback) == "function" then
         callback()
       end
+
+      local infile  = io.open(config.build_directory.filename .. "/compile_commands.json", "r")
+      local outfile = io.open("compile_commands.json", "w")
+
+      outfile:write(infile:read("*a"))
+      outfile:close()
+      infile:close()
     end,
     cmake_console_position = const.cmake_console_position,
     cmake_show_console = const.cmake_show_console,

@ayles
Copy link
Author

ayles commented Apr 18, 2023

Is there any reason to copy it instead of just making symlink?

@iFuSiiOnzZ
Copy link

@ayles Because it should be platform independent and I haven't seen anything in the LUA file api that allows to create symbolic links. On Linux you would use ln -s and on Windows mklink.

@Civitasv
Copy link
Owner

@iFuSiiOnzZ Why not use vim.cmd("term ln -s")?

@Civitasv
Copy link
Owner

I've added this ability. See 6e4e422

@iFuSiiOnzZ
Copy link

Haven't test in on Linux yet. On Windows there are a some problems.

Powershell normal user

CMake Error: failed to create symbolic link 'C:\Users\Develop\Projects\ls/compile_commands.json': A required privilege is not held by the client.

Powershell with admin privileges

:!cmake -E create_symlink cmake_build_Debug/compile_commands.json C:\Users\AndreiAJ\Projects\ls/compile_commands.json

@rohit-kumar-j
Copy link
Contributor

@iFuSiiOnzZ, I did you try compile_commands with MSVC on powershell?

@Civitasv
Copy link
Owner

Powershell with admin privileges

When in admin privileges, Was the command successful?

@Civitasv Civitasv self-assigned this Apr 19, 2023
@iFuSiiOnzZ
Copy link

@rohit-kumar-j I am using mingw, at the moment, so no idea if it works or not.
@Civitasv Nope, I played a bit with Windows policies, but also no luck (Windows 11).

@Civitasv
Copy link
Owner

Can you show the error messages?

@iFuSiiOnzZ
Copy link

For some reason the neovim log is empty and cmake reports nothing about the error.
What is more strange... I ran cmake -E create_symlink from the terminal and it worked.

@Civitasv
Copy link
Owner

That's interesting.

@Civitasv
Copy link
Owner

Look at this.

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

4 participants