Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show error massage only once #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions pythonx/ncm_r.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand All @@ -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"""

Expand All @@ -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(
Expand All @@ -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: <localleader>rf).')
return False
Expand All @@ -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: <localleader>rf).')
raise
Expand Down Expand Up @@ -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):
Expand Down