-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
vim.filetype.add: user extensions can't override builtin patterns #29468
Comments
It works if you add it in the vim.filetype.add({
extension = {
c = "lua",
TEST = "lua",
asm = "lua",
},
pattern = {
['.*%.[sS]'] = "lua",
},
}) This is because patterns always have priority over extensions. However, maybe there should be a way for user extensions to override builtin patterns? |
That is difficult due to the architecture of the filetype detection (if not impossible without a full, burn-it-to-the-ground-first, redesign). I think this should just be documented better, including with a concrete example. (The |
Moving diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index 6dd920e506..48685368f8 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -205,6 +205,10 @@ local extension = {
asm = detect.asm,
lst = detect.asm,
mac = detect.asm,
+ s = detect.asm,
+ S = detect.asm,
+ a = detect.asm,
+ A = detect.asm,
asn1 = 'asn',
asn = 'asn',
asp = detect.asp,
@@ -1741,8 +1745,6 @@ local pattern = {
['.*asterisk/.*%.conf.*'] = starsetf('asterisk'),
['.*asterisk.*/.*voicemail%.conf.*'] = starsetf('asteriskvm'),
['.*/%.aptitude/config'] = 'aptconf',
- ['.*%.[aA]'] = detect.asm,
- ['.*%.[sS]'] = detect.asm,
['[mM]akefile%.am'] = 'automake',
['.*/bind/db%..*'] = starsetf('bindzone'),
['.*/named/db%..*'] = starsetf('bindzone'), I'm not sure if this should be done, as it's indeed done for some filetypes, but for some other filetypes (e.g. case-insensitive one) this may not be a good idea. |
It's also a matter of performance. I don't think we should mess with the logic; it was hard-won. Instead, we just need to explicitly mention that you can only override within a category, so pick the highest one (filename > pattern > extension) that fits. |
I feel that the current behavior isn't ideal. The pattern vs. extension for builtin filetypes is an implementation detail, but the behavior of |
Thanks for the solution @zeertzjq, FWIW I find it unintuitive that some extensions can be overridden, while others can't due to some internal nvim code, even now knowing this priority logic. |
You can override extensions by extensions, but not patterns by extensions. I agree it's unintuitive since it requires knowing implementation details, but there are really good reasons for the way things are now. If in doubt, specify a pattern. |
I think regardless of whatever other decisions we make, we should do this. There's no reason for the pattern table to have patterns like this, this is exactly what the extension table is for. If there are other examples like this, we should move those too. |
Problem
Related: #19996
.s and .S files are not forced and instead recognized as the default "asm" filetype. I've tried:
Steps to reproduce
In init.lua:
only .c, .TEST, and .asm files are overriden correctly
Expected behavior
.s and .S files are correctly forced to the specified types.
Neovim version (nvim -v)
NVIM v0.10.0 Build type: Release LuaJIT 2.1.1716656478
Vim (not Nvim) behaves the same?
Operating system/version
Arch linux, 6.9.6-arch1-1
Terminal name/version
kitty, linux console
$TERM environment variable
xterm-kitty, linux
Installation
Pacman
The text was updated successfully, but these errors were encountered: