vscode-neovim
vscode-neovim copied to clipboard
Update user's settings.json from vim
Hi, I started using the recent feature of displaying "inlay hints" within the source code and it's great too see all that info real quick, but it would be even better if I could toggle its visibility, since it also makes the code a bit cluttered. Unfortunately there's no toggle command, only a key in settings.json
file.
My hope would be to be able to do something like this:
nnoremap [i <Cmd>call VSCodeSetUserSettingsValue('editor.inlayHints.enabled', 1)<CR>
nnoremap ]i <Cmd>call VSCodeSetUserSettingsValue('editor.inlayHints.enabled', 0)<CR>
So, is there such a function available? If there isn't, would someone kindly give me some hints as to how I could implement such function? I'm not really familiar with VSCode's extension APIs.
https://github.com/vscode-neovim/vscode-neovim/issues/852#issuecomment-1106592180
It looks like the extension API supports updating config values via the
update()
function: code.visualstudio.com/api/references/vscode-api#WorkspaceConfigurationYou could make a very simple extension / modify this extension to add a vscode command that calls that function, and then call that command via
VSCodeNotify
.I know "make a new extension" is not very helpful, but to answer your question yes it certainly seems possible.
There is an extension called "Toggle" (Marketplace, Github) which could be the missing piece.
It allows to map keybindings in VS Code to toggle between settings in the users's settings.json
. What to toggle and which keybinding is used is defined in the keybindings.json
as follows (modified example from the extension's readme):
{
"key": "F3",
"command": "toggle",
"args": {
"id": "minimap",
"value": [
{
"editor.minimap.enabled": true
},
{
"editor.minimap.enabled": false
}
]
}
}
Before attempting to map the function in my init.vim
I tried to validate it using the VIM Command Line in VS Code. However, if I try to pass arguments like …
-
call VSCodeNotify('toggle', { 'id': 'minimap' } )
or -
call VSCodeNotify('toggle', { 'args': { 'id': 'minimap' } })
… this error message is shown:
Please make sure your 'args' is not empty
Yet, there is no error in VS Code's output. What would be the right way to call the function?
Another idea would be to use the Toggle extension to register a keybinding (like F3
in the example above) and then have neovim send a simulated keystroke to VS Code.
Is this even possible using VSCodeNotify()
?
I could not find anything similar done in the advanced examples. I'd be very grateful for any input on that. Thanks a lot in advance.
Just noting for reference:
https://github.com/vscode-neovim/vscode-neovim#invoking-vscode-actions-from-neovim
Yes it is possible to use Toggle or related plugins (like settings cycle) that expose a vscode command, to call that command in nvim.
Please make sure your 'args' is not empty
Yet, there is no error in VS Code's output. What would be the right way to call the function?
You should set the args
as a lua table:
local args = {
id="minimap",
value={
-- Need ["key"] syntax because dot in identifier is not valid
{["editor.minimap.enabled"]=true},
{["editor.minimap.enabled"]=false},
}
}
For info, I needed to add a keybind that changed a setting value and notify a command. I just used notify first to set my settings to the desired value (with each element in value
with the same value), then use the notify a second time.