From a6f26c86cb74222fe2449f8a035f29b0ee45c98e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Nov 2023 22:48:15 +0800 Subject: [PATCH] refactor(IWYU): fix includes for cmdhist.h (#26324) --- Makefile | 8 -------- src/clint.py | 8 -------- src/nvim/cmdhist.c | 1 + src/nvim/cmdhist.h | 11 +++++------ src/nvim/diff.h | 11 ++++++----- src/nvim/drawscreen.h | 3 +-- src/nvim/eval.c | 2 +- src/nvim/ex_cmds.c | 1 + src/nvim/fold.h | 6 +++--- src/nvim/insexpand.c | 1 + src/nvim/log.h | 6 ++++-- src/nvim/main.c | 1 + src/nvim/path.c | 2 -- src/nvim/path.h | 43 ++++++++++++++++++++++--------------------- src/nvim/shada.c | 10 +++++----- src/nvim/tui/input.c | 2 ++ 16 files changed, 53 insertions(+), 63 deletions(-) diff --git a/Makefile b/Makefile index cbcc7f5eae..5667c9d953 100644 --- a/Makefile +++ b/Makefile @@ -152,11 +152,8 @@ iwyu: build/.ran-cmake |src/nvim/channel.h\ |src/nvim/charset.h\ |src/nvim/cmdexpand.h\ - |src/nvim/cmdhist.h\ |src/nvim/decoration.h\ - |src/nvim/diff.h\ |src/nvim/drawline.h\ - |src/nvim/drawscreen.h\ |src/nvim/eval.h\ |src/nvim/eval/encode.h\ |src/nvim/eval/typval.h\ @@ -174,7 +171,6 @@ iwyu: build/.ran-cmake |src/nvim/event/time.h\ |src/nvim/event/wstream.h\ |src/nvim/extmark.h\ - |src/nvim/fold.h\ |src/nvim/garray.h\ |src/nvim/getchar.h\ |src/nvim/globals.h\ @@ -183,7 +179,6 @@ iwyu: build/.ran-cmake |src/nvim/highlight_group.h\ |src/nvim/input.h\ |src/nvim/keycodes.h\ - |src/nvim/log.h\ |src/nvim/lua/executor.h\ |src/nvim/main.h\ |src/nvim/mark.h\ @@ -197,14 +192,11 @@ iwyu: build/.ran-cmake |src/nvim/os/pty_conpty_win.h\ |src/nvim/os/pty_process_unix.h\ |src/nvim/os/pty_process_win.h\ - |src/nvim/path.h\ |src/nvim/plines.h\ - |src/nvim/popupmenu.h\ |src/nvim/tui/input.h\ |src/nvim/ui.h\ |src/nvim/viml/parser/expressions.h\ |src/nvim/viml/parser/parser.h\ - |src/nvim/window.h\ )" --nosafe_headers < build/iwyu.log cmake -B build -U ENABLE_IWYU cmake --build build diff --git a/src/clint.py b/src/clint.py index 9b946998c9..ddd3ff7d44 100755 --- a/src/clint.py +++ b/src/clint.py @@ -910,11 +910,8 @@ def CheckIncludes(filename, lines, error): "src/nvim/channel.h", "src/nvim/charset.h", "src/nvim/cmdexpand.h", - "src/nvim/cmdhist.h", "src/nvim/decoration.h", - "src/nvim/diff.h", "src/nvim/drawline.h", - "src/nvim/drawscreen.h", "src/nvim/eval.h", "src/nvim/eval/encode.h", "src/nvim/eval/typval.h", @@ -932,7 +929,6 @@ def CheckIncludes(filename, lines, error): "src/nvim/event/time.h", "src/nvim/event/wstream.h", "src/nvim/extmark.h", - "src/nvim/fold.h", "src/nvim/garray.h", "src/nvim/getchar.h", "src/nvim/globals.h", @@ -941,7 +937,6 @@ def CheckIncludes(filename, lines, error): "src/nvim/highlight_group.h", "src/nvim/input.h", "src/nvim/keycodes.h", - "src/nvim/log.h", "src/nvim/lua/executor.h", "src/nvim/main.h", "src/nvim/mark.h", @@ -955,14 +950,11 @@ def CheckIncludes(filename, lines, error): "src/nvim/os/pty_conpty_win.h", "src/nvim/os/pty_process_unix.h", "src/nvim/os/pty_process_win.h", - "src/nvim/path.h", "src/nvim/plines.h", - "src/nvim/popupmenu.h", "src/nvim/tui/input.h", "src/nvim/ui.h", "src/nvim/viml/parser/expressions.h", "src/nvim/viml/parser/parser.h", - "src/nvim/window.h", ] skip_headers = [ diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c index 7ebe3c34a1..9396fdac7f 100644 --- a/src/nvim/cmdhist.c +++ b/src/nvim/cmdhist.c @@ -21,6 +21,7 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_vars.h" +#include "nvim/os/time.h" #include "nvim/regexp.h" #include "nvim/strings.h" #include "nvim/types_defs.h" diff --git a/src/nvim/cmdhist.h b/src/nvim/cmdhist.h index cce0f92898..489e9d283f 100644 --- a/src/nvim/cmdhist.h +++ b/src/nvim/cmdhist.h @@ -1,10 +1,10 @@ #pragma once -#include "nvim/cmdexpand_defs.h" // IWYU pragma: export +#include "nvim/cmdexpand_defs.h" // IWYU pragma: keep #include "nvim/eval/typval_defs.h" -#include "nvim/ex_cmds_defs.h" // IWYU pragma: export -#include "nvim/os/time.h" -#include "nvim/types_defs.h" +#include "nvim/ex_cmds_defs.h" // IWYU pragma: keep +#include "nvim/os/time_defs.h" +#include "nvim/types_defs.h" // IWYU pragma: keep /// Present history tables typedef enum { @@ -17,8 +17,7 @@ typedef enum { HIST_DEBUG, ///< Debug commands. } HistoryType; -/// Number of history tables -#define HIST_COUNT (HIST_DEBUG + 1) +enum { HIST_COUNT = HIST_DEBUG + 1, }; ///< Number of history tables /// History entry definition typedef struct hist_entry { diff --git a/src/nvim/diff.h b/src/nvim/diff.h index 8b58887890..fd897498df 100644 --- a/src/nvim/diff.h +++ b/src/nvim/diff.h @@ -2,16 +2,17 @@ #include -#include "nvim/ex_cmds_defs.h" +#include "nvim/buffer_defs.h" // IWYU pragma: keep +#include "nvim/ex_cmds_defs.h" // IWYU pragma: keep #include "nvim/macros_defs.h" -#include "nvim/pos_defs.h" +#include "nvim/pos_defs.h" // IWYU pragma: keep // Value set from 'diffopt'. -EXTERN int diff_context INIT( = 6); // context for folds -EXTERN int diff_foldcolumn INIT( = 2); // 'foldcolumn' for diff mode +EXTERN int diff_context INIT( = 6); ///< context for folds +EXTERN int diff_foldcolumn INIT( = 2); ///< 'foldcolumn' for diff mode EXTERN bool diff_need_scrollbind INIT( = false); -EXTERN bool need_diff_redraw INIT( = false); // need to call diff_redraw() +EXTERN bool need_diff_redraw INIT( = false); ///< need to call diff_redraw() #ifdef INCLUDE_GENERATED_DECLARATIONS # include "diff.h.generated.h" diff --git a/src/nvim/drawscreen.h b/src/nvim/drawscreen.h index 565b01bcd1..b18a907ba8 100644 --- a/src/nvim/drawscreen.h +++ b/src/nvim/drawscreen.h @@ -3,7 +3,6 @@ #include #include "nvim/buffer_defs.h" -#include "nvim/drawline.h" #include "nvim/macros_defs.h" /// flags for update_screen() @@ -22,7 +21,7 @@ enum { /// ('lines' and 'rows') must not be changed. EXTERN bool updating_screen INIT( = 0); -EXTERN match_T screen_search_hl INIT( = { 0 }); // used for 'hlsearch' highlight matching +EXTERN match_T screen_search_hl INIT( = { 0 }); ///< used for 'hlsearch' highlight matching #define W_ENDCOL(wp) ((wp)->w_wincol + (wp)->w_width) #define W_ENDROW(wp) ((wp)->w_winrow + (wp)->w_height) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index de36bf016f..6786316b8e 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4548,7 +4548,7 @@ bool garbage_collect(bool testing) // history items (ShaDa additional elements) if (p_hi) { - for (HistoryType i = 0; i < HIST_COUNT; i++) { + for (int i = 0; i < HIST_COUNT; i++) { const void *iter = NULL; do { histentry_T hist; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index c0aca071e2..2c51d64972 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -25,6 +25,7 @@ #include "nvim/change.h" #include "nvim/channel.h" #include "nvim/charset.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/cmdhist.h" #include "nvim/cursor.h" #include "nvim/decoration.h" diff --git a/src/nvim/fold.h b/src/nvim/fold.h index 3a70c11792..efa239daa5 100644 --- a/src/nvim/fold.h +++ b/src/nvim/fold.h @@ -1,13 +1,13 @@ #pragma once -#include +#include // IWYU pragma: keep #include "nvim/buffer_defs.h" // IWYU pragma: keep #include "nvim/fold_defs.h" // IWYU pragma: export #include "nvim/garray_defs.h" // IWYU pragma: keep #include "nvim/macros_defs.h" -#include "nvim/pos_defs.h" -#include "nvim/types_defs.h" +#include "nvim/pos_defs.h" // IWYU pragma: keep +#include "nvim/types_defs.h" // IWYU pragma: keep EXTERN int disable_fold_update INIT( = 0); diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 4595c6913b..a59ba1b6d9 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -9,6 +9,7 @@ #include #include +#include "klib/kvec.h" #include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" diff --git a/src/nvim/log.h b/src/nvim/log.h index cac074d146..b277e09a0f 100644 --- a/src/nvim/log.h +++ b/src/nvim/log.h @@ -45,9 +45,11 @@ # define LOG_CALLSTACK_TO_FILE(fp) log_callstack_to_file(fp, __func__, __LINE__) #endif -#if NVIM_HAS_INCLUDE("sanitizer/asan_interface.h") -# include "sanitizer/asan_interface.h" +// uncrustify:off +#if NVIM_HAS_INCLUDE() +# include // IWYU pragma: keep #endif +// uncrustify:on #ifdef INCLUDE_GENERATED_DECLARATIONS # include "log.h.generated.h" diff --git a/src/nvim/main.c b/src/nvim/main.c index 937035eace..216e39f3e8 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -30,6 +30,7 @@ #include "nvim/decoration.h" #include "nvim/decoration_provider.h" #include "nvim/diff.h" +#include "nvim/drawline.h" #include "nvim/drawscreen.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" diff --git a/src/nvim/path.c b/src/nvim/path.c index 100d66dfff..28de003212 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -15,9 +15,7 @@ #include "nvim/ex_docmd.h" #include "nvim/file_search.h" #include "nvim/fileio.h" -#include "nvim/func_attr.h" #include "nvim/garray.h" -#include "nvim/garray_defs.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/macros_defs.h" diff --git a/src/nvim/path.h b/src/nvim/path.h index 89f939dd02..a8eb893bb3 100644 --- a/src/nvim/path.h +++ b/src/nvim/path.h @@ -2,32 +2,33 @@ #include // IWYU pragma: keep -#include "nvim/func_attr.h" #include "nvim/garray_defs.h" // IWYU pragma: keep #include "nvim/types_defs.h" // IWYU pragma: keep -// Flags for expand_wildcards() -#define EW_DIR 0x01 // include directory names -#define EW_FILE 0x02 // include file names -#define EW_NOTFOUND 0x04 // include not found names -#define EW_ADDSLASH 0x08 // append slash to directory name -#define EW_KEEPALL 0x10 // keep all matches -#define EW_SILENT 0x20 // don't print "1 returned" from shell -#define EW_EXEC 0x40 // executable files -#define EW_PATH 0x80 // search in 'path' too -#define EW_ICASE 0x100 // ignore case -#define EW_NOERROR 0x200 // no error for bad regexp -#define EW_NOTWILD 0x400 // add match with literal name if exists -#define EW_KEEPDOLLAR 0x800 // do not escape $, $var is expanded +/// Flags for expand_wildcards() +enum { + EW_DIR = 0x01, ///< include directory names + EW_FILE = 0x02, ///< include file names + EW_NOTFOUND = 0x04, ///< include not found names + EW_ADDSLASH = 0x08, ///< append slash to directory name + EW_KEEPALL = 0x10, ///< keep all matches + EW_SILENT = 0x20, ///< don't print "1 returned" from shell + EW_EXEC = 0x40, ///< executable files + EW_PATH = 0x80, ///< search in 'path' too + EW_ICASE = 0x100, ///< ignore case + EW_NOERROR = 0x200, ///< no error for bad regexp + EW_NOTWILD = 0x400, ///< add match with literal name if exists + EW_KEEPDOLLAR = 0x800, ///< do not escape $, $var is expanded + EW_ALLLINKS = 0x1000, ///< also links not pointing to existing file + EW_SHELLCMD = 0x2000, ///< called from expand_shellcmd(), don't check + ///< if executable is in $PATH + EW_DODOT = 0x4000, ///< also files starting with a dot + EW_EMPTYOK = 0x8000, ///< no matches is not an error + EW_NOTENV = 0x10000, ///< do not expand environment variables + EW_NOBREAK = 0x20000, ///< do not invoke breakcheck +}; // Note: mostly EW_NOTFOUND and EW_SILENT are mutually exclusive: EW_NOTFOUND // is used when executing commands and EW_SILENT for interactive expanding. -#define EW_ALLLINKS 0x1000 // also links not pointing to existing file -#define EW_SHELLCMD 0x2000 // called from expand_shellcmd(), don't check - // if executable is in $PATH -#define EW_DODOT 0x4000 // also files starting with a dot -#define EW_EMPTYOK 0x8000 // no matches is not an error -#define EW_NOTENV 0x10000 // do not expand environment variables -#define EW_NOBREAK 0x20000 // do not invoke breakcheck /// Return value for the comparison of two files. Also @see path_full_compare. typedef enum file_comparison { diff --git a/src/nvim/shada.c b/src/nvim/shada.c index d288c36f65..819fbcf885 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1117,7 +1117,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) } HistoryMergerState hms[HIST_COUNT]; if (srni_flags & kSDReadHistory) { - for (HistoryType i = 0; i < HIST_COUNT; i++) { + for (int i = 0; i < HIST_COUNT; i++) { hms_init(&hms[i], (uint8_t)i, (size_t)p_hi, true, true); } } @@ -1381,7 +1381,7 @@ shada_read_main_cycle_end: // memory for the history string itself and separator character which // may be assigned right away. if (srni_flags & kSDReadHistory) { - for (HistoryType i = 0; i < HIST_COUNT; i++) { + for (int i = 0; i < HIST_COUNT; i++) { hms_insert_whole_neovim_history(&hms[i]); clr_history(i); int *new_hisidx; @@ -2499,7 +2499,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef bool dump_history = false; // Initialize history merger - for (HistoryType i = 0; i < HIST_COUNT; i++) { + for (int i = 0; i < HIST_COUNT; i++) { int num_saved = get_shada_parameter(hist_type2char(i)); if (num_saved == -1) { num_saved = (int)p_hi; @@ -2893,7 +2893,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef #undef PACK_WMS_ARRAY if (dump_history) { - for (size_t i = 0; i < HIST_COUNT; i++) { + for (int i = 0; i < HIST_COUNT; i++) { if (dump_one_history[i]) { hms_insert_whole_neovim_history(&wms->hms[i]); HMS_ITER(&wms->hms[i], cur_entry, { @@ -2913,7 +2913,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef } shada_write_exit: - for (size_t i = 0; i < HIST_COUNT; i++) { + for (int i = 0; i < HIST_COUNT; i++) { if (dump_one_history[i]) { hms_dealloc(&wms->hms[i]); } diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 7ef10c0acd..4ebd2acc1d 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -705,6 +705,7 @@ static void handle_raw_buffer(TermInput *input, bool force) const size_t bufsize = termkey_get_buffer_size(input->tk); const bool success = termkey_set_buffer_size(input->tk, MAX(bufsize + delta, bufsize * 2)); assert(success); + (void)success; } size_t consumed = termkey_push_bytes(input->tk, ptr, size); @@ -731,6 +732,7 @@ static void handle_raw_buffer(TermInput *input, bool force) // shrink it back down to its original size. const bool success = termkey_set_buffer_size(input->tk, INPUT_BUFFER_SIZE); assert(success); + (void)success; } }