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

Dartls is Extremely Slow when inserting a new line #2802

Closed
ghost opened this issue Sep 10, 2023 · 8 comments
Closed

Dartls is Extremely Slow when inserting a new line #2802

ghost opened this issue Sep 10, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Sep 10, 2023

Description

Hello.


I have not been using Nvim-lspconfig because I used the Mason, especially Mason-Lspconfig, as a LSP configuration tool. Of course, Mason provides nice UIs and many features for handling the language server protocols that are manipulated by Nvim-Lspconfig. (It it is not true, let me know)

However, Mason started not providing Dartls lsp for some reason. So, I started using Nvim-lspconfig directly to setup the environment for Dart, not through Mason. This is the lua file for configuring Mason. And this part is where I set the Dartls directly.


How I installed Dart

I want to share how I installed Dart because this might have been the problem.

  1. Open this website.
  2. Run the following commands.
    • Installing Homebrew.
      • I added export PATH=/opt/homebrew/bin:$PATH to ~/.zshrc and ~/.bashrc because I had this problem.
    • brew tap dart-lang/dart
    • brew install dart

The below log is what I could see when I run brew info dart.

==> dart-lang/dart/dart: stable 3.1.1, HEAD
SDK
https://dart.dev
Conflicts with:
  dart-beta (because dart-beta ships the same binaries)
/opt/homebrew/Cellar/dart/3.1.1 (987 files, 554.4MB) *
  Built from source on 2023-09-09 at 22:06:13
From: https://github.com/dart-lang/homebrew-dart/blob/HEAD/Formula/dart.rb
==> Options
--HEAD
	Install HEAD version
==> Caveats
Please note the path to the Dart SDK:
  /opt/homebrew/opt/dart/libexec

Dart Version - dart --version

Dart SDK version: 3.1.1 (stable) (Tue Sep 5 12:20:14 2023 +0000) on "macos_arm64"

Like I mentioned, Mason provides countless features for handling the lsps that are manipulated by Nvim-Lspconfig. That is also the reason why I do not know where this problem happens. I thought I had this problem because my computer has problems that I do not know, so I reseted(like, factory reset) my computer but the problem remains.

Neovim version

NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

Nvim-lspconfig version

93c6826

Operating system and version

macOS Ventura 13.5.1

Affected language servers

dartls

Steps to reproduce

  1. Setup Dartls through lspconfig.
-- Dart Setting
require 'lspconfig'.dartls.setup {
  cmd = { "dart", "language-server", "--protocol=lsp" },
  filetypes = { "dart" },
  init_options = {
    closingLabels = true,
    flutterOutline = true,
    onlyAnalyzeProjectsWithOpenFiles = true,
    outline = true,
    suggestFromUnimportedLibraries = true
  },
  settings = {
    dart = {
      completeFunctionCalls = true,
      showTodos = true
    }
  },
}
  1. Open any dart file. something.dart. The file should be in the folder that has pubspec.yaml.
  2. Type something in Dart, and press Enter
  3. You will be waiting for a few seconds to just insert.

Actual behavior

Every time I insert a new line in any types of Dart file, it takes a few seconds without doing anything(maybe it is calculating or something...?).

Expected behavior

What I expect it to do is to NOT take a few seconds every time I insert a new line obviously. Think what happen when you code in TypeScript, does it freeze when you type enter? No. However, it does for some reason.

Minimal config

local on_windows = vim.loop.os_uname().version:match 'Windows'

local function join_paths(...)
  local path_sep = on_windows and '\\' or '/'
  local result = table.concat({ ... }, path_sep)
  return result
end

-- vim.cmd [[set runtimepath=$VIMRUNTIME]]

local temp_dir = vim.loop.os_getenv 'TEMP' or '/tmp'

vim.cmd('set packpath=' .. join_paths(temp_dir, 'nvim', 'site'))
vim.lsp.set_log_level('debug')

local package_root = join_paths(temp_dir, 'nvim', 'site', 'pack')
local lspconfig_path = join_paths(package_root, 'test', 'start', 'nvim-lspconfig')

if vim.fn.isdirectory(lspconfig_path) ~= 1 then
  vim.fn.system { 'git', 'clone', 'https://github.com/neovim/nvim-lspconfig', lspconfig_path }
end

-- vim.lsp.set_log_level 'trace'
require('vim.lsp.log').set_format_func(vim.inspect)

local nvim_lsp = require 'lspconfig'
local on_attach = function(_, bufnr)
  local function buf_set_option(...)
    vim.api.nvim_buf_set_option(bufnr, ...)
  end

  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  -- Mappings.
  local opts = { buffer = bufnr, noremap = true, silent = true }
  vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
  vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
  vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
  vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
  vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
  vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
  vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
  vim.keymap.set('n', '<space>wl', function()
    print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
  end, opts)
  vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
  vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
  vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
  vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
  vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
  vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
  vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
end

-- Add the server that troubles you here
local name = 'dartls'
local cmd = { "dart", "language-server", "--protocol=lsp" } -- needed for elixirls, lua_ls, omnisharp
nvim_lsp[name].setup {
  cmd = cmd,
  on_attach = on_attach,
}

LSP log

https://gist.github.com/cattynip/20b938c15e2c20625fadada5837d0202

@ghost ghost added the bug Something isn't working label Sep 10, 2023
@ghost
Copy link
Author

ghost commented Sep 10, 2023

The reason why I commented vim.cmd [[set runtimepath=$VIMRUNTIME]] is that it makes an error with the theme TokyoNight that I have been using if I enable it. However, when I enabled that and disabled the TokyoNight, taking a few seconds did not happen.

@ghost ghost changed the title Dartls is Extremely Slow when inserting Dartls is Extremely Slow when inserting a new line Sep 10, 2023
@justinmk
Copy link
Member

Can't debug your config for you. This repo is just a set of configs, not a support channel.

@justinmk justinmk closed this as not planned Won't fix, can't repro, duplicate, stale Sep 10, 2023
@themosthigh
Copy link

I fixed it by removing dart from my treesitter ensure_installed options and deleting all my parsers (i only needed to delete the dart.so)

TreeSitter is the problem, not the dart lsp

@ghost
Copy link
Author

ghost commented Jan 6, 2024

Oh, thank you. It is working well right now.

@AlexMeuer
Copy link

Specifically, it appears to be the indentation behaviour of the treesitter. You can check this by disabling indent for the current buffer with :TSBufDisable indent

@Andresdiaz16
Copy link

I fixed this issue by adding the follow line to my Treesitter setup:
indent = { enable = true, disable = {'dart'} },

@themosthigh
Copy link

image

I thinks this issue has finally been fixed

@ghost
Copy link
Author

ghost commented May 30, 2024

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants