diff --git a/README.md b/README.md new file mode 100644 index 0000000..35e755a --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# ncm2-racer + +[ncm2-racer](https://github.com/ncm2/ncm2-racer) is a Rust auto-completion plugin for [ncm2](https://github.com/ncm2/ncm2). + +## Requirement + +- [racer](https://github.com/racer-rust/racer) + +ncm2-racer depends on [racer](https://github.com/racer-rust/racer). + +Ensure you have installed racer, if not, please refer to https://github.com/racer-rust/racer#installation for more information. diff --git a/pythonx/ncm2_racer.py b/pythonx/ncm2_racer.py index 08e5abf..ba042f1 100644 --- a/pythonx/ncm2_racer.py +++ b/pythonx/ncm2_racer.py @@ -2,29 +2,34 @@ import vim from ncm2 import Ncm2Source, getLogger, Popen -import re import os import glob import subprocess - logger = getLogger(__name__) -class Source(Ncm2Source): +class Source(Ncm2Source): def check(self): from distutils.spawn import find_executable if not find_executable("racer"): - self.nvim.call('ncm2_racer#error', 'Can not find racer for completion, you need https://github.com/phildawes/racer') + self.nvim.call( + 'ncm2_racer#error', + ('Can not find racer for completion, ' + 'please check out https://github.com/racer-rust/racer')) if not self._check_rust_src_path(): - self.nvim.call('ncm2_racer#error', '$RUST_SRC_PATH not defined, please read https://github.com/phildawes/racer#configuration' ) + self.nvim.call('ncm2_racer#error', ( + '$RUST_SRC_PATH not defined, ' + 'please read https://github.com/racer-rust/racer#configuration' + )) def _check_rust_src_path(self): if "RUST_SRC_PATH" in os.environ: return os.environ["RUST_SRC_PATH"] # auto detect, if user already run `rustup component add rust-src` - found = glob.glob(os.path.expanduser( - "~/.rustup/toolchains/*/lib/rustlib/src/rust/src")) + found = glob.glob( + os.path.expanduser( + "~/.rustup/toolchains/*/lib/rustlib/src/rust/src")) if found: logger.info("detect RUST_SRC_PATH as [%s]", found[0]) os.environ["RUST_SRC_PATH"] = found[0] @@ -42,11 +47,16 @@ def on_complete(self, ctx, lines): filepath = ctx['filepath'] startccol = ctx['startccol'] - args = ['racer', 'complete-with-snippet', str(lnum), str(bcol - 1), filepath, '-'] - proc = Popen(args=args, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.DEVNULL) + args = [ + 'racer', 'complete-with-snippet', + str(lnum), + str(bcol - 1), filepath, '-' + ] + proc = Popen( + args=args, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL) result, errs = proc.communicate(src, timeout=30) @@ -79,7 +89,8 @@ def on_complete(self, ctx, lines): match = dict(word=word) menu = fields[6] - if "RUST_SRC_PATH" in os.environ and menu.startswith(os.environ["RUST_SRC_PATH"]): + if "RUST_SRC_PATH" in os.environ and menu.startswith( + os.environ["RUST_SRC_PATH"]): menu = menu[len(os.environ["RUST_SRC_PATH"]):] match['menu'] = menu @@ -97,6 +108,7 @@ def on_complete(self, ctx, lines): self.complete(ctx, startccol, matches) + source = Source(vim) on_complete = source.on_complete