├── .gitignore ├── .travis.yml ├── .vintrc.yml ├── LICENSE ├── README.md ├── autoload └── lsc │ └── dart.vim ├── doc └── lsc_dart.txt └── ftplugin └── dart.vim /.gitignore: -------------------------------------------------------------------------------- 1 | doc/tags 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - master 4 | 5 | addons: 6 | apt: 7 | update: true 8 | packages: 9 | - python3 10 | - python3-pip 11 | - python3-setuptools 12 | 13 | before_install: 14 | - pip3 install --user vim-vint 15 | 16 | script: 17 | - vint . 18 | -------------------------------------------------------------------------------- /.vintrc.yml: -------------------------------------------------------------------------------- 1 | cmdargs: 2 | severity: style_problem 3 | color: true 4 | policies: 5 | ProhibitImplicitScopeVariable: 6 | enabled: true 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2019, Nate Bosch 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Registers the Dart Analysis Server as a language server with 2 | [`vim-lsc`](https://github.com/natebosch/vim-lsc) 3 | 4 | # Commands 5 | 6 | `:DartOrganizeImports`. Sort and remove unused imports in the current file. 7 | 8 | `:DartToggleMethodBodyType`. With the cursor on either a `return` statement 9 | (when it is the only statement in a method block) or on the `=>` in a method 10 | definition, toggle between the two ways to write the method. If it is an 11 | expression body method (`=>`) convert to a block body (`{}` and a `return`) or 12 | vice versa. Recommended mapping (in `ftplugin/dart.vim`): 13 | 14 | ```viml 15 | noremap tr :DartToggleMethodBodyType 16 | ``` 17 | -------------------------------------------------------------------------------- /autoload/lsc/dart.vim: -------------------------------------------------------------------------------- 1 | function! lsc#dart#register() abort 2 | let l:command = s:FindCommand() 3 | if type(l:command) == type(v:null) | return | endif 4 | let l:config = { 5 | \ 'name': 'Dart Analysis Server', 6 | \ 'command': l:command, 7 | \ 'message_hooks': { 8 | \ 'initialize': { 9 | \ 'initializationOptions': { 10 | \ 'onlyAnalyzeProjectsWithOpenFiles': v:true 11 | \ } 12 | \ }, 13 | \ }, 14 | \ 'notifications': { 15 | \ '$/analyzerStatus': function('HandleStatus'), 16 | \ }, 17 | \} 18 | call RegisterLanguageServer('dart', l:config) 19 | call RegisterLanguageServer('yaml', 'Dart Analysis Server') 20 | call RegisterLanguageServer('html', 'Dart Analysis Server') 21 | endfunction 22 | 23 | function! s:FindCommand() abort 24 | if exists('g:lsc_dart_command_override') 25 | return g:lsc_dart_command_override 26 | endif 27 | if exists('g:lsc_dart_sdk_path') 28 | let l:dart = expand(g:lsc_dart_sdk_path).'/bin/dart' 29 | if !executable(l:dart) 30 | echoerr 'The path "'.l:dart.'" is not executable.' 31 | return v:null 32 | endif 33 | else 34 | let l:dart = 'dart' 35 | endif 36 | let l:cmd = [l:dart, 'language-server', '--client-id', 'vim'] 37 | if get(g:, 'lsc_dart_enable_log', v:false) 38 | let l:log_file = tempname() 39 | call add(l:cmd, '--instrumentation-log-file='.l:log_file) 40 | echom 'Dart instrumentation log: '.l:log_file 41 | endif 42 | return l:cmd 43 | endfunction 44 | 45 | function! s:HandleStatus(method, params) abort 46 | let g:dart_analyzer_status = a:params.isAnalyzing 47 | endfunction 48 | -------------------------------------------------------------------------------- /doc/lsc_dart.txt: -------------------------------------------------------------------------------- 1 | *lsc-dart* Language Server Client config for Dart 2 | 3 | INTRODUCTION *lsc-dart-intro* 4 | 5 | vim-lsc-dart configures the vim-lsc plugin to run the Dart Analysis Server for 6 | `dart` and `yaml` file types. This plugin requires either `dart` or `flutter` to 7 | exist on your path. 8 | 9 | See https://github.com/natebosch/vim-lsc for information about the vim-lsc 10 | plugin. 11 | 12 | 13 | CONFIGURATION *lsc-dart-configure* 14 | 15 | *lsc-dart-command-override* 16 | *g:lsc_dart_command_override* 17 | Define the full command to run for the Dart language server. Overrides the SDK 18 | discovery and any values for |g:lsc_dart_enable_log|, and |g:lsc_dart_sdk_path|. 19 | 20 | *lsc-dart-configure-log* 21 | *g:lsc_dart_enable_log* 22 | Enable the Analysis Server instrumentation log file by setting 23 | `g:lsc_dart_enable_log` to `v:true`. When enabled the analysis server will write 24 | a log to a new temp file. This file will get cleaned up at vim exit. 25 | 26 | *g:lsc_dart_sdk_path* 27 | This plugin should auto detect the location of the Dart SDK as long as there 28 | is a `dart` or `flutter` command available in your `$PATH`. If the detection 29 | fails set `g:lsc_dart_sdk_path` to the path to the Dart SDK directory. This 30 | should be the directory above the `/bin/dart` executable. Flutter has it's own 31 | `dart` executable in addition to the one in the Dart SDK, 32 | `g:lsc_dart_sdk_path` should be the path for the cached Dart SDK, not the 33 | flutter SDK. For example, if you are a flutter user and your flutter SDK is 34 | installed to 35 | `~/development/flutter` use: 36 | > 37 | let g:lsc_dart_sdk_path = '~/development/flutter/bin/cache/dart-sdk' 38 | < 39 | 40 | COMMANDS *lsc-dart-commands* 41 | 42 | *:DartToggleMethodBodyType* 43 | With the cursor on either a `=>` or a `return` which is the only statement in a 44 | method, run `:DartToggleMethodBodyType` to flip between an expression bodied 45 | method (`=>` method) and a block bodied method (a method with `{}` and a 46 | `return` statement). 47 | 48 | *:DartOrganizeImports* 49 | Runs the "Organize Imports" code action to sort imports in the standard order 50 | and remove unused mports. The cursor may be anywhere in a Dart file. 51 | 52 | *:DartAnalysisServerDiagnostics* 53 | Ask the Analysis Server to start a web server with a UI showing diagnostics 54 | about the running server, including configuration and the server's view of file 55 | contents. The URL on `localhost` for the server will be reported once it is 56 | running. This may be useful if things are not behaving as expected. 57 | 58 | 59 | vim:tw=78:sw=4:ts=8:ft=help:norl: 60 | -------------------------------------------------------------------------------- /ftplugin/dart.vim: -------------------------------------------------------------------------------- 1 | if !exists('s:initialized') 2 | call lsc#dart#register() 3 | let s:initialized = v:true 4 | endif 5 | 6 | command! -buffer -nargs=0 DartAnalysisServerDiagnostics 7 | \ call DartDiagnosticServer() 8 | 9 | function! s:DartDiagnosticServer() abort 10 | call lsc#server#userCall('dart/diagnosticServer', v:null, 11 | \ function('EchoServerUrl')) 12 | endfunction 13 | 14 | function! s:EchoServerUrl(result) abort 15 | echom 'Analysis Server Diagnostics: http://localhost:'.string(a:result.port) 16 | endfunction 17 | 18 | command! -buffer -nargs=0 DartToggleMethodBodyType 19 | \ LSClientFindCodeActions '\v\cConvert to (expressionblock) body' 20 | 21 | command! -buffer -nargs=0 DartOrganizeImports 22 | \ LSClientFindCodeActions '\v\cOrganize Imports' 23 | --------------------------------------------------------------------------------