mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
fix: editor.py switch to disable docstring
This commit is contained in:
@ -20,7 +20,7 @@ from bec_widgets.widgets import ModularToolBar
|
|||||||
|
|
||||||
|
|
||||||
class AutoCompleter(QThread):
|
class AutoCompleter(QThread):
|
||||||
def __init__(self, file_path, api):
|
def __init__(self, file_path, api, enable_docstring=False):
|
||||||
super(AutoCompleter, self).__init__(None)
|
super(AutoCompleter, self).__init__(None)
|
||||||
self.file_path = file_path
|
self.file_path = file_path
|
||||||
self.script: Script = None
|
self.script: Script = None
|
||||||
@ -30,26 +30,33 @@ class AutoCompleter(QThread):
|
|||||||
self.index = 0
|
self.index = 0
|
||||||
self.text = ""
|
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):
|
def run(self):
|
||||||
|
self.update_script(self.text)
|
||||||
try:
|
try:
|
||||||
self.script = Script(self.text, path=self.file_path)
|
|
||||||
self.completions = self.script.complete(self.line, self.index)
|
self.completions = self.script.complete(self.line, self.index)
|
||||||
self.load_autocomplete(self.completions)
|
self.load_autocomplete(self.completions)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(err)
|
print(err)
|
||||||
|
|
||||||
self.finished.emit()
|
self.finished.emit()
|
||||||
|
|
||||||
def get_function_signature(self, line: int, index: int, text: str) -> str:
|
def get_function_signature(self, line: int, index: int, text: str) -> str:
|
||||||
|
self.update_script(text)
|
||||||
try:
|
try:
|
||||||
script = Script(text, path=self.file_path)
|
signatures = self.script.get_signatures(line, index)
|
||||||
signatures = script.get_signatures(line, index)
|
if signatures and self.enable_docstring is True:
|
||||||
if signatures:
|
|
||||||
full_docstring = signatures[0].docstring(raw=True)
|
full_docstring = signatures[0].docstring(raw=True)
|
||||||
compact_docstring = self.get_compact_docstring(full_docstring)
|
compact_docstring = self.get_compact_docstring(full_docstring)
|
||||||
return compact_docstring
|
return compact_docstring
|
||||||
|
elif signatures and self.enable_docstring is False:
|
||||||
|
return signatures[0].to_string()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(err)
|
print(f"Signature Error:{err}")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def load_autocomplete(self, completions):
|
def load_autocomplete(self, completions):
|
||||||
|
Reference in New Issue
Block a user