aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/generators/gen_declarations.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:39:54 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:39:54 +0000
commit21cb7d04c387e4198ca8098a884c78b56ffcf4c2 (patch)
tree84fe5690df1551f0bb2bdfe1a13aacd29ebc1de7 /src/nvim/generators/gen_declarations.lua
parentd9c904f85a23a496df4eb6be42aa43f007b22d50 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-colorcolchar.tar.gz
rneovim-colorcolchar.tar.bz2
rneovim-colorcolchar.zip
Merge remote-tracking branch 'upstream/master' into colorcolcharcolorcolchar
Diffstat (limited to 'src/nvim/generators/gen_declarations.lua')
-rw-r--r--[-rwxr-xr-x]src/nvim/generators/gen_declarations.lua28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/nvim/generators/gen_declarations.lua b/src/nvim/generators/gen_declarations.lua
index 4097ff7dc5..f9e9c6b0a8 100755..100644
--- a/src/nvim/generators/gen_declarations.lua
+++ b/src/nvim/generators/gen_declarations.lua
@@ -1,12 +1,9 @@
-#!/usr/bin/lua
-
local fname = arg[1]
local static_fname = arg[2]
local non_static_fname = arg[3]
local preproc_fname = arg[4]
-
-local lpeg = require('lpeg')
+local lpeg = vim.lpeg
local fold = function (func, ...)
local result = nil
@@ -174,7 +171,7 @@ static functions into static.h and declarations for non-static functions into
non-static.h. File `definitions.i' should contain an already preprocessed
version of definitions.c and it is the only one which is actually parsed,
definitions.c is needed only to determine functions from which file out of all
-functions found in definitions.i are needed.
+functions found in definitions.i are needed and to generate an IWYU comment.
Additionally uses the following environment variables:
@@ -227,6 +224,18 @@ local non_static = header .. [[
local static = header
+if fname:find('.*/src/nvim/.*%.c$') then
+ -- Add an IWYU pragma comment if the corresponding .h file exists.
+ local header_fname = fname:sub(1, -3) .. '.h'
+ local header_f = io.open(header_fname, 'r')
+ if header_f ~= nil then
+ header_f:close()
+ non_static = ([[
+// IWYU pragma: private, include "%s"
+]]):format(header_fname:gsub('.*/src/nvim/', 'nvim/')) .. non_static
+ end
+end
+
local filepattern = '^#%a* (%d+) "([^"]-)/?([^"/]+)"'
local init = 1
@@ -244,12 +253,7 @@ while init ~= nil do
curfile = file
is_needed_file = (curfile == neededfile)
declline = tonumber(line) - 1
- local curdir_start = dir:find('src/nvim/')
- if curdir_start ~= nil then
- curdir = dir:sub(curdir_start + #('src/nvim/'))
- else
- curdir = dir
- end
+ curdir = dir:gsub('.*/src/nvim/', '')
else
declline = declline - 1
end
@@ -311,7 +315,7 @@ F = io.open(static_fname, 'w')
F:write(static)
F:close()
--- Before generating the non-static headers, check if the current file(if
+-- Before generating the non-static headers, check if the current file (if
-- exists) is different from the new one. If they are the same, we won't touch
-- the current version to avoid triggering an unnecessary rebuilds of modules
-- that depend on this one