-
-
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
feat: add vim.filetype.get_option() #22634
Conversation
Nice! Implementation seems a bit hacky, but can't suggest any better. Will definitely use it. |
2f37b6f
to
1da1168
Compare
Are there other filetype-local options that could be interesting (and thus warrant a generic vim.treesitter.get_lang_option)? |
It is what it is. Fundementally we need to load |
Good question. Maybe. |
Quick look: setlocal cinkeys-=0#
setlocal indentkeys-=0#
setlocal include=^\\s*\\(from\\\|import\\)
setlocal define=^\\s*\\(def\\\|class\\)
setlocal includeexpr=...
setlocal suffixesadd=.py
setlocal comments=b:#,fb:-
setlocal omnifunc=python3complete#Complete
setlocal keywordprg=python3\ -m\ pydoc
setlocal isk+=# I don't think we heavily use many (any?) of these. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Omnifunc sounds very useful but would need to be handled at a lower level; same with idk and keywordprg. Would have to be something that plugins need to know about. (If we had comment in core...) |
That should definitely be more generic then... (But hard to make backward compatible.) If we go that route, we should integrate all such options into filetype.lua, which already supports setting filetype options (because filetype.vim does, because why not add another mechanism on top of existing ones). |
I think that would be a reasonable and natural optimization -- not necessarily for this PR, and not until someone complains about performance... |
This comment was marked as resolved.
This comment was marked as resolved.
Well...as per my comments on the other PR, I'm not sure |
fwiw, it can be The interface matters more, and it sounds like we are heading in a good direction here. |
|
Thoughts on the generic function:
|
I think my initial expectation for allowed options in a function |
Sure, that would be one method of validation. |
This comment was marked as resolved.
This comment was marked as resolved.
Thinking about it, to pull this off properly we also need a reverse mapping "parser name -> filetype" to look up the correct commentstring for languages where the parser name is different from the filetype ( (Or any other way of associating language to canonical filetype, no matter how we end up implementing the |
This comment was marked as resolved.
This comment was marked as resolved.
Been thinking about this, and there may be some performance concerns. This is because we need to fire the A good implementation of a commenting function could know about this perf characteristic and decide to keep a short lived local cache, however I would expect other implementation/applications to not take this into account. Due to how dynamic autocmds make this, I don't think it's possible to implement a private cache in The only think I can think of would be to just document that this new |
I agree with the analysis, but since we have to add a caveat either way, we could also say "value is cached and may not update in every situation"? (And wait for complaints to see if these situations are worth supporting.) |
- Also adjust the expr-mapping behaviour so normal commands and text changes are allowed in internal dummy buffers.
1f3da60
to
d038b93
Compare
d038b93
to
e5641df
Compare
Sorry to comment here on a PR that is already merged instead of creating an issue, but I have some issues with LSP attaching to the dummy-buffer and notifiying me of different things, but I don't feel that it's worth a separate issue. I see that lspconfig don't try to attach to a buffer if the Is this something that we can set on the dummy buffer? Or is there some other option already set or something that we can set? I can then send a PR to lspconfig to avoid trying to attach to a buffer with that said option#lewis6991 |
Issue with repro steps please. |
I have tried to come up with something, but I haven't been able to consistently reproduce it with a super minimal config without lspconfig. I can try some more, but I do think it would be nice to have some way to detect a dummy buffer |
The issue needs to be analyzed and understood. The dummy buffer is purely an implementation detail, not something you should be messing with. |
You can replicate everything nvim-lspconfig does with |
I will also try to come up with a repro. I was attempting to replicate the commentstring example from the description and when i have codelens auto refreshing, i get tons of errors about an invalid buffer id. it's also extremely slow (each time you move the cursor takes like 2 seconds), but that is merely tangential. Thanks for all the hard work on Neovim, y'all have been on fire recently!! |
yeah, the snippet is not the best way to realize that (you'd query the commentstring on demand, not run a |
The whole point of |
This is the most minimal I could get it: local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
{
"nvim-treesitter/nvim-treesitter",
config = function()
require("nvim-treesitter.configs").setup({
highlight = {
enable = true,
},
})
end,
priority = 100,
build = ":TSUpdate",
},
{
"neovim/nvim-lspconfig",
config = function()
require("lspconfig")["lua_ls"].setup({})
end,
},
})
vim.keymap.set("n", "gcc", function()
vim.filetype.get_option(vim.bo.ft, "commentstring")
end) I used Then do: Notice that I use (Deleted the message first as I thought for a second I didn't use the minimal config, but I did. So this should reproduce it) |
Repro both issues (LSP and bad cache), should be fixed in #22753 |
@seblj you should never need a package manager for a minimal repro. Best to use this template from gitsigns: vim.o.packpath = '/tmp/nvim/site'
local plugins = {
gitsigns = 'https://github.com/lewis6991/gitsigns.nvim',
-- ADD OTHER PLUGINS _NECESSARY_ TO REPRODUCE THE ISSUE
}
for name, url in pairs(plugins) do
local install_path = '/tmp/nvim/site/pack/test/start/'..name
if vim.fn.isdirectory(install_path) == 0 then
vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
end
end
require('gitsigns').setup{
debug_mode = true, -- You must add this to enable debug messages
-- ADD GITSIGNS CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE
} |
I know... I didn't want to use it but couldn't get it to work without it. Thanks for the snippet from gitsigns! Will use it in the future |
Problem: some API functions that check textlock (usually those that can change curwin or curbuf) can break the cmdwin. Solution: make FUNC_API_CHECK_TEXTLOCK call text_locked() instead, which already checks for textlock, cmdwin and `<expr>` status. Add FUNC_API_CHECK_TEXTLOCK_ALLOW_CMDWIN to allow such functions to be usable in the cmdwin if they can work properly there; the opt-in nature of this attribute should hopefully help mitigate future bugs. Also fix a regression in neovim#22634 that made functions checking textlock usable in `<expr>` mappings.
Problem: some API functions that check textlock (usually those that can change curwin or curbuf) can break the cmdwin. Solution: make FUNC_API_CHECK_TEXTLOCK call text_locked() instead, which already checks for textlock, cmdwin and `<expr>` status. Add FUNC_API_CHECK_TEXTLOCK_ALLOW_CMDWIN to allow such functions to be usable in the cmdwin if they can work properly there; the opt-in nature of this attribute should hopefully help mitigate future bugs. Also fix a regression in neovim#22634 that made functions checking textlock usable in `<expr>` mappings.
Problem: some API functions that check textlock (usually those that can change curwin or curbuf) can break the cmdwin. Solution: make FUNC_API_CHECK_TEXTLOCK call text_locked() instead, which already checks for textlock, cmdwin and `<expr>` status. Add FUNC_API_TEXTLOCK_ALLOW_CMDWIN to allow such functions to be usable in the cmdwin if they can work properly there; the opt-in nature of this attribute should hopefully help mitigate future bugs. Also fix a regression in neovim#22634 that made functions checking textlock usable in `<expr>` mappings, and rename FUNC_API_CHECK_TEXTLOCK to FUNC_API_TEXTLOCK.
Problem: some API functions that check textlock (usually those that can change curwin or curbuf) can break the cmdwin. Solution: make FUNC_API_CHECK_TEXTLOCK call text_locked() instead, which already checks for textlock, cmdwin and `<expr>` status. Add FUNC_API_TEXTLOCK_ALLOW_CMDWIN to allow such functions to be usable in the cmdwin if they can work properly there; the opt-in nature of this attribute should hopefully help mitigate future bugs. Also fix a regression in neovim#22634 that made functions checking textlock usable in `<expr>` mappings, and rename FUNC_API_CHECK_TEXTLOCK to FUNC_API_TEXTLOCK.
Problem
It is not possible to get the default option value for a specific filetype. This is required for a number of applications, including working with treesitter injections, e.g: automatically updating
'commentstring'
based on cursor position.Solution
filetype
option tonvim_get_option_value()
to get the default option value for a specific filetype.vim.filetype.get_option(filetype, option)
as a wrapper aroundnvim_get_option_value()
with caching.Use this to set a context aware commentstring