Commit Graph

509 Commits

Author SHA1 Message Date
4cc69f45b4 build: add ubsan default options
Use print_stacktrace=1 for UBSAN by default.
2023-05-15 16:50:58 +02:00
08991b0782 docs: small fixes
Co-authored-by: Christian Clason <c.clason@uni-graz.at>
Co-authored-by: Gregory Anders <greg@gpanders.com>
Co-authored-by: HiPhish <hiphish@posteo.de>
Co-authored-by: Julio B <julio.bacel@gmail.com>
Co-authored-by: T727 <74924917+T-727@users.noreply.github.com>
Co-authored-by: camoz <camoz@users.noreply.github.com>
Co-authored-by: champignoom <66909116+champignoom@users.noreply.github.com>
2023-05-13 21:33:22 +02:00
4f235e3caf fix(tui): position cursor at bottom-left before stopping (#23369)
Fix #23361
2023-04-28 20:26:02 +08:00
5e569a4703 refactor(fs): now it is time to get rid of fs_loop and fs_loop_mutex
Here's the headline: when run in sync mode (last argument cb=NULL),
these functions don't actually use the uv_loop_t.

An earlier version of this patch instead replaced fs_loop with
using main_loop.uv on the main thread and luv_loop() on luv worker
threads. However this made the code more complicated for no reason.

Also arbitrarily, half of these functions would attempt to handle
UV_ENOMEM by try_to_free_memory(). This would mostly happen
on windows because it needs to allocate a converted WCHAR buffer.
This should be a quite rare situation. Your system is pretty
much hosed already if you cannot allocate like 50 WCHAR:s.
Therefore, take the liberty of simply removing this fallback.

In addition, we tried to "recover" from ENOMEM in read()/readv()
this way which doesn't make any sense. The read buffer(s) are already
allocated at this point.

This would also be an issue when using these functions on a worker
thread, as try_to_free_memory() is not thread-safe. Currently
os_file_is_readable() and os_is_dir() is used by worker threads
(as part of nvim__get_runtime(), to implement require from 'rtp' in
threads).

In the end, these changes makes _all_ os/fs.c functions thread-safe,
and we thus don't need to document and maintain a thread-safe subset.
2023-04-25 21:30:19 +02:00
0d2fe77865 refactor(time): refactor delay with input checking
Previously, there were three low-level delay entry points

- os_delay(ms, ignoreinput=true): sleep for ms, only break on got_int

- os_delay(ms, ignoreinput=false): sleep for ms, break on any key input
  os_microdelay(us, false): equivalent, but in μs (not directly called)

- os_microdelay(us, true): sleep for μs, never break.

The implementation of the latter two both used uv_cond_timedwait()
This could have been for two reasons:
 1. allow another thread to "interrupt" the wait
 2. uv_cond_timedwait() has higher resolution than uv_sleep()

However we (1) never used the first, even when TUI was a thread, and
(2) nowhere in the codebase are we using μs resolution, it is always a ms
multiplied with 1000.

In addition, os_delay(ms, false) would completely block the thread for
100ms intervals and in between check for input. This is not how event handling
is done alound here.

Therefore:

Replace the implementation of os_delay(ms, false) to use
LOOP_PROCESS_EVENTS_UNTIL which does a proper epoll wait with a timeout,
instead of the 100ms timer panic.

Replace os_microdelay(us, false) with a direct wrapper of uv_sleep.
2023-04-24 17:38:19 +02:00
b773a52515 refactor(env): remove unused mutex
This was needed when TUI was a thread.
lua code uses os_getenv only on the main thread.
2023-04-20 18:54:00 +02:00
85c61d6716 vim-patch:9.0.1007: there is no way to get a list of swap file names
Problem:    There is no way to get a list of swap file names.
Solution:   Add the swapfilelist() function.  Use it in the test script to
            clean up.  Remove deleting individual swap files.

c216a7a21a

vim-patch:9.0.1005: a failed test may leave a swap file behind

Problem:    A failed test may leave a swap file behind.
Solution:   Delete the swap file to avoid another test to fail.  Use another
            file name.

d0f8d39d20

Cherry-pick test_window_cmd.vim changes from patch 8.2.1593.
Remove FUNC_ATTR_UNUSED from eval functions as fptr is always unused.

Co-authored-by: Bram Moolenaar <Bram@vim.org>
2023-04-19 11:29:35 +08:00
7b05ddbb72 vim-patch:9.0.0397: :defer not tested with exceptions and ":qa!"
Problem:    :defer not tested with exceptions and ":qa!".
Solution:   Test :defer works when exceptions are thrown and when ":qa!" is
            used.  Invoke the deferred calls on exit.

58779858fb

Co-authored-by: Bram Moolenaar <Bram@vim.org>
2023-04-16 15:04:41 +08:00
04933b1ea9 refactor: remove redundant casts 2023-04-07 21:08:16 +02:00
d5f6176e6d refactor: add const and remove unnecessary casts (#22841) 2023-04-01 08:49:51 +08:00
b02880593e build(win): export extern symbols for use in FFI #22756
Makes `extern` variables accessible through ffi on Windows.

Follow-up to https://github.com/neovim/neovim/pull/15999
2023-03-23 04:58:50 -07:00
7dc9182cf0 vim-patch:8.2.1398: autoload script sourced twice if sourced directly (#22622)
Problem:    Autoload script sourced twice if sourced directly.
Solution:   Do not source an autoload script again. (issue vim/vim#6644)

daa2f36573

Cherry-pick ret_sid changes from patch 8.2.0149.
Use do_in_runtimepath() as that's what source_runtime() calls in Nvim.

Co-authored-by: Bram Moolenaar <Bram@vim.org>
2023-03-11 21:29:25 +08:00
0775858703 build: fix unknown pragma warning with mingw (#22533)
This checks MSVC toolchain with _MSC_VER macro before adding
pragma warning directive. It is specific to MSVC and shows
compiler warning with mingw gcc as following:

main.c:187: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
  187 | # pragma warning(suppress : 4996)
2023-03-05 21:52:32 +08:00
1b3c1f6c06 refactor(build): graduate HAVE_LOCALE_H feature
Merge locale.h into os/lang.h
Having a source file with the same name as a system header we use is
considered an anti-pattern.
2023-03-03 14:19:46 +01:00
cf07f2baab feat(edit)!: remove old c implementation of hebrew keymap
This feature has long been obsolete. The 'keymap' option can be used
to support language keymaps, including hebrew and hebrewp (phonetic
mapping). There is no need to keep the old c code with hardcoded
keymaps for some languages.
2023-02-28 15:14:03 +01:00
f1816f9ee2 refactor(main.c): remove unreachable use_builtin_ui conditions (#22338)
When use_builtin_ui is true, Nvim will exit before line 385 is reached.
2023-02-20 15:13:55 +08:00
b62c0c8d9c docs: fix typos (#21961)
Co-authored-by: Ben Morgan <cassava@iexu.de>
2023-02-20 15:12:59 +08:00
ec782211f2 fix(tui): set taskbar, icon in Windows #22270
Problem: After TUI refactor commit, code for setting Windows taskbar
icon wasn't being executed because of a backdated conditional.

Solution: Update the conditional to take TUI refactor into account.

Ref: https://github.com/neovim/neovim/pull/20634#discussion_r1088993820
2023-02-15 07:39:23 -08:00
1539f71363 Merge #22214 move init_default_autocmds to lua 2023-02-14 19:13:12 -05:00
27177e5819 refactor: reduce scope of locals as per the style guide (#22211) 2023-02-11 14:14:24 +01:00
c5b34fa554 refactor: move init_default_autocmds to lua
The original motivation for this change came from developping
https://github.com/neovim/neovim/pull/22159, which will require adding
more autocommand creation to Neovim's startup sequence.

This change requires lightly editing a test that expected no autocommand
to have been created from lua.
2023-02-11 14:02:17 +01:00
7d58de11f4 fix(rpc)!: preseve files when stdio channel is closed (#22137)
BREAKING CHANGE: Unsaved changes are now preserved rather than discarded
when stdio channel is closed.
2023-02-11 18:25:01 +08:00
4be6c6cf0d refactor: replace char_u with char (#21901)
refactor: replace char_u with char

Work on https://github.com/neovim/neovim/issues/459
2023-02-11 11:05:57 +01:00
7224c889e0 build: enable MSVC level 3 warnings (#21934)
MSVC has 4 different warning levels: 1 (severe), 2 (significant), 3
(production quality) and 4 (informational). Enabling level 3 warnings
mostly revealed conversion problems, similar to GCC/clang -Wconversion
flag.
2023-02-11 10:25:24 +01:00
69bb145cea refactor(exit): pass error message to preserve_exit() (#22097)
Problem:
1. Some calls to preserve_exit() don't put a message in IObuff, so the
   IObuff printed by preserve_exit() contains unrelated information.
2. If a TUI client runs out of memory or receives a deadly signal, the
   error message is shown on alternate screen and cannot be easily seen
   because the TUI exits alternate screen soon afterwards.

Solution:
Pass error message to preserve_exit() and exit alternate screen before
printing it.

Note that this doesn't fix the problem that server error messages cannot
be easily seen on exit. This is tracked in #21608 and #21843.
2023-02-04 20:14:31 +08:00
2c5906b55b fix(exit): skip unnecessary steps in TUI preserve_exit() (#21897)
This prevents the TUI from doing unexpected things when receiving a
deadly signal or running out of memory.
2023-02-02 10:05:03 +08:00
d6d6ab3f8e feat(lua): low-level interpreter mode (nvim -ll) 2023-01-31 13:53:22 +01:00
c6ab8dfc15 revert: "refactor(win_close): remove "force", don't pass on "free_buf" (#21921)" (#21979)
This reverts commit 0371d0f7af.

> 'bufhidden' option exists. I don't think we should assume autoclosing
windows are fine just because 'hidden' is set.
2023-01-24 18:31:07 +08:00
0371d0f7af refactor(win_close): remove "force", don't pass on "free_buf" (#21921)
Problem:
The "force" flag of win_close() complicates the code and adds edge cases
where it is not clear what the correct behavior should be.
The "free_buf" flag of win_close() is passed on to float windows when
closing the last window of a tabpage, which doesn't make much sense.

Solution:
Remove the "force" flag and always close float windows as if :close! is
used when closing the last window of a tabpage, and set the "free_buf"
flag for a float window based on whether its buffer can be freed.
As 'hidden' is on by default, this change shouldn't affect many people.
2023-01-23 18:55:11 +08:00
b36b58d0d4 fix(Windows): restore console title at exit #21922
Fixes #21404
2023-01-23 01:45:18 -08:00
fb805bb8b7 fix(remote): don't leak memory on failure to connect to server (#21931)
Also fix the race between output and resize in the test for this.
2023-01-21 18:54:17 +08:00
4c531714ff refactor: replace char_u with char 25 (#21838)
refactor: replace char_u with char

Work on https://github.com/neovim/neovim/issues/459
2023-01-19 22:25:56 +08:00
90493beb15 Merge pull request #21831 from bfredl/nofd
fix(ui): re-organize tty fd handling and fix issues
2023-01-16 11:55:34 +01:00
160c69b655 fix(ui): re-organize tty fd handling and fix issues
- Use the correct fd to replace stdin on windows (CONIN)
- Don't start the TUI if there are no tty fd (not a regression,
  but makes sense regardless)
- De-mythologize "global input fd". it is just STDIN.
2023-01-16 11:26:49 +01:00
be3d30cace fix(diff): "nvim -d" should only diff arglist files #21829
Co-authored-by: 0xadk <0xadk@users.noreply.github.com>
2023-01-16 01:37:58 -08:00
3269902a13 refactor: fix IWYU mapping file and use IWYU (#21802)
Also add the EXITFREE definition to main_lib rather than the nvim target, as the header generation needs the EXITFREE flag to work properly.
2023-01-15 14:16:33 +01:00
2065ce877e vim-patch:partial:9.0.1196: code is indented more than necessary (#21796)
Problem:    Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
            closes vim/vim#11813)

e857598896

Partial port as this depends on some previous eval and 'smoothscroll'
patches.

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-01-14 21:36:15 +08:00
f2141de9e4 refactor: replace char_u with char 20 (#21714)
refactor: replace char_u with char

Work on https://github.com/neovim/neovim/issues/459
2023-01-13 07:35:39 +08:00
38140a63fb refactor(pty): remove old logic for inheriting termios from host terminal 2023-01-10 14:04:58 +01:00
50f03773f4 refactor: replace char_u with char 18 (#21237)
refactor: replace char_u with char

Work on https://github.com/neovim/neovim/issues/459
2023-01-09 22:37:34 +08:00
1d16bba4d8 fix(embed): handle stdio in server properly
Rename stdin/stdout in the server, so that RPC data won't get corrupted.
This also restores the use of stderr to write directly to the terminal.
2023-01-09 11:17:11 +01:00
628b717022 refactor: extract code to open stdin for reading 2023-01-05 17:44:12 +01:00
7089f33144 refactor(lua): move _G.arg init to nlua_init() 2023-01-05 17:10:02 +01:00
f43de742e8 feat(lua): execute stdin ("-") as Lua 2023-01-05 17:10:02 +01:00
adef308a59 feat(lua): exit 1 on Lua "-l" script error 2023-01-05 17:10:02 +01:00
45549f031e feat(lua): send "--" literally to Lua "-l" script
Problem:
When "-l" is followed by "--", we stop sending args to the Lua script
and treat "--" in the usual way. This was for flexibility but didn't
have a strong use-case, and has these problems:
- prevents Lua "-l" scripts from handling "--" in their own way.
- complicates the startup logic (must call nlua_init before command_line_scan)

Solution:
Don't treat "--" specially if it follows "-l".
2023-01-05 17:10:02 +01:00
7c94bcd2d7 feat(lua)!: execute Lua with "nvim -l"
Problem:
Nvim has Lua but the "nvim" CLI can't easily be used to execute Lua
scripts, especially scripts that take arguments or produce output.

Solution:
- support "nvim -l [args...]" for running scripts. closes #15749
- exit without +q
- remove lua2dox_filter
- remove Doxyfile. This wasn't used anyway, because the doxygen config
  is inlined in gen_vimdoc.py (`Doxyfile` variable).
- use "nvim -l" in docs-gen CI job

Examples:

    $ nvim -l scripts/lua2dox.lua --help
    Lua2DoX (0.2 20130128)
    ...

    $ echo "print(vim.inspect(_G.arg))" | nvim -l - --arg1 --arg2
    $ echo 'print(vim.inspect(vim.api.nvim_buf_get_text(1,0,0,-1,-1,{})))' | nvim +"put ='text'" -l -

TODO?
  -e executes Lua code
  -l loads a module
  -i enters REPL _after running the other arguments_.
2023-01-05 17:10:02 +01:00
47ba78f89a refactor(ui): devirtualize the ui layer
- The defined interface for the UI is only the RPC protocol. The original
  UI interface as an array of function pointers fill no function.
- On the server, all the UI:s are all RPC channels.
  - ui.c is only used on the server.
  - The compositor is a preprocessing step for single-grid UI:s
- on the client, ui_client and tui talk directly to each other
  - we still do module separation, as ui_client.c could form the basis
    of a libnvim client module later.

Items for later PR:s
- vim.ui_attach is still an unhappy child, reconsider based on plugin experience.
- the flags in ui_events.in.h are still a mess. Can be simplified now.
- UX for remote attachment needs more work.
- startup for client can be simplified further (think of the millisecs we can save)
2023-01-05 09:48:26 +01:00
c3d8665851 fix(exit): the TUI should not ui_flush() itself (#21625) 2023-01-03 17:21:42 +08:00
43e8ec92de fix(tui): more work in the TUI 2022-12-31 13:25:26 +01:00