flutter-tools.nvim icon indicating copy to clipboard operation
flutter-tools.nvim copied to clipboard

[Bug]: LSP not starting for dart-only projects

Open nank1ro opened this issue 3 years ago • 11 comments

First of all thank you a lot for this plugin. I'm coming from coc, coc-flutter and I have to say that with nvim-lsp-config and your plugin everything is faster.

Describe the bug The LSP is not starting for dart-only projects. For flutter projects everything works fine. I'm using NvChad, and here it is the packer init.lua config about flutter-tools:

use {
    "akinsho/flutter-tools.nvim",
    requires = {
        "mfussenegger/nvim-dap",
        "nvim-lua/plenary.nvim"
    },
    event = "VimEnter",
    config = function()
        require("flutter-tools").setup {
            ui = {
                border = "rounded"
            },
            decorations = {
                statusline = {
                    app_version = true,
                    device = true
                }
            },
            debugger = {
                enabled = true,
                run_via_dap = true,
                register_configurations = function(paths)
                    require("dap").configurations.dart = {}
                    require("dap.ext.vscode").load_launchjs()
                end
            },
            flutter_path = "~/development/flutter",
            flutter_lookup_cmd = nil,
            fvm = true,
            widget_guides = {
                enabled = false
            },
            closing_tags = {
                highlight = "ErrorMsg",
                prefix = ">",
                enabled = true
            },
            dev_log = {
                enabled = false,
                open_cmd = "tabedit"
            },
            dev_tools = {
                autostart = false,
                auto_open_browser = false
            },
            outline = {
                open_cmd = "30vnew",
                auto_open = false
            }
        }
    end,
    
    setup = function()
        require("core.utils").packer_lazy_load "flutter-tools.nvim"
    end
}

Inside the README.md you said to don't configure dartls because it is already being done by this plugin. In fact, with the Flutter projects all works fine, but when I open a dart-only project the LSP doesn't start. I've looked inside this plugin code and I noticed that you enable it on all *.dart files, so it should work, right?

If this is the expected behaviour, may I know how to configure the dartls to start only on non-flutter projects.

To Reproduce Steps to reproduce the behavior:

  1. Go to a Dart-only project with nvim
  2. See LSP not starting

Expected behavior Have the LSP working

System information

  • OS: macOS Monterey 12.1
  • Flutter version: 2.8.1
  • Is flutter in $PATH: Yes
  • neovim version: 0.6.1

nank1ro avatar Jan 07 '22 16:01 nank1ro

Hi @nank1ro,

Thanks for reporting this. Ideally this should also work on dart only projects but tbh I only work with flutter + dart so don't often test in dart only environments. Can you have a look at your lsp logs to see if you have any errors being reported. You can do this by running the :edit command on the file output by running :lua vim.lsp.get_log_path()

akinsho avatar Jan 09 '22 17:01 akinsho

Hi @akinsho thank you for your reply :) The lsp.log simply contains [START][2022-01-09 20:16:32] LSP logging initiated, no errors are present.

The command LspInfo returns: Screenshot 2022-01-09 at 20 18 12

While for Flutter projects I see that there is 1 attached server

nank1ro avatar Jan 09 '22 19:01 nank1ro

@nank1ro can you confirm that the project has a .git folder and also a pubspec.yaml?

akinsho avatar Jan 10 '22 09:01 akinsho

@akinsho yes I confim. You can reproduce the issue simply running these commands:

dart create -t console-full dart-only-proj
cd dart-only-proj
git init
vim lib/dart_only_proj.dart

After entering in this project this error happend:

Spawning language server with cmd: `~/bin/dart` failed. The language server is either not installed, missing from PATH, or not executable.
Error detected while processing VimEnter Autocommands for "*":
E5108: Error executing lua ...vim/site/pack/packer/opt/packer.nvim/lua/packer/load.lua:165: Vim(echomsg):E114: Missing quote: "Error in packer_compiled: ...vim/site/pack/packer/opt/packer.nvim/lua/packer/load
.lua:155: Vim(lua):E5108: Error executing lua ...l/Cellar/neovim/0.6.1/share/nvim/runtime/lua/vim/lsp.lua:1154: client_id: expected number, got nil
stack traceback:
        [C]: in function 'cmd'
        ...vim/site/pack/packer/opt/packer.nvim/lua/packer/load.lua:165: in function <...vim/site/pack/packer/opt/packer.nvim/lua/packer/load.lua:161>
        [string ":lua"]:1: in main chunk

The requested dart bin is not in ~/bin/dart but in:

> which dart
/Users/alex/development/flutter/bin/dart

nank1ro avatar Jan 10 '22 10:01 nank1ro

I may have an idea about the cause. If I have fvm set to true on Flutter projects the error is not presented and the LSP starts. If I set fvm to false, also Flutter projects show the same error.

While on Dart projects I cannot setup fvm (it's only for flutter)

nank1ro avatar Jan 11 '22 09:01 nank1ro

@nank1ro do you have fvm installed or any of it's files setup somewhere above your project?

akinsho avatar Jan 11 '22 09:01 akinsho

@akinsho yes I have fvm installed and in the working flutter projects I see the .fvm folder in the root. While on Dart-only projects cannot be setup and there isn't the .fvm folder at the project root.

nank1ro avatar Jan 11 '22 09:01 nank1ro

@nank1ro I think this might be because at least by this plugins standards your setup is a little complex, I'm guessing that you have flutter installed in a custom directory via fvm maybe in but are using the plugin without fvm in a dart only project since you have to but don't have dart independently installed right i.e. you depend on the dart in the custom flutter install directory in which case this plugin won't have any idea how to resolve the path to your dart bin. You can add in a flutter_path manually which might help

akinsho avatar Jan 11 '22 09:01 akinsho

@akinsho if you see the first comment, I already set the flutter_path manually to: flutter_path = "~/development/flutter". I'm going to try to install the Dart SDK directly and I'll let you know if it works

nank1ro avatar Jan 11 '22 10:01 nank1ro

I've installed dart with brew. Then copied all the bin content to ~/bin but still nothing, same error happens.

nank1ro avatar Jan 18 '22 08:01 nank1ro

Hi @nank1ro, I use this plugin as my daily dart-non-flutter development tools to replace my dartls configuration and it works I think your problem is because you are using NvChad with that weird lazy loading if you want lazy load, I suggest you to use ft = dart instead.

Here is my packer spec for this plugin

{
  "akinsho/flutter-tools.nvim",
  requires = "nvim-lua/plenary.nvim",
  config = function()
    require("plugin.flutter-tools.config")
    require("plugin.flutter-tools.keymap")
  end,
  ft = "dart",
  event = "BufRead pubspec.yaml",
  module = "flutter-tools",
}

fitrh avatar Apr 21 '22 13:04 fitrh

Going to close

akinsho avatar Oct 01 '22 22:10 akinsho