Skip to content
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

[BUG]: widgets.sidebar.toggle() causes incremental lag (js-debug-adapter) #1176

Open
serranomorante opened this issue Mar 23, 2024 · 3 comments

Comments

@serranomorante
Copy link

serranomorante commented Mar 23, 2024

Debug adapter definition and debug configuration

Notice how toggling the sidebar gets more and more slow (I'm toggling it at a fast speed but it doesn't respond)

nvim-dap-sidebar-2024-03-23_21.54.13.webm

Debug adapter version

js-debug-adapter 1.88.0
nvim nightly

Steps to Reproduce

Create and start a dummy react app (javascript)

npx create-react-app my-app
cd my-app
npm start

Reproduction steps on Neovim

Copy the repro.lua code snippet and open nvim with nvim --clean +'so repro.lua' and wait for nvim plugins to get automatically installed
Install js-debug-adapter with MasonInstall js-debug-adapter
Open the App.js file on my-app/src/App.js
Set a breakpoint on the return statement with lua require'dap'.toggle_breakpoint()
Start the debug session with lua require'dap'.continue()
Start toggling the sidebar with <leader>ds. Repeat this keymap and you will notice the slow down.

-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")
root = root:sub(-1) == "/" and root or root .. "/"
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. name
end

vim.g.mapleader = " "

--------------------------------------------------------------------------------

local plugins = {
  {
    "williamboman/mason.nvim",
    lazy = false,
    cmd = "Mason",
    opts = {
      ui = {
        check_outdated_packages_on_open = false,
        keymaps = {
          update_all_packages = "noop",
        },
      },
      install_root_dir = root .. "/mason",
    },
  },
  {
    "mfussenegger/nvim-dap",
    config = function()
      local dap = require("dap")
      local mason_registry = require("mason-registry")
      local vscode_js_debug_dap = mason_registry.get_package("js-debug-adapter")
      if vscode_js_debug_dap then
        local dap_executable = vscode_js_debug_dap:get_install_path() .. "/js-debug/src/dapDebugServer.js"

        for _, type in ipairs({
          "node",
          "chrome",
          "pwa-node",
          "pwa-chrome",
          "pwa-msedge",
          "node-terminal",
          "pwa-extensionHost",
        }) do
          local host = "localhost"
          dap.adapters[type] = {
            type = "server",
            host = host,
            port = "${port}",
            executable = {
              command = "node",
              args = { dap_executable, "${port}", host },
            },
          }
        end

        for _, language in ipairs({ "typescript", "javascript", "javascriptreact", "typescriptreact" }) do
          dap.configurations[language] = {
            {
              name = "Test react app",
              type = "pwa-chrome",
              request = "launch",
              url = "http://localhost:3000",
              webRoot = "${workspaceFolder}",
              userDataDir = false,
            },
          }
        end
      end

      local widgets = require("dap.ui.widgets")
      local scopes_sidebar = widgets.sidebar(widgets.scopes, { number = true, wrap = false })
      vim.keymap.set("n", "<leader>ds", scopes_sidebar.toggle, { desc = 'DAP: Toggle "scopes" in sidebar' })
    end,
  },
}

--------------------------------------------------------------------------------

local lazypath = root .. "/plugins/lazy.nvim"
---@diagnostic disable-next-line: undefined-field
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

Expected Result

Toggling shouldn't get more slow the more you execute it

Actual Result

Toggling the sidebar get more slow the more you use it

@serranomorante
Copy link
Author

This issue was mentioned on this discussion: #1171

@mfussenegger
Copy link
Owner

Looks like this might be a js-debug-adapter specific issue, see: microsoft/vscode-js-debug#2119

@serranomorante
Copy link
Author

Looks like this might be a js-debug-adapter specific issue, see: microsoft/vscode-js-debug#2119

Is it? I'm still able to reproduce it even after installing the vscode-js-debug commit that supposedly fixes the performance issue 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants