theniceboy / coc-flutter-tools

Rich Flutter development experience for (Neo)vim
64 stars 5 forks source link
coc dart flutter neovim nodejs nvim

coc-flutter-tools

Flutter support for (Neo)vim

2019-10-07 23-31-40 2019-10-08 00_04_07

What is this?

coc-flutter-tools is an active fork of coc-flutter, that fixes bugs and adds new features.

Big thanks to the author of coc-flutter @iamcco

Features of this fork:

Flutter Outline

Features

Make sure that you have the Flutter SDK path in the PATH environment variable

  • LSP features (power by analysis_server)
  • Auto-completion
  • Diagnostics
  • Auto-formatting
  • Renaming elements
  • Hovering support
  • Signature help
  • Jumping to definitions/implementations/references
  • Highlighting
  • Widget trees (flutter outline)
  • Document symbols
  • Code actions
  • More detail
  • Automatic hot reloading on save
  • Automatically run flutter pub get on pubspec.yaml changes
  • Flutter Dev Server support
  • Snippets (enable with flutter.provider.enableSnippet)
  • Device/Emulator List
  • SDK switching

Installation

:CocInstall coc-flutter-tools

NOTE: The dart-vim-plugin plugin is recommended (for filetype detection and syntax highlighting)

Most likely the extension will find your SDK automatically as long as the flutter command maps to an SDK location on your system.

If you are using a version manager like asdf that maps the flutter command to another binary instead of an SDK location or this extension cannot find your SDK for another reason you'll have to provide the extension with how to find your SDK. To do this there are a few options:

  1. If your version manager supports a which command like then you can set the flutter.sdk.flutter-lookup config option. Eg. "flutter.sdk.flutter-lookup": "asdf which flutter".
  2. You can add the path where to find the SDK to the flutter.sdk.searchPaths config option. Either specify the exact folder the SDK is installed in or a folder that contains other folders which directly have an SDK in them. Note that not all of these folders need to have an SDK, if they don't contain one they will simply be ignored
  3. Set the flutter.sdk.path config option to the exact path you want to use for your SDK. If you have also set the flutter.sdk.searchPaths then you can use the FlutterSdks list (see below) to see what versions you have installed and set the config option for you. Note that this means that the flutter.sdk.path option will be overriden by this list

coc-list sources

Settings

Enable format on save:

If you have dart-vim-plugin install, put this in your vimrc:

let g:dart_format_on_save = 1

Alternatively, you may use coc-settings.

"coc.preferences.formatOnSaveFiletypes": [
  "dart"
],

Code Actions

coc.nvim provides code actions. To enable them, add the following configuration in your vimrc

this can also be found in coc.nvim README

xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)

To show code actions on selected areas:

Then you will see a list of code actions:

Commands

Get a list of flutter related commands: CocList --input=flutter commands

Global Commands:

LSP Commands

Dev Server Commands:

These commands will only be available when the Flutter Dev Server is running (i.e after you run flutter run)

Closing Labels

when flutter.lsp.initialization.closingLabels is set to true, the closing labels will be display at end of closing.

this feature only support neovim since vim do not support virtual text

disabled enabled

UI Path

when flutter.UIPath is set to true, the path for the UI component under cursor will be shown on the status bar. Screen Shot 2020-08-09 at 6 25 10 PM

Flutter Outline

In the Flutter Outline panel, press enter to goto the corresponding location in the source file.

Sponsored by Instaboard