From 3cc05cde147cd520b98f0896beb64781ea47d816 Mon Sep 17 00:00:00 2001 From: wyzula-jan <133381102+wyzula-jan@users.noreply.github.com> Date: Tue, 21 Nov 2023 22:56:27 +0100 Subject: [PATCH] fix: editor.py switch to disable docstring --- bec_widgets/widgets/editor/editor.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bec_widgets/widgets/editor/editor.py b/bec_widgets/widgets/editor/editor.py index 422fa170..3eec4ebf 100644 --- a/bec_widgets/widgets/editor/editor.py +++ b/bec_widgets/widgets/editor/editor.py @@ -20,7 +20,7 @@ from bec_widgets.widgets import ModularToolBar class AutoCompleter(QThread): - def __init__(self, file_path, api): + def __init__(self, file_path, api, enable_docstring=False): super(AutoCompleter, self).__init__(None) self.file_path = file_path self.script: Script = None @@ -30,26 +30,33 @@ class AutoCompleter(QThread): self.index = 0 self.text = "" + self.enable_docstring = enable_docstring + + def update_script(self, text: str): + if self.script is None or self.script.path != text: + self.script = Script(text, path=self.file_path) + def run(self): + self.update_script(self.text) try: - self.script = Script(self.text, path=self.file_path) self.completions = self.script.complete(self.line, self.index) self.load_autocomplete(self.completions) except Exception as err: print(err) - self.finished.emit() def get_function_signature(self, line: int, index: int, text: str) -> str: + self.update_script(text) try: - script = Script(text, path=self.file_path) - signatures = script.get_signatures(line, index) - if signatures: + signatures = self.script.get_signatures(line, index) + if signatures and self.enable_docstring is True: full_docstring = signatures[0].docstring(raw=True) compact_docstring = self.get_compact_docstring(full_docstring) return compact_docstring + elif signatures and self.enable_docstring is False: + return signatures[0].to_string() except Exception as err: - print(err) + print(f"Signature Error:{err}") return "" def load_autocomplete(self, completions):