Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
Add option to filter duplicates, fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianmarkow committed Jul 18, 2017
1 parent 5057355 commit 0a86e50
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -72,6 +72,11 @@ Set Rust source code path (when cloning from Github usually ending on `/src`).
let g:deoplete#sources#rust#rust_source_path='/path/to/rust/src'
~~~

Show duplicate matches.
~~~
let g:deoplete#sources#rust#show_duplicates=1
~~~

To disable default key mappings (`gd` & `K`) add the following
~~~
let g:deoplete#sources#rust#disable_keymap=1
Expand Down
7 changes: 7 additions & 0 deletions doc/deoplete-rust.txt
Expand Up @@ -66,6 +66,13 @@ g:deoplete#sources#rust#rust_source_path
e.g. `$HOME/rust/src`
(REQUIRED)

*g:deoplete#sources#rust#show_duplicates*
g:deoplete#sources#rust#show_duplicates
Set whether duplicate matches should be filtered.
Set to 0 to filter duplicates.
Default: 1
(OPTIONAL)

*g:deoplete#sources#rust#disable_keymap*
g:deoplete#sources#rust#disable_keymap
Set to 1 to disable default keymaps.
Expand Down
3 changes: 3 additions & 0 deletions plugin/deoplete-rust.vim
Expand Up @@ -15,6 +15,9 @@ let g:deoplete#sources#rust#rust_source_path=
let g:deoplete#sources#rust#documentation_max_height=
\ get(g:, 'deoplete#sources#rust#documentation_max_height', 20)

let g:deoplete#sources#rust#show_duplicates=
\ get(g:, 'deoplete#sources#rust#show_duplicates', 1)

let s:buffer_nr=-1

function! s:jumpTo(mode, filename, line_nr, column_nr)
Expand Down
7 changes: 6 additions & 1 deletion rplugin/python3/deoplete/sources/rust.py
Expand Up @@ -12,6 +12,7 @@

VAR_RACER_BINARY = 'deoplete#sources#rust#racer_binary'
VAR_RUST_SOURCE = 'deoplete#sources#rust#rust_source_path'
VAR_DUPLICATION = 'deoplete#sources#rust#show_duplicates'


class Source(Base):
Expand All @@ -26,6 +27,7 @@ def __init__(self, vim):
self.rank = 500

self.__racer = self.vim.vars.get(VAR_RACER_BINARY)
self.__dup = self.vim.vars.get(VAR_DUPLICATION)
self.__encoding = self.vim.eval('&encoding')
self.__rust_re = re.compile(r'\w*$|(?<=")[./\-\w]*$')

Expand All @@ -49,14 +51,17 @@ def gather_candidates(self, ctx):
lines = self.__retrieve()
matches = [line[6:] for line in lines if line.startswith('MATCH')]

if not bool(self.__dup):
matches = set(matches)

for match in matches:
tokens = match.split(",")
candidate = {
'word': tokens[0],
'kind': tokens[4],
'menu': tokens[5],
'info': ','.join(tokens[5:]),
'dup': 1,
'dup': self.__dup,
}
candidates.append(candidate)

Expand Down

1 comment on commit 0a86e50

@mqudsi
Copy link

@mqudsi mqudsi commented on 0a86e50 Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. I was concerned that you might be doing an ordered deduplication where only adjacent duplicates are removed because it seems that the duplicates don't come out of rust consecutively, they are separated by other results. But this looks good!

Please sign in to comment.