From 0dc41dfe9a4523ad3084f430019fc7782548021e Mon Sep 17 00:00:00 2001 From: XTY Date: Mon, 20 Oct 2025 13:36:15 +0800 Subject: [PATCH] refactor(vscode): reimplement terminal integration and unify calls to extension API (#6076) ## Description This PR proposes the following changes to the VS Code extra: - Re-implement the VS Code terminal integration (broken since [`2f46974`](https://github.com/LazyVim/LazyVim/commit/2f4697443c0186663ba4421bd4b856e36c3bd7cc#diff-f878104b5415a79ed4bb9036974722cad911327fdd46994e04f5065ff90e9a55), see comment referenced below) - Unify calls to the [extension API](https://github.com/vscode-neovim/vscode-neovim/tree/v1.18.21?tab=readme-ov-file#%EF%B8%8F-api) - Fully adopt the Lua API in favour of the deprecated Vim script functions (see [deprecation notice](https://github.com/vscode-neovim/vscode-neovim/tree/v1.18.21?tab=readme-ov-file#vimscript)) - Centralise `require("vscode")` calls ## Related Issue(s) - Fixes https://github.com/LazyVim/LazyVim/pull/4392#issuecomment-2881395017 ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines. --------- Co-authored-by: Folke Lemaitre --- lua/lazyvim/plugins/extras/vscode.lua | 28 +++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lua/lazyvim/plugins/extras/vscode.lua b/lua/lazyvim/plugins/extras/vscode.lua index 92b7f9f0..1ae459bb 100644 --- a/lua/lazyvim/plugins/extras/vscode.lua +++ b/lua/lazyvim/plugins/extras/vscode.lua @@ -23,6 +23,7 @@ local enabled = { } local Config = require("lazy.core.config") +local vscode = require("vscode") Config.options.checker.enabled = false Config.options.change_detection.enabled = false Config.options.defaults.cond = function(plugin) @@ -36,19 +37,30 @@ vim.api.nvim_create_autocmd("User", { callback = function() -- VSCode-specific keymaps for search and navigation vim.keymap.set("n", "", "Find") - vim.keymap.set("n", "/", [[lua require('vscode').action('workbench.action.findInFiles')]]) - vim.keymap.set("n", "ss", [[lua require('vscode').action('workbench.action.gotoSymbol')]]) + vim.keymap.set("n", "/", function() + vscode.call("workbench.action.findInFiles") + end) + vim.keymap.set("n", "ss", function() + vscode.call("workbench.action.gotoSymbol") + end) + + -- Toggle VS Code integrated terminal + for _, lhs in ipairs({ "ft", "fT", "" }) do + vim.keymap.set("n", lhs, function() + vscode.call("workbench.action.terminal.toggleTerminal") + end) + end -- Navigate VSCode tabs like lazyvim buffers - vim.keymap.set("n", "", "call VSCodeNotify('workbench.action.previousEditor')") - vim.keymap.set("n", "", "call VSCodeNotify('workbench.action.nextEditor')") + vim.keymap.set("n", "", function() + vscode.call("workbench.action.previousEditor") + end) + vim.keymap.set("n", "", function() + vscode.call("workbench.action.nextEditor") + end) end, }) -function LazyVim.terminal() - require("vscode").action("workbench.action.terminal.toggleTerminal") -end - return { { "snacks.nvim",