-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve util.root_pattern()
#3621
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most (or all) of util.lua is on the path to deprecation. However, improvements to it, especially simplifications, are still helpful because it makes it easier to understand what is missing from "upstream" Nvim stdlib.
- For each dir level, try all root patterns (instead of all levels for each pattern), returning on the first match. Prefer deeper matches, regardless of which pattern matches, over an earlier pattern matching in a parent dir. - Accept root patterns matching broken symlinks. If the dirent exists, that should be good enough. - perf: don't check/resolve/follow symlinks when matching root patterns - Remove pointless check for file existence (`vim.fn.glob()` already guarantees this) - perf: avoid unnecessary table creations (e.g. used only to concatenate strings; `string.format()` or `..` should be preferred for simple/static string concatenations) - perf: avoid synchronous `vim.loop.fs*()` calls where possible (they tend to be slower than their builtin counterparts) - Account for the fact that functions like `string.match()` and `string.gsub()` return multiple values (e.g. use `return (s:gsub(...))` to return the modified string) - Add types to some of the utils
It's basically ready now, but going through the file one more time, I observed and decided to fix the bug in The way
And it seems to have led to some ugly/hacky code in order to workaround the new (and IMO unintuitive) behavior, and it has caused at least a couple bugs as well (#3508). But that change was over a year ago, and perhaps things were different then. The way I understand it now is that the But anyway, even though it should definitely be changed back to how it was, I understand (now) that that could potentially cause some servers' configuration to break as they may have been changed in the meantime in order to adapt. So just let me know whether to change it, or leave it (hopefully to be addressed later). |
Accept root patterns matching broken symlinks. If the dirent exists, that should be good enough.
perf: don't check/resolve/follow symlinks when matching root patterns
Remove pointless conditionals such as
if match ~= nil then return match
Remove pointless check for file existence (
vim.fn.glob()
already guarantees this)perf: avoid unnecessary table creations (e.g. used only to concatenate strings;
string.format()
or..
should be preferred for simple/static string concatenations)perf: avoid synchronous
vim.loop.fs*()
calls where possible (they tend to be slower than their builtin counterparts)Account for the fact that functions like
string.match()
andstring.gsub()
return multiple values (e.g. usereturn (s:gsub(...))
to return the modified string)Add types to some of the utils