update_intellisense.lua 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. -- imports
  2. import("core.project.config")
  3. import("core.project.project")
  4. import("clang.compile_commands", {rootdir = path.join(os.programdir(), "plugins", "project")})
  5. -- config target
  6. function _config_target(target)
  7. local oldenvs = os.addenvs(target:pkgenvs())
  8. for _, rule in ipairs(target:orderules()) do
  9. local on_config = rule:script("config")
  10. if on_config then
  11. on_config(target)
  12. end
  13. end
  14. local on_config = target:script("config")
  15. if on_config then
  16. on_config(target)
  17. end
  18. if oldenvs then
  19. os.setenvs(oldenvs)
  20. end
  21. end
  22. -- config targets
  23. function _config_targets()
  24. for _, target in ipairs(project.ordertargets()) do
  25. if target:is_enabled() then
  26. _config_target(target)
  27. end
  28. end
  29. end
  30. -- main entry
  31. function main(compileCommandsDirectory, compileCommandsBackend)
  32. -- generate compile_commands.json
  33. -- @note we can only load configuration because we watched onFileChanged(xmake.conf)
  34. os.setenv("XMAKE_IN_PROJECT_GENERATOR", "true")
  35. os.setenv("XMAKE_GENERATOR_COMPDB_LSP", compileCommandsBackend)
  36. config.load()
  37. _config_targets()
  38. compile_commands.make(compileCommandsDirectory or ".vscode")
  39. os.setenv("XMAKE_IN_PROJECT_GENERATOR", nil)
  40. end