Support code completion
MarkBennett opened this issue · 22 comments
This may not be possible, but it would wonderful if the vim plugin could somehow use the dart analyzer to determine the type of an object and provide context specific completion.
Up! 👍 :)
Patches welcome! This library doesn't have an owner.
FWIW - some ideas in this area would be to use the YouCompleteMe plugin. I know the Dart analyzer team is planning to have a service, so you can launch the analzyer as a server and interact with it via sockets. Once that's available, I believe it will be easier to make it work.
Bump. Is there news on the dart server?
@jwren how are things looking with the analyzer service?
I don't bandwidth to author completion for vim, but I'm more than happy to code review & merge pull requests if someone else wants to give it a shot!
Analysis server is one of our top priorities and we continue to make great progress on it. Moving to analysis server is still the plan, but I don't have a specific timeline for you.
From the 1.9 release announcement:
The Dart Analyzer has moved to the Dart Analysis Server. This makes it much easier to integrate Dart source analysis into IDE’s beyond the Dart Editor (for instance, IntelliJ and Sublime).
Appears the Dart Analysis Server is now available.
Yes, Specification for the analysis server is here. Editor/ Eclipse plugin both use the code completion from the analysis server. Complete spec for the analysis server is below.
It should be pretty straightfoward to write a plugin for https://github.com/Valloric/ycmd. Not only would that enable errors, completion, and jump to def in vim (via YouCompleteMe, which this project was separated from for modularity), but also in emacs and atom according to the readme.
Oh I see @sigmundch already said that, nevermind.
Cool!
On Sat, May 16, 2015 at 1:40 AM, sigmundch notifications@github.com wrote:
@polux https://github.com/polux that's awesome!
—
Reply to this email directly or view it on GitHub
#5 (comment)
.
Erik Ernst - Google Danmark ApS
Skt Petri Passage 5, 2 sal, 1165 København K, Denmark
CVR no. 28866984
For those interested, we just made available an untested prototype of using the dart analysis server from YouCompleteMe. This was mainly the code @polux did a while back with some tweaks from me and @cbracken.
We unfortunately haven't had the time to get this cleaned up and landed in YouCompleteMe, if any of you out there wants to help in that process, please do! There are some bugs that need fixing (see below), some style changes to match YCM style guide, and it needs tests.
To try out this prototype you basically need to checkout a branch on our repo, which happens to be based on a very old commit of ycm at this moment. Here are more details:
Install Vundle
First clone Vundle into your ~/.vim/bundle directory:
mkdir -p ~/.vim/bundle
cd ~/.vim/bundle
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vimEdit your .vimrc file to configure Vundle. Near the top:
set nocompatible
filetype off
" Configure Vundle
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Bundle 'Valloric/YouCompleteMe'
Plugin 'dart-lang/dart-vim-plugin'
call vundle#end()
filetype plugin indent on
syntax on
set tabstop=2
set shiftwidth=2
set expandtab
" Set Dart SDK location
let g:ycm_dart_bin_folder_path = '/the/path/to/your/dart-sdk/bin'From the command line, invoke Vundle's PluginInstall command to install
YouCompleteMe and dart-vim-plugin:
vim +PluginInstall +qallBuild YouCompleteMe's support binaries:
sudo apt-get install cmake # required by install.sh
cd ~/.vim/bundle/YouCompleteMe
./install.sh --clang-completerGet the Dart support branch
(eventually the code in https://github.com/sigmundch/YouCompleteMe/ and https://github.com/sigmundch/ycmd/ should get merged upstream)
cd ~/.vim/bundle/YouCompleteMe/third_party/ycmd
git remote add clone https://github.com/sigmundch/ycmd
git checkout clone/dart_support
cd ~/.vim/bundle/YouCompleteMe
git remote add clone https://github.com/sigmundch/YouCompleteMe
git checkout clone/dart_supportYou can also try to merge the changes into the latest master, but we haven't done so recently and you may run into merge conflicts.
Optional Configuration
Optionally, set any of the following configuration in your .vimrc:
" Turn off Syntastic gutter markers
let g:ycm_show_diagnostics_ui = 1
let g:ycm_enable_diagnostic_signs = 0
let g:ycm_enable_diagnostic_highlighting = 1
let g:ycm_echo_current_diagnostic = 1
" Highlight errors and warnings with red/magenta undercurl
hi SpellBad term=none ctermbg=none cterm=undercurl ctermfg=Red gui=undercurl guisp=Red
hi SpellCap term=none ctermbg=none cterm=undercurl ctermfg=Magenta gui=undercurl guisp=Magenta
" Use C-] to jump to definition
nmap <C-]> :YcmCompleter GoToDefinition<CR>Known Issues
- Shifted error highlighting: after iterating on a file for a while, you may see that error highlighting areas are displaced by some offset.
- Slow startup: For large code-bases it can take several seconds to get the full power of the analysis server available. A new server is started whenever you close and reopen vim, so you may have a better experience if you keep your session open for a while.
- Most commands are asynchronous and will not block vim, but go-to-definition is not. If the analysis server is not yet available, using go-to-definition might freeze your vim session for a few seconds.
- It's hard to see the state of the server from within vim (e.g. whether it's running, whether it is working as expected or not). Sometimes features stop working and it's not obvious why.
For anyone who installed @sigmundch's prototype above, if you're getting YCM auto-completion for Dart but you aren't getting diagnostics to show, here's a quick manual patch to enable them:
Edit ~/.vim/bundle/YouCompleteMe/python/ycm/youcompleteme.py (assuming a standard Vundle installation). At or near line 105, you should see the following:
DIAGNOSTIC_UI_FILETYPES = set( [ 'cpp', 'cs', 'c', 'objc', 'objcpp' ] )
Change this line to:
DIAGNOSTIC_UI_FILETYPES = set( [ 'cpp', 'cs', 'c', 'objc', 'objcpp', 'dart' ] )
and diagnostic messages should start showing up when you edit Dart code.
The latest prototype is actually here:
https://github.com/cbracken/ycmd
Forgot this issue was still open here. There's a detailed set of instructions on setup that's maintained internally at Google. I'll get those open-sourced. Unfortunately I'm on holiday at the moment, but will take a look in a week and a half when I'm back.
Is dart ycmd support any closer to being upstreamed?
At this point the main blockers are:
- A bit of code cleanup.
- Add tests.
- Find maintainer(s) for this code.
The biggest issue is really the last one. Right now this is a 20% project of a 20% project for me and the others involved. If someone's willing to ensure that issues in YCMD get dealt with promptly, then I think the main blocker is getting tests written. Only thing to be aware of is that YCMD uses a very particular style, so the tests would need to be written with that in mind.
@cbracken well, I checked the repository but I guess you didn't make those internal google documents open source yet did you? :)
@razvanc-r Apologies for the delay in getting back to you. Here's how to apply the patch -- adjust your directories as necessary for your setup:
- Download the patch:
curl -o /tmp/dart_support.patch https://github.com/cbracken/ycmd/commit/aa7c2245ea96e52e1342175db83857382a7137b6.patch
- Apply the patch to YCMD:
cd .vim/bundle/YouCompleteMe/third_party/ycmd
patch -p1 < /tmp/dart_support.patch
Going to close this as adding code completion support to the vim Dart plugin is likely out of scope given the alternatives. If anyone is willing to help write tests and help maintain the YCM support, I'm more than happy to work on getting it upstreamed.
One other option is this: https://github.com/natebosch/dart_language_server
To clarify, you can use dart_language_server via https://github.com/natebosch/vim-lsc
