From 0713b6d2fcf739c6dfd8fdd4062be1e407c2f96b Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 17 May 2017 22:33:16 +0200 Subject: [PATCH] TASK: Improve logging and make it configurable --- rplugin/python3/neotags.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/rplugin/python3/neotags.py b/rplugin/python3/neotags.py index 5c08aa0..1deddb7 100644 --- a/rplugin/python3/neotags.py +++ b/rplugin/python3/neotags.py @@ -17,9 +17,17 @@ class NeotagsPlugin(object): self.ctags_cmd = 'ctags' # Perhaps fetch debugging settings? + def update_settings(self): + try: + self.logging = bool(self.nvim.vars['neotags_logging']) + except neovim.api.nvim.NvimError: + self.logging = false + # Check whether 'FileWritePost' is necessary @neovim.autocmd('BufWritePost', pattern='*', eval='expand(":p")') def update_tags_for_file(self, filename): + self.update_settings() + self.log('Triggered for "%s"' % filename) pwd = self.nvim.funcs.execute('pwd').strip() @@ -30,7 +38,7 @@ class NeotagsPlugin(object): self.log('Start updating tags for "%s"' % filename) self.strip_existing_tags(tags_file, relative_filename) self.generate_tags(tags_file, relative_filename) - self.log('Tags for file "%s"' % filename) + self.log('Tags updated for "%s"' % filename) except: self.log( 'Failed to update tags for "%s", reason: %s' % ( @@ -55,17 +63,20 @@ class NeotagsPlugin(object): def get_tags_file(self, filename): path = pathlib.Path(filename) + possible_file = path.with_name(self.tags_filename) - self.log('Test: ' + str(path.with_name(self.tags_filename))) - if path.with_name(self.tags_filename).is_file(): - return str(path.with_name(self.tags_filename)) + self.log('Search tags file: "%s"' % possible_file) + if possible_file.is_file(): + return str(possible_file) for folder in path.parents: - self.log('Test: ' + str(folder.with_name(self.tags_filename))) - if folder.with_name(self.tags_filename).is_file(): - return str(folder.with_name(self.tags_filename)) + possible_file = folder.with_name(self.tags_filename) + self.log('Search tags file: "%s"' % possible_file) + if possible_file.is_file(): + return str(possible_file) raise ValueError('No tags file found in parent folders of given file') def log(self, message): - self.nvim.out_write('neotags > ' + message + "\n") + if self.logging: + self.nvim.out_write('neotags > ' + message + "\n")