diff --git a/core/handler/completion.py b/core/handler/completion.py index a78702e41c..a8b9b7a6ff 100644 --- a/core/handler/completion.py +++ b/core/handler/completion.py @@ -85,16 +85,21 @@ def get_display_label(self, item, display_new_text): # Optimizing for Rust try: if (self.method_server_name == "rust-analyzer") and ("(\u2026)" in label or "()" in label): # '\u2026' is the unicode char: '…' - # When finding an ellipsis in 'label' - # replace 'fn' with function name in 'label' function_name = label.split('(')[0] - detail_label = re.sub(r'\bfn\b', function_name, detail) - # Remove `pub` or `pub const` before function name. - match = re.search(r'\b(\w+\s*\([^)]*\)\s*->\s*\w+)\b', detail_label) - if match: - # If a match is successful, pick up the captured group - detail_label = match.group(1) + match_fn = re.search(r'\bfn\b', function_name) + if match_fn: + # When finding an ellipsis in 'label' + # replace 'fn' with function name in 'label' + detail_label = re.sub(r'\bfn\b', function_name, detail) + + # Remove `pub` or `pub const` before function name. + match = re.search(r'\b(\w+\s*\([^)]*\)\s*->\s*\w+)\b', detail_label) + if match: + # If a match is successful, pick up the captured group + detail_label = match.group(1) + else: + detail_label = function_name except: pass