Code Monkey home page Code Monkey logo

Comments (14)

Civitasv avatar Civitasv commented on July 30, 2024 1
function cmake.create_regenerate_on_save_autocmd()
  local cmake_files = file_picker.get_cmake_files()
  local others = { "CMakePresets.json", "CMakeUserPresets.json", "cmake-presets.json", "cmake-user-presets.json", "CMakeVariants.json", "CMakeVariants.yaml", "cmake-variants.yaml", "cmake-variants.json", "CMakeKits.json", "cmake-kits.json" }

  local pattern = {}
  for _, item in ipairs(cmake_files) do
    table.insert(pattern, vim.loop.cwd() .. "/" .. item)
  end

  for _, item in ipairs(others) do
    table.insert(pattern, vim.loop.cwd() .. "/" .. item)
  end

  if #pattern ~= 0 then
    -- for cmake files
    vim.api.nvim_create_autocmd("BufWritePre", {
      group = group,
      pattern = pattern,
      callback = function()
        print("FILE PICKER", vim.inspect(pattern))
        local buf = vim.api.nvim_get_current_buf()
        -- Check if buffer is actually modified, and only if it is modified,
        -- execute the :CMakeGenerate, otherwise return. This is to avoid unnecessary regenerattion
        local buf_modified = vim.api.nvim_buf_get_option(buf, "modified")
        if buf_modified then
          cmake.generate({ bang = false, fargs = {} }, nil)
        end
      end,
    })
  end
end

I think we do. Because what happens if new files are added?

Yes, we should re-register every time after CMakeGenerate.

from cmake-tools.nvim.

Civitasv avatar Civitasv commented on July 30, 2024

Is it normal that users manually change contents of .cmake dir?

from cmake-tools.nvim.

hfn92 avatar hfn92 commented on July 30, 2024

I don't mean the files in the cmake cache. But addidional cmake config files are usually .cmake.
E.g setting.cmake and coverage.cmake. They are part of the source.

from cmake-tools.nvim.

Civitasv avatar Civitasv commented on July 30, 2024

Oh, I understand. Ideally, if they are included in CMakeLists.txt, we should register listener for them.

Follows are files or settings that should register contents change event in my opinion:

  • .cmake files that are included in CMakeLists.txt
  • presets files
  • variants files (if presets not exists)
  • kits files (if presets not exists)
  • CMakeSettings (maybe)

@hfn92 What do you think?

from cmake-tools.nvim.

Civitasv avatar Civitasv commented on July 30, 2024

I've confirmed that .cmake files that are included in CMakeLists.txt will be included in codemodel file.

from cmake-tools.nvim.

hfn92 avatar hfn92 commented on July 30, 2024

It's not just .cmake files but also files used in configure_file. And probably some more. But the codemodel file should contain all those files

from cmake-tools.nvim.

hfn92 avatar hfn92 commented on July 30, 2024

Oh, I understand. Ideally, if they are included in CMakeLists.txt, we should register listener for them.

Follows are files or settings that should register contents change event in my opinion:

  • .cmake files that are included in CMakeLists.txt
  • presets files
  • variants files (if presets not exists)
  • kits files (if presets not exists)
  • CMakeSettings (maybe)

@hfn92 What do you think?

I think its better to handle content change of each file in the cmake codemodel as those should include all relevant files.

from cmake-tools.nvim.

Civitasv avatar Civitasv commented on July 30, 2024
function cmake.create_regenerate_on_save_autocmd()
  local cmake_files = file_picker.get_cmake_files()

  -- for cmake files
  vim.api.nvim_create_autocmd("BufWritePre", {
    group = group,
    pattern = cmake_files,
    callback = function()
      local buf = vim.api.nvim_get_current_buf()
      -- Check if buffer is actually modified, and only if it is modified,
      -- execute the :CMakeGenerate, otherwise return. This is to avoid unnecessary regenerattion
      local buf_modified = vim.api.nvim_buf_get_option(buf, "modified")
      if buf_modified then
        cmake.generate({ bang = false, fargs = {} }, nil)
      end
    end,
  })

  -- For presets, variants and kits
  vim.api.nvim_create_autocmd("BufWritePre", {
    group = group,
    pattern = { "CMakePresets.json", "CMakeUserPresets.json", "cmake-presets.json", "cmake-user-presets.json", "CMakeVariants.json", "CMakeVariants.yaml", "cmake-variants.yaml", "cmake-variants.json", "CMakeKits.json", "cmake-kits.json" },
    callback = function()
      local buf = vim.api.nvim_get_current_buf()
      -- Check if buffer is actually modified, and only if it is modified,
      -- execute the :CMakeGenerate, otherwise return. This is to avoid unnecessary regenerattion
      local buf_modified = vim.api.nvim_buf_get_option(buf, "modified")
      if buf_modified then
        cmake.generate({ bang = false, fargs = {} }, nil)
      end
    end,
  })
end

Do you think it is enough? We should re-register it every time after CMakeGenerate

from cmake-tools.nvim.

hfn92 avatar hfn92 commented on July 30, 2024

I'm not sure. I don't know the vim api well enough. You can test it by adding
configure_file(some_file ${CMAKE_BINARY_DIR}/some_file.junk) to your CMakeLists.txt. Then changing some_file should trigger re-generate

from cmake-tools.nvim.

hfn92 avatar hfn92 commented on July 30, 2024

regarding

pattern = { "CMakePresets.json", "CMakeUserPresets.json", "cmake-presets.json", "cmake-user-presets.json", "CMakeVariants.json", "CMakeVariants.yaml", "cmake-variants.yaml", "cmake-variants.json", "CMakeKits.json", "cmake-kits.json" }

I'm not sure if this works. I think once configured, changing files like CMakePresets.json doesn't affect the already created cmake cache. You'd need to delete cache first I think. So this is probably unnecessary.

from cmake-tools.nvim.

Civitasv avatar Civitasv commented on July 30, 2024

configure_file(some_file ${CMAKE_BINARY_DIR}/some_file.junk)

It works! And turns out we don't need re-register it every time, it's dynamic.

from cmake-tools.nvim.

hfn92 avatar hfn92 commented on July 30, 2024

configure_file(some_file ${CMAKE_BINARY_DIR}/some_file.junk)

It works!

Great! 👍

And turns out we don't need re-register it every time, it's dynamic.

I think we do. Because what happens if new files are added?

from cmake-tools.nvim.

Civitasv avatar Civitasv commented on July 30, 2024

I think once configured, changing files like CMakePresets.json doesn't affect the already created cmake cache. You'd need to delete cache first I think. So this is probably unnecessary.

Presets, variants, and kits have some configuration about cmake generation, they kinda like CMakeLists.txt, so I think it is necessary to watch them.

from cmake-tools.nvim.

hfn92 avatar hfn92 commented on July 30, 2024

I think once configured, changing files like CMakePresets.json doesn't affect the already created cmake cache. You'd need to delete cache first I think. So this is probably unnecessary.

Presets, variants, and kits have some configuration about cmake generation, they kinda like CMakeLists.txt, so I think it is necessary to watch them.

ok, I see

from cmake-tools.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.