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
fix(filetype): fix filetype patterns #19218
Conversation
All the |
What do you think about refactoring some patterns by omitting leading and trailing
This should be solved by using |
Hmmm... I think that would make it harder to check, for relatively little technical advantage. But if there's an actual benefit (and it's documented), why not? Especially if it's a matter of consistency (i.e., all patterns have an implicit
I don't think that's it, actually -- a "naked" |
But in any case, the first order of business is to pass the test suite -- that will give us much more confidence when refactoring ;) |
c2535fb
to
8a405ac
Compare
Now all tests are passing except the Git check (@gpanders):
|
For me also the (EDIT: see following collapsed comment chain for explanation; TL;DR on macOS, the actual expanded name is |
This seems to be something to do with actual filename normalization, since After a lot of experimentation, this specific issue seems to be due to I still have no idea why exactly For this PR, I'd therefore suggest
and putting a |
@clason I created a PR on the Vim repo that updates the |
Because we call local path = vim.fn.resolve(vim.fn.fnamemodify(name, ':p')) Maybe we ought to remove that.
We could pass diff --git a/runtime/filetype.lua b/runtime/filetype.lua
index 35bb31edc..a9afbed27 100644
--- a/runtime/filetype.lua
+++ b/runtime/filetype.lua
@@ -12,7 +12,7 @@ vim.api.nvim_create_augroup('filetypedetect', { clear = false })
vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
group = 'filetypedetect',
callback = function(args)
- local ft, on_detect = vim.filetype.match({ buf = args.buf })
+ local ft, on_detect = vim.filetype.match({ buf = args.buf, filename = args.match })
if ft then
vim.api.nvim_buf_set_option(args.buf, 'filetype', ft)
if on_detect then
|
Yes we do since recently. bak = function(path, bufnr)
local root = vim.fn.fnamemodify(path, ':r')
return M.match({ buf = bufnr, filename = root })
end, ) |
Yes, I think that sounds like a good idea. (Sorry, I was on mobile and misremembered; now I checked the actual code :)) |
I just had a chance to test this; either change is sufficient to fix the symlink issue (which is also fixed by @smjonas' port ;)). It does not fix the double slash issue, though, which is due to the (necessary) I think these two changes make sense in themselves (align more closely to upstream behavior) -- can you think of any downside to passing For the double slash issue, I don't see any alternative to either adding a new pattern or removing that (frankly a bit silly) test. |
Isn't the buffer name retrieved anyway if not passed? So it should be working exactly the same, right (plus saving a function call ;))?
I would suggest to simply add the additional pattern |
Thanks! If I can request one last iteration: Could you put the autocommand changes and the removal of the |
Sure, do you want me to also include the "generic fallback" change in the autocommand in this separate commit or in the old one because it's more related to filetype changes? And btw, is that a fix or refactor? |
Good idea; the point is to separate the "infrastructure" changes that (may) have global effect from the changes to individual patterns. I'd say it's a |
…ch function For example on MacOS, /etc/hostname.file is symlinked to /private/etc/hostname.file. We only care about the original file path though.
Thank you, @smjonas, for seeing this through! |
Thank you as well for helping me with this! Seems like Lua filetype detection is almost ready, awesome! 🎉 |
Correct some incorrect filetype patterns and add missing ones to avoid test failures that became evident in #19216.