diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2024-01-19 14:51:10 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-19 14:51:10 -0600 |
commit | d3a8e9217f39c59dd7762bd22a76b8bd03ca85ff (patch) | |
tree | 176bbcf0793bab5338614f717f003c385f9c3878 /src | |
parent | 5a8fe0769cc9c5d8323b073d5c45ee37ce91c049 (diff) | |
download | rneovim-d3a8e9217f39c59dd7762bd22a76b8bd03ca85ff.tar.gz rneovim-d3a8e9217f39c59dd7762bd22a76b8bd03ca85ff.tar.bz2 rneovim-d3a8e9217f39c59dd7762bd22a76b8bd03ca85ff.zip |
feat(ui): add chdir UI event (#27093)
When an embedded Nvim instance changes its current directory a "chdir"
UI event is emitted. Attached UIs can use this information however they
wish. In the TUI it is used to synchronize the cwd of the TUI process
with the cwd of the embedded Nvim process.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/ui_events.in.h | 2 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 8 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 8 | ||||
-rw-r--r-- | src/nvim/ui.c | 6 |
4 files changed, 23 insertions, 1 deletions
diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index bda0c72423..c2f02c34f8 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -39,6 +39,8 @@ void screenshot(String path) FUNC_API_SINCE(7); void option_set(String name, Object value) FUNC_API_SINCE(4); +void chdir(String path) + FUNC_API_SINCE(12); // Stop event is not exported as such, represented by EOF in the msgpack stream. void stop(void) FUNC_API_NOEXPORT; diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 09203990bb..d80539708d 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -33,6 +33,7 @@ # include <sys/xattr.h> #endif +#include "nvim/api/private/helpers.h" #include "nvim/ascii_defs.h" #include "nvim/gettext_defs.h" #include "nvim/globals.h" @@ -44,6 +45,7 @@ #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/types_defs.h" +#include "nvim/ui.h" #include "nvim/vim_defs.h" #ifdef HAVE_SYS_UIO_H @@ -90,7 +92,11 @@ int os_chdir(const char *path) smsg(0, "chdir(%s)", path); verbose_leave(); } - return uv_chdir(path); + int err = uv_chdir(path); + if (err == 0) { + ui_call_chdir(cstr_as_string((char *)path)); + } + return err; } /// Get the name of current directory. diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 6b8b73a2a0..f9560ce076 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -1500,6 +1500,14 @@ void tui_option_set(TUIData *tui, String name, Object value) } } +void tui_chdir(TUIData *tui, String path) +{ + int err = uv_chdir(path.data); + if (err != 0) { + ELOG("Failed to chdir to %s: %s", path.data, strerror(err)); + } +} + void tui_raw_line(TUIData *tui, Integer g, Integer linerow, Integer startcol, Integer endcol, Integer clearcol, Integer clearattr, LineFlags flags, const schar_T *chunk, const sattr_T *attrs) diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 8888535878..316342c028 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -384,6 +384,12 @@ void ui_attach_impl(UI *ui, uint64_t chanid) ui_refresh_options(); resettitle(); + char cwd[MAXPATHL]; + size_t cwdlen = sizeof(cwd); + if (uv_cwd(cwd, &cwdlen) == 0) { + ui_call_chdir((String){ .data = cwd, .size = cwdlen }); + } + for (UIExtension i = kUIGlobalCount; (int)i < kUIExtCount; i++) { ui_set_ext_option(ui, i, ui->ui_ext[i]); } |