Skip to content

Commit 8a226bb

Browse files
sebu06Sebastian Uharek
authored andcommitted
Added option to override config with local file.
1 parent 680a501 commit 8a226bb

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

docs/sessions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ local session = {
3939
```
4040

4141
per project.
42+
43+
Alternatively, cmake-tools will search for a file ".cmake-tools.lua" in the current working directory. If it is found, the configuration in this file will be used. If no configuration is found in the current working directory, it will continue looking in the parent directory. If no config can be found, it will use the sessions mentioned above.

lua/cmake-tools/session.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
local osys = require("cmake-tools.osys")
22
local utils = require("cmake-tools.utils")
33

4+
local function findFileInDirOrParent(dir, fname)
5+
local path = dir .. "/" .. fname
6+
local file = io.open(path, "r")
7+
if file then
8+
file:close()
9+
return path
10+
end
11+
12+
local parentDir = dir:match("(.+)/[^/]+$")
13+
if not parentDir then
14+
return nil
15+
end
16+
17+
return findFileInDirOrParent(parentDir, fname)
18+
end
19+
420
local session = {
521
dir = {
622
unix = vim.fn.expand("~") .. "/.cache/cmake_tools_nvim/",
@@ -25,6 +41,10 @@ end
2541

2642
local function get_current_path()
2743
local current_path = vim.loop.cwd()
44+
local local_config = findFileInDirOrParent(current_path, ".cmake-tools.lua")
45+
if local_config then
46+
return local_config
47+
end
2848
local clean_path = current_path:gsub("/", "")
2949
clean_path = clean_path:gsub("\\", "")
3050
clean_path = clean_path:gsub(":", "")

0 commit comments

Comments
 (0)