From f2e1fa6c19c65504d3c3ba8da93cf62d0aa2e798 Mon Sep 17 00:00:00 2001 From: ShawnChen1996 Date: Thu, 4 Apr 2019 23:31:10 +0800 Subject: [PATCH] Update ncm_r.py --- pythonx/ncm_r.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pythonx/ncm_r.py b/pythonx/ncm_r.py index 9298054..a1f1410 100644 --- a/pythonx/ncm_r.py +++ b/pythonx/ncm_r.py @@ -17,6 +17,16 @@ from omnils import add_snippet_var_inside_brackets +def only_first(func): + cache = {} + def wrap(self, message): + if message not in cache: + func(self, message) + cache[message] = 1 + return wrap + + + class Source(Rsource): # pylint: disable=R0902 """Completion Manager Source for R language""" @@ -36,6 +46,10 @@ def __init__(self, nvim): self.get_nvimr_settings() self.get_all_pkg_matches() + @only_first + def error(self, message): + self._error(message) + def get_nvimr_settings(self): """Get Nvim-R settings to read completion files""" @@ -44,7 +58,7 @@ def get_nvimr_settings(self): self._settings['nvimr_tmp'] = self.nvim.eval('g:rplugin_tmpdir') self._settings['nvimr_cmp'] = self.nvim.eval('g:rplugin_compldir') except NvimError: - self._error('Can\'t load Nvim-R options. ' + self.error('Can\'t load Nvim-R options. ' 'Did you install the Nvim-R plugin?') self._info("NVIMR_ID: {}, tmp: {}, cmp: {}".format( @@ -60,7 +74,7 @@ def check_nvimr_started(self): self.get_nvimr_settings() if self._settings['nvimr_id'] == '': - self._error('Can\'t find $NVIMR_ID. ' + self.error('Can\'t find $NVIMR_ID. ' 'Please start R using Nvim-R ' '(default mapping: rf).') return False @@ -81,7 +95,7 @@ def update_loaded_pkgs(self): pkg_loaded = self.nvim.eval('g:rplugin_loaded_libs') self._pkg_loaded = list(reversed(pkg_loaded)) except NvimError: - self._error('Can\'t find loaded R packages. ' + self.error('Can\'t find loaded R packages. ' 'Please start R using Nvim-R ' '(default mapping: rf).') raise @@ -153,11 +167,11 @@ def get_all_pkg_matches(self): self._pkg_matches.extend(self.matches.from_pkg_desc(descriptions)) except FileNotFoundError: - self._error('Can\'t find completion files. Please load the ' + self.error('Can\'t find completion files. Please load the ' 'R packages you need (e.g. "base" or "utils").') raise except Exception as error: - self._error('Could not load completion data', error) + self.error('Could not load completion data', error) raise def get_data_matches(self):