├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── doc └── deoplete-rust.txt ├── ftdetect └── rust.vim ├── plugin └── deoplete-rust.vim ├── requirements.txt ├── rplugin └── python3 │ └── deoplete │ └── sources │ └── rust.py └── syntax └── rustdoc.vim /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | python: 4 | - "3.4" 5 | - "3.5" 6 | - "nightly" 7 | 8 | cache: 9 | directories: 10 | - "$HOME/.cache/pip" 11 | 12 | install: 13 | - pip3 install -r requirements.txt 14 | 15 | script: 16 | - vint **/*.vim 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Sebastian Klatt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # deoplete-rust [![Gitter](https://img.shields.io/badge/chat-on%20gitter-11C19C.svg?style=flat-square)](https://gitter.im/sebastianmarkow/deoplete-rust?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) 2 | 3 | [Neovim][neovim]/[Deoplete][deoplete] auto-completion source for [Rust][rust] 4 | via [Racer][racer]. 5 | 6 | Auto-completion: 7 | ![Screenshot auto-completion](https://s31.postimg.org/yilwwkz5n/Bildschirmfoto_2016_07_22_um_21_56_36.png) 8 | 9 | Documentation: 10 | ![Screenshot documentation](https://s31.postimg.org/aeezddlm3/Bildschirmfoto_2016_07_22_um_23_54_10.png) 11 | 12 | ## Requirements 13 | * [Rust][rust] source code 14 | * [Racer][racer] (>=2.0.0) 15 | * [Deoplete][deoplete] 16 | 17 | ### Install Racer 18 | #### with `cargo` 19 | ~~~ 20 | cargo install racer 21 | ~~~ 22 | 23 | #### from source 24 | ~~~ 25 | git clone https://github.com/phildawes/racer.git; cd racer 26 | cargo build --release 27 | ~~~ 28 | 29 | Copy binary to `./target/release/racer` to a location of your choice. 30 | (e.g. to `/usr/local/bin`) 31 | 32 | ### Get Rust source code 33 | ~~~ 34 | mkdir -p choose/a/path 35 | git clone --depth=1 https://github.com/rust-lang/rust.git 36 | ~~~ 37 | 38 | ### Install Deoplete 39 | For details see the [installation guide][installdeoplete] 40 | 41 | ## Installation 42 | ### with `vim-plug` 43 | ~~~ 44 | Plug 'sebastianmarkow/deoplete-rust' 45 | ~~~ 46 | 47 | ### with `Vundle` 48 | ~~~ 49 | Plugin 'sebastianmarkow/deoplete-rust' 50 | ~~~ 51 | 52 | ### with `NeoBundle` 53 | ~~~ 54 | NeoBundle 'sebastianmarkow/deoplete-rust' 55 | ~~~ 56 | 57 | ### with `Pathogen` 58 | ~~~ 59 | git clone --depth=1 https://github.com/sebastianmarkow/deoplete-rust.git path/to/vim/bundle/deoplete-rust 60 | ~~~ 61 | 62 | ## Configuration (`init.vim`) 63 | Set fully qualified path to `racer` binary. If it is in your `PATH` already use 64 | `which racer`. (__required__) 65 | ~~~ 66 | let g:deoplete#sources#rust#racer_binary='/path/to/racer' 67 | ~~~ 68 | 69 | Set Rust source code path (when cloning from Github usually ending on `/src`). 70 | (__required__) 71 | ~~~ 72 | let g:deoplete#sources#rust#rust_source_path='/path/to/rust/src' 73 | ~~~ 74 | 75 | Show duplicate matches. 76 | ~~~ 77 | let g:deoplete#sources#rust#show_duplicates=1 78 | ~~~ 79 | 80 | To disable default key mappings (`gd` & `K`) add the following 81 | ~~~ 82 | let g:deoplete#sources#rust#disable_keymap=1 83 | ~~~ 84 | 85 | Set max height of documentation split. 86 | ~~~ 87 | let g:deoplete#sources#rust#documentation_max_height=20 88 | ~~~ 89 | 90 | ## Usage 91 | ### Default key mappings 92 | These are the default key mappings 93 | ~~~ 94 | nmap gd DeopleteRustGoToDefinitionDefault 95 | nmap K DeopleteRustShowDocumentation 96 | ~~~ 97 | 98 | Additional methods to bind 99 | 100 | Method | Action 101 | --- | --- 102 | `DeopleteRustGoToDefinitionSplit` | Open definition in horizontal split 103 | `DeopleteRustGoToDefinitionVSplit` | Open definition in vertical split 104 | `DeopleteRustGoToDefinitionTab` | Open definition in new tab 105 | 106 | #### `gd` Go to definition 107 | Jump to definition of the current element under the cursor. 108 | 109 | #### `K` Show documentation 110 | Show brief description of the current element under the cursor. 111 | To close press either `q`, `cr` or `esc`. 112 | 113 | #### Show help 114 | You don't have to remember it all. Run `:help deoplete-rust`. 115 | 116 | ## License 117 | deoplete-rust is licensed under MIT License. 118 | For additional information, see `LICENSE` file. 119 | 120 | [installdeoplete]: https://github.com/Shougo/deoplete.nvim#installation 121 | [racer]: https://github.com/phildawes/racer 122 | [neovim]: https://github.com/neovim/neovim 123 | [deoplete]: https://github.com/Shougo/deoplete.nvim 124 | [rust]: https://github.com/rust-lang/rust 125 | -------------------------------------------------------------------------------- /doc/deoplete-rust.txt: -------------------------------------------------------------------------------- 1 | *deoplete-rust.txt* Rust auto-completion via Racer/Deoplete 2 | 3 | Author: Sebastian Klatt 4 | License: MIT License 5 | 6 | ============================================================================== 7 | CONTENTS *deoplete-rust* 8 | 9 | Introduction............................: |deoplete-rust-introduction| 10 | Requirements............................: |deoplete-rust-requirements| 11 | Configuration...........................: |deoplete-rust-configuration| 12 | Usage...................................: |deoplete-rust-usage| 13 | Issues..................................: |deoplete-rust-issues| 14 | 15 | ============================================================================== 16 | REQUIREMENTS *deoplete-rust-requirements* 17 | 18 | These are the requirements to have rust autocompletion in neovim 19 | 20 | racer 21 | rust source code 22 | deoplete 23 | 24 | ------------------------------------------------------------------------------ 25 | Install racer 26 | 27 | With cargo: 28 | > 29 | cargo install racer 30 | < 31 | 32 | From source: 33 | > 34 | git clone https://github.com/phildawes/racer.git; cd racer 35 | cargo build --release 36 | < 37 | Copy binary to ./target/release/racer to a location of your choosing. 38 | (e.g. to /usr/local/bin) 39 | 40 | ------------------------------------------------------------------------------ 41 | Get Rust source code 42 | 43 | Clone from github: 44 | > 45 | mkdir -p choose/a/path 46 | git clone --depth=1 https://github.com/rust-lang/rust.git 47 | < 48 | 49 | ------------------------------------------------------------------------------ 50 | Install Deoplete 51 | 52 | For details see the installation guide. 53 | 54 | 55 | ============================================================================== 56 | CONFIGURATION *deoplete-rust-configuration* 57 | 58 | g:deoplete#sources#rust#racer_binary *g:deoplete#sources#rust#racer_binary* 59 | This variable sets the full path to the racer binary. 60 | e.g. `/usr/bin/racer` or `$HOME/.cargo/bin/racer` 61 | (REQUIRED) 62 | 63 | *g:deoplete#sources#rust#rust_source_path* 64 | g:deoplete#sources#rust#rust_source_path 65 | This variable sets the full path to the rust source. 66 | e.g. `$HOME/rust/src` 67 | (REQUIRED) 68 | 69 | *g:deoplete#sources#rust#show_duplicates* 70 | g:deoplete#sources#rust#show_duplicates 71 | Set whether duplicate matches should be filtered. 72 | Set to 0 to filter duplicates. 73 | Default: 1 74 | (OPTIONAL) 75 | 76 | *g:deoplete#sources#rust#disable_keymap* 77 | g:deoplete#sources#rust#disable_keymap 78 | Set to 1 to disable default keymaps. 79 | See |deoplete-rust-mappings|. 80 | (OPTIONAL) 81 | 82 | *g:deoplete#sources#rust#documentation_max_height* 83 | g:deoplete#sources#rust#documentation_max_height 84 | Set the max height of the documentation preview. 85 | Default: 20 86 | (OPTIONAL) 87 | 88 | ============================================================================== 89 | MAPPINGS *deoplete-rust-mappings* 90 | 91 | gd Jumps to definition of the current element under the cursor. 92 | Reuses the current window if possible. 93 | 94 | K If further documentation exists, it will open a new window and 95 | display the content. 96 | Press `q`, `esc` or `cr`/`enter` to dismiss the window. 97 | 98 | These are the default keymaps. 99 | (to disable, see |g:deoplete#sources#rust#disable_keymap|) 100 | 101 | ------------------------------------------------------------------------------ 102 | Additional commands 103 | 104 | Open definition in horizontal split window. 105 | > 106 | DeopleteRustGoToDefinitionSplit 107 | < 108 | 109 | Open definition in vertical split window. 110 | > 111 | DeopleteRustGoToDefinitionVSplit 112 | < 113 | 114 | Open definition in a new tab. 115 | > 116 | DeopleteRustGoToDefinitionTab 117 | < 118 | 119 | ------------------------------------------------------------------------------ 120 | Example 121 | 122 | Map `gd` to open definition in a horizontal split window. 123 | > 124 | augroup rust-mapping 125 | autocmd! 126 | autocmd filetype rust nmap gd DeopleteRustGoToDefinitionSplit 127 | augroup end 128 | < 129 | 130 | ============================================================================== 131 | ISSUES *deoplete-rust-issues* 132 | 133 | Any issues and suggestions are welcome on the Github bugtracker 134 | https://github.com/sebastianmarkow/deoplete-rust/issues 135 | -------------------------------------------------------------------------------- /ftdetect/rust.vim: -------------------------------------------------------------------------------- 1 | autocmd BufRead,BufNewFile *.rs setlocal filetype=rust 2 | -------------------------------------------------------------------------------- /plugin/deoplete-rust.vim: -------------------------------------------------------------------------------- 1 | if exists('g:loaded_deoplete_rust') 2 | finish 3 | endif 4 | let g:loaded_deoplete_rust=1 5 | 6 | let s:save_cpoptions = &cpoptions 7 | set cpoptions&vim 8 | 9 | let g:deoplete#sources#rust#racer_binary= 10 | \ get(g:, 'deoplete#sources#rust#racer_binary', '') 11 | 12 | let g:deoplete#sources#rust#rust_source_path= 13 | \ get(g:, 'deoplete#sources#rust#rust_source_path', '') 14 | 15 | let g:deoplete#sources#rust#documentation_max_height= 16 | \ get(g:, 'deoplete#sources#rust#documentation_max_height', 20) 17 | 18 | let g:deoplete#sources#rust#show_duplicates= 19 | \ get(g:, 'deoplete#sources#rust#show_duplicates', 1) 20 | 21 | let s:buffer_nr=-1 22 | 23 | function! s:jumpTo(mode, filename, line_nr, column_nr) 24 | if a:mode ==# 'tab' 25 | if bufloaded(a:filename) == 0 26 | tab split 27 | endif 28 | elseif a:mode ==# 'split' 29 | split 30 | elseif a:mode ==# 'vsplit' 31 | vsplit 32 | elseif bufloaded(a:filename) != 0 && bufwinnr(a:filename) != -1 33 | execute bufwinnr(a:filename) . 'wincmd w' 34 | endif 35 | 36 | " FIXME(SK): Throws error if buffer has been modified but changes 37 | " have not been written to disk yet 38 | exec 'edit '.a:filename 39 | call cursor(a:line_nr, a:column_nr) 40 | 41 | normal! zz 42 | endfunction 43 | 44 | function! s:formatDoc(text) 45 | let l:placeholder = '{LITERALSEMICOLON}' 46 | let l:line = substitute(a:text, '\\;', l:placeholder, 'g') 47 | let l:tokens = split(l:line, ';') 48 | let l:desc = substitute(substitute(substitute(substitute(get(l:tokens, 7, ''), '^\"\(.*\)\"$', '\1', ''), '\\\"', '\"', 'g'), '\\''', '''', 'g'), '\\n', '\n', 'g') 49 | let l:tokens = add(l:tokens[:6], l:desc) 50 | let l:tokens = map(copy(l:tokens), 'substitute(v:val, '''.l:placeholder.''', '';'', ''g'')') 51 | 52 | let l:doc = '# '.l:tokens[0].' ['.l:tokens[5].']: `'.l:tokens[6].'`' 53 | 54 | if l:tokens[7] !=# '' 55 | let l:doc = l:doc."\n\n".l:tokens[7] 56 | endif 57 | 58 | return l:doc 59 | endfunction 60 | 61 | function! s:openView(mode, position, content) 62 | if !bufexists(s:buffer_nr) 63 | execute a:mode 64 | sil file `='[RustDoc]'` 65 | let s:buffer_nr = bufnr('%') 66 | elseif bufwinnr(s:buffer_nr) == -1 67 | execute a:position 68 | execute s:buffer_nr . 'buffer' 69 | elseif bufwinnr(s:buffer_nr) != bufwinnr('%') 70 | execute bufwinnr(s:buffer_nr) . 'wincmd w' 71 | endif 72 | 73 | let l:max_height = g:deoplete#sources#rust#documentation_max_height 74 | let l:content_height = len(split(a:content, '\n')) 75 | 76 | if l:content_height > l:max_height 77 | execute 'resize '.l:max_height 78 | else 79 | execute 'resize '.l:content_height 80 | endif 81 | 82 | setlocal filetype=rustdoc 83 | setlocal bufhidden=delete 84 | setlocal buftype=nofile 85 | setlocal noswapfile 86 | setlocal nobuflisted 87 | setlocal nocursorline 88 | setlocal nocursorcolumn 89 | setlocal iskeyword+=: 90 | setlocal iskeyword-=- 91 | setlocal conceallevel=2 92 | setlocal concealcursor=nvic 93 | 94 | setlocal modifiable 95 | %delete _ 96 | call append(0, split(a:content, '\n')) 97 | sil $delete _ 98 | setlocal nomodifiable 99 | sil normal! gg 100 | 101 | noremap q :close 102 | noremap :close 103 | noremap :close 104 | endfunction 105 | 106 | function! s:DeopleteRustShowDocumentation() 107 | if !s:validEnv() 108 | return 109 | endif 110 | 111 | let l:view = winsaveview() 112 | 113 | normal! he 114 | 115 | let l:line_nr = line('.') 116 | let l:column_nr = col('.') 117 | let l:path = expand('%:p') 118 | let l:buf = tempname() 119 | 120 | call writefile(getline(1, '$'), l:buf) 121 | 122 | let l:cmd = g:deoplete#sources#rust#racer_binary.' complete-with-snippet '.l:line_nr.' '.l:column_nr.' '.l:path.' '.l:buf 123 | let l:result = system(l:cmd) 124 | 125 | if v:shell_error 126 | echoerr l:result 127 | return 128 | endif 129 | 130 | call delete(l:buf) 131 | call winrestview(l:view) 132 | 133 | for l:line in split(l:result, "\\n") 134 | if l:result =~# 'ERROR:' 135 | call s:warn(l:line) 136 | break 137 | elseif l:line =~? '^MATCH' 138 | let l:content = s:formatDoc(l:line[6:]) 139 | 140 | if l:content !=# '' 141 | call s:openView('new', 'split', l:content) 142 | endif 143 | break 144 | endif 145 | endfor 146 | endfunction 147 | 148 | function! s:DeopleteRustGoToDefinition(mode) 149 | if !s:validEnv() 150 | return 151 | endif 152 | 153 | let l:line_nr = line('.') 154 | let l:column_nr = col('.') 155 | let l:path = expand('%:p') 156 | let l:buf = tempname() 157 | 158 | call writefile(getline(1, '$'), l:buf) 159 | 160 | let l:cmd = g:deoplete#sources#rust#racer_binary.' find-definition '.l:line_nr.' '.l:column_nr.' '.l:path.' '.l:buf 161 | let l:result = system(l:cmd) 162 | 163 | if v:shell_error 164 | echoerr l:result 165 | return 166 | endif 167 | 168 | call delete(l:buf) 169 | 170 | for l:line in split(l:result, '\\n') 171 | if l:result =~# 'ERROR:' 172 | call s:warn(l:line) 173 | break 174 | elseif l:line =~? '^MATCH' 175 | let l:info = split(l:line[6:], ',') 176 | let l:line_nr = l:info[1] 177 | let l:column_nr = l:info[2] 178 | let l:filename = l:info[3] 179 | 180 | call s:jumpTo(a:mode, l:filename, l:line_nr, l:column_nr+1) 181 | break 182 | endif 183 | endfor 184 | endfunction 185 | 186 | function! s:warn(message) 187 | echohl WarningMsg | echomsg a:message | echohl NONE 188 | endfunction 189 | 190 | function! s:validEnv() 191 | if !executable(g:deoplete#sources#rust#racer_binary) 192 | call s:warn('racer binary path not set (:help deoplete-rust)') 193 | return 0 194 | endif 195 | 196 | if !isdirectory($RUST_SRC_PATH) 197 | if !exists('g:deoplete#sources#rust#rust_source_path') 198 | call s:warn('rust source path not set (:help deoplete-rust)') 199 | return 0 200 | elseif !isdirectory(g:deoplete#sources#rust#rust_source_path) 201 | call s:warn('rust source path not set (:help deoplete-rust)') 202 | return 0 203 | else 204 | let $RUST_SRC_PATH=g:deoplete#sources#rust#rust_source_path 205 | endif 206 | endif 207 | 208 | return 1 209 | endfunction 210 | 211 | function! s:DeopleteRustInit() 212 | nnoremap DeopleteRustGoToDefinitionDefault 213 | \ :call DeopleteRustGoToDefinition('') 214 | nnoremap DeopleteRustGoToDefinitionSplit 215 | \ :call DeopleteRustGoToDefinition('split') 216 | nnoremap DeopleteRustGoToDefinitionVSplit 217 | \ :call DeopleteRustGoToDefinition('vsplit') 218 | nnoremap DeopleteRustGoToDefinitionTab 219 | \ :call DeopleteRustGoToDefinition('tab') 220 | nnoremap DeopleteRustShowDocumentation 221 | \ :call DeopleteRustShowDocumentation() 222 | 223 | if !exists('g:deoplete#sources#rust#disable_keymap') 224 | nmap gd DeopleteRustGoToDefinitionDefault 225 | nmap K DeopleteRustShowDocumentation 226 | endif 227 | endfunction 228 | 229 | augroup deoplete-rust 230 | autocmd! 231 | autocmd filetype rust call s:DeopleteRustInit() 232 | augroup end 233 | 234 | let &cpoptions = s:save_cpoptions 235 | unlet s:save_cpoptions 236 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | neovim>=0.1.9 2 | nose>=1.3.7 3 | pep8>=1.7.0 4 | pylint>=1.6.1 5 | vim-vint>=0.3.6 6 | -------------------------------------------------------------------------------- /rplugin/python3/deoplete/sources/rust.py: -------------------------------------------------------------------------------- 1 | """Rust completion via Racer""" 2 | 3 | import os 4 | import re 5 | import subprocess 6 | import tempfile 7 | 8 | from .base import Base 9 | from deoplete.logger import getLogger 10 | 11 | logger = getLogger('rust') 12 | 13 | VAR_RACER_BINARY = 'deoplete#sources#rust#racer_binary' 14 | VAR_RUST_SOURCE = 'deoplete#sources#rust#rust_source_path' 15 | VAR_DUPLICATION = 'deoplete#sources#rust#show_duplicates' 16 | 17 | 18 | class Source(Base): 19 | """Deoplete Rust source""" 20 | def __init__(self, vim): 21 | Base.__init__(self, vim) 22 | 23 | self.name = 'rust' 24 | self.mark = '[Rust]' 25 | self.filetypes = ['rust'] 26 | self.input_pattern = r'(\.|::)\w*' 27 | self.rank = 500 28 | 29 | self.__racer = self.vim.vars.get(VAR_RACER_BINARY) 30 | self.__dup = self.vim.vars.get(VAR_DUPLICATION) 31 | self.__encoding = self.vim.eval('&encoding') 32 | self.__rust_re = re.compile(r'\w*$|(?<=")[./\-\w]*$') 33 | 34 | if 'RUST_SRC_PATH' not in os.environ: 35 | rust_path = self.vim.vars.get(VAR_RUST_SOURCE) 36 | if rust_path: 37 | os.environ['RUST_SRC_PATH'] = rust_path 38 | 39 | def get_complete_position(self, ctx): 40 | """Missing""" 41 | if not self.__check_binary(): 42 | return -1 43 | 44 | method = self.__rust_re.search(ctx['input']) 45 | return method.start() if method else -1 46 | 47 | def gather_candidates(self, ctx): 48 | """Missing""" 49 | candidates = [] 50 | 51 | lines = self.__retrieve() 52 | matches = [line[6:] for line in lines if line.startswith('MATCH')] 53 | 54 | if not bool(self.__dup): 55 | matches = set(matches) 56 | 57 | for match in matches: 58 | tokens = match.split(",") 59 | candidate = { 60 | 'word': tokens[0], 61 | 'kind': tokens[4], 62 | 'menu': tokens[5], 63 | 'info': ','.join(tokens[5:]), 64 | 'dup': self.__dup, 65 | } 66 | candidates.append(candidate) 67 | 68 | return candidates 69 | 70 | def __retrieve(self): 71 | """Missing""" 72 | content = self.vim.current.buffer 73 | line, column = self.vim.current.window.cursor 74 | 75 | with tempfile.NamedTemporaryFile(mode='w') as buf: 76 | buf.write("\n".join(content)) 77 | buf.flush() 78 | 79 | args = [ 80 | self.__racer, 81 | 'complete', 82 | str(line), 83 | str(column), 84 | content.name, 85 | buf.name 86 | ] 87 | 88 | results = [] 89 | 90 | try: 91 | results = subprocess.check_output(args) \ 92 | .decode(self.__encoding).splitlines() 93 | except Exception: 94 | pass 95 | 96 | return results 97 | 98 | def __check_binary(self): 99 | """Missing""" 100 | return os.path.isfile(self.__racer) and os.environ.get('RUST_SRC_PATH') 101 | -------------------------------------------------------------------------------- /syntax/rustdoc.vim: -------------------------------------------------------------------------------- 1 | scriptencoding utf-8 2 | 3 | if exists("b:current_syntax") 4 | finish 5 | endif 6 | 7 | if !exists('main_syntax') 8 | let main_syntax = 'rustdoc' 9 | endif 10 | 11 | runtime! syntax/html.vim 12 | unlet! b:current_syntax 13 | 14 | let s:syntax_rust_loaded=1 15 | try 16 | syntax include @markdownHighlightRust syntax/rust.vim 17 | catch 18 | let s:syntax_rust_loaded=0 19 | endtry 20 | 21 | syntax sync minlines=10 22 | syntax case ignore 23 | 24 | syntax match markdownLineStart "^[<@]\@!" nextgroup=@markdownBlock 25 | 26 | syntax cluster markdownBlock contains=markdownH1,markdownH2,markdownH3,markdownH4,markdownH5,markdownH6,markdownBlockquote,markdownListMarker,markdownOrderedListMarker,markdownCodeBlock,markdownRule 27 | syntax cluster markdownInline contains=markdownLineBreak,markdownLinkText,markdownItalic,markdownBold,markdownCode,markdownEscape,markdownError 28 | 29 | syntax match markdownHeadingRule "^[=-]\+$" contained 30 | 31 | syntax region markdownH1 matchgroup=markdownHeadingDelimiter start="^\s*#\s*" end="$" concealends oneline contained contains=@markdownInline,markdownAutomaticLink,markdownCodeRust 32 | syntax region markdownH2 matchgroup=markdownHeadingDelimiter start="^\s*##\s*" end="$" concealends oneline contained contains=@markdownInline,markdownAutomaticLink,markdownCodeRust 33 | syntax region markdownH3 matchgroup=markdownHeadingDelimiter start="^\s*###\s*" end="$" concealends oneline contained contains=@markdownInline,markdownAutomaticLink 34 | syntax region markdownH4 matchgroup=markdownHeadingDelimiter start="^\s*####\s*" end="$" concealends oneline contained contains=@markdownInline,markdownAutomaticLink 35 | syntax region markdownH5 matchgroup=markdownHeadingDelimiter start="^\s*#####\s*" end="$" concealends oneline contained contains=@markdownInline,markdownAutomaticLink 36 | syntax region markdownH6 matchgroup=markdownHeadingDelimiter start="^\s*######\s*" end="$" concealends oneline contained contains=@markdownInline,markdownAutomaticLink 37 | 38 | syntax match markdownBlockquote ">\%(\s\|$\)" contained nextgroup=@markdownBlock 39 | 40 | syntax region markdownCodeBlock start=" \|\t" end="$" contained 41 | 42 | syntax match markdownListMarker "\%(\t\| \{0,4\}\)[-*+]\%(\s\+\S\)\@=" contained conceal cchar=• 43 | syntax match markdownOrderedListMarker "\%(\t\| \{0,4}\)\<\d\+\.\%(\s\+\S\)\@=" contained 44 | 45 | syntax match markdownRule "\* *\* *\*[ *]*$" contained 46 | syntax match markdownRule "- *- *-[ -]*$" contained 47 | 48 | syntax match markdownLineBreak " \{2,\}$" 49 | 50 | " Concel completely 51 | syntax region markdownIdDeclaration matchgroup=markdownLinkDelimiter start="^ \{0,3\}!\=\[" end="\]:\s*" oneline keepend nextgroup=markdownUrl skipwhite conceal 52 | syntax match markdownUrl "\S\+" nextgroup=markdownUrlTitle skipwhite contained 53 | syntax region markdownUrl matchgroup=markdownUrlDelimiter start="<" end=">" oneline keepend nextgroup=markdownUrlTitle skipwhite contained 54 | syntax region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+"+ end=+"+ keepend contained 55 | syntax region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+'+ end=+'+ keepend contained 56 | syntax region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+(+ end=+)+ keepend contained 57 | 58 | syntax region markdownLinkText matchgroup=markdownLinkTextDelimiter start="!\=\[\%(\_[^]]*]\%( \=[[(]\)\)\@=" end="\]\%( \=[[(]\)\@=" nextgroup=markdownLink,markdownId skipwhite contains=@markdownInline,markdownLineStart,markdownCodeRust concealends 59 | syntax region markdownLink matchgroup=markdownLinkDelimiter start="(" end=")" contains=markdownUrl keepend contained conceal 60 | syntax region markdownId matchgroup=markdownIdDelimiter start="\[" end="\]" keepend contained conceal 61 | syntax region markdownAutomaticLink matchgroup=markdownUrlDelimiter start="<\%(\w\+:\|[[:alnum:]_+-]\+@\)\@=" end=">" keepend oneline concealends 62 | 63 | syntax region markdownItalic matchgroup=markdownItalicDelimiter start="\S\@<=\*\|\*\S\@=" end="\S\@<=\*\|\*\S\@=" keepend contains=markdownLineStart concealends 64 | syntax region markdownItalic matchgroup=markdownItalicDelimiter start="\S\@<=_\|_\S\@=" end="\S\@<=_\|_\S\@=" keepend contains=markdownLineStart concealends 65 | syntax region markdownBold matchgroup=markdownBoldDelimiter start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" keepend contains=markdownLineStart,markdownItalic concealends 66 | syntax region markdownBold matchgroup=markdownBoldDelimiter start="\S\@<=__\|__\S\@=" end="\S\@<=__\|__\S\@=" keepend contains=markdownLineStart,markdownItalic concealends 67 | syntax region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" keepend contains=markdownLineStart concealends 68 | syntax region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\S\@<=___\|___\S\@=" end="\S\@<=___\|___\S\@=" keepend contains=markdownLineStart concealends 69 | 70 | syntax region markdownCodeRust matchgroup=markdownCodeDelimiter start="`" end="`" keepend concealends contains=@markdownHighlightRust 71 | syntax region markdownCodeRust matchgroup=markdownCodeDelimiter start="`` \=" end=" \=``" keepend concealends contains=@markdownHighlightRust 72 | syntax region markdownCodeRust matchgroup=markdownCodeDelimiter start="^\s*```*.*$" end="^\s*```*\ze\s*$" keepend contains=@markdownHighlightRust 73 | 74 | syntax match markdownFootnote "\[^[^\]]\+\]" 75 | syntax match markdownFootnoteDefinition "^\[^[^\]]\+\]:" 76 | 77 | syntax match markdownEscape "\\[][\\`*_{}()<>#+.!-]" 78 | syntax match markdownError "\w\@<=_\w\@=" 79 | 80 | highlight def link markdownH1 htmlH1 81 | highlight def link markdownH2 htmlH2 82 | highlight def link markdownH3 htmlH3 83 | highlight def link markdownH4 htmlH4 84 | highlight def link markdownH5 htmlH5 85 | highlight def link markdownH6 htmlH6 86 | highlight def link markdownHeadingRule markdownRule 87 | highlight def link markdownHeadingDelimiter Delimiter 88 | highlight def link markdownOrderedListMarker markdownListMarker 89 | highlight def link markdownListMarker htmlTagName 90 | highlight def link markdownBlockquote Comment 91 | highlight def link markdownRule PreProc 92 | 93 | highlight def link markdownFootnote Typedef 94 | highlight def link markdownFootnoteDefinition Typedef 95 | 96 | highlight def link markdownLinkText htmlLink 97 | highlight def link markdownIdDeclaration htmlLink 98 | highlight def link markdownId htmlLink 99 | highlight def link markdownAutomaticLink htmlLink 100 | highlight def link markdownUrl htmlLink 101 | highlight def link markdownUrlTitle htmlLink 102 | highlight def link markdownIdDelimiter markdownLinkDelimiter 103 | highlight def link markdownUrlDelimiter htmlTag 104 | highlight def link markdownUrlTitleDelimiter Delimiter 105 | 106 | highlight def link markdownItalic htmlItalic 107 | highlight def link markdownItalicDelimiter markdownItalic 108 | highlight def link markdownBold htmlBold 109 | highlight def link markdownBoldDelimiter markdownBold 110 | highlight def link markdownBoldItalic htmlBoldItalic 111 | highlight def link markdownBoldItalicDelimiter markdownBoldItalic 112 | highlight def link markdownCodeDelimiter Delimiter 113 | 114 | highlight def link markdownEscape Special 115 | highlight def link markdownError Error 116 | 117 | let b:current_syntax = 'rustdoc' 118 | if main_syntax ==# 'rustdoc' 119 | unlet main_syntax 120 | endif 121 | --------------------------------------------------------------------------------