iamcco / coc-flutter

flutter support for (Neo)vim
472 stars 38 forks source link
autocomplete coc flutter lsp neovim vim

coc-flutter

Flutter support for (Neo)vim

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

Features

Install

:CocInstall coc-flutter

NOTE: install dart-vim-plugin plugin if your (neo)vim detect filetype incorrect

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

Running the app

When the extension starts and has found an sdk it will request from flutter the available devices. The device it will run the app on will be shown in the statusbar and can be changed using the FlutterDevices list. If you call flutter.run with an explicit -d deviceId argument then the selected device will be ignored.

After making sure that the correct device is selected you can run the app by calling the flutter.run:

:CocCommand flutter.run

If you want to give arguments to the flutter run command you can simply append them:

:CocCommand flutter.run -t lib/main.dart --flavor myflavor

coc-list sources

Settings

Enable format on save:

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

Code Actions

Add below config mapping

this config should be in the coc.nvim README

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

Applying codeAction to the selected region.

Example: <leader>aap for current paragraph, <leader>aw for the current word

Then you will see action list:

Commands

Open flutter only commands list: CocList --input=flutter commands

Global Commands:

LSP Commands

Dev Server Commands:

available when dev server running

Closing Labels

when flutter.lsp.initialization.closingLabels is 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

Buy Me A Coffee ☕️

btc

image