ycm-core / ycmd

A code-completion & code-comprehension server

Home Page:https://ycm-core.github.io/ycmd/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TS: include `@param` and `@returns` in docs

notEvil opened this issue · comments

Hi,

would you consider adding @param and @returns for JavaScript/TypeScript docs? Like

--- a/ycmd/completers/typescript/typescript_completer.py
+++ b/ycmd/completers/typescript/typescript_completer.py
@@ -1128,6 +1128,27 @@ def _BuildCompletionExtraMenuAndDetailedInfo( request_data, entry ):
     extra_menu_info = re.sub( '\\s+', ' ', signature )
     detailed_info = [ signature ]
 
+  interface = []
+  returns = None
+
+  for tag in entry.get("tags", []):
+    if tag["name"] == "param":
+      text = tag["text"]
+      match = re.search("\s", text)
+      index = len(text) if match is None else match.start(0)
+      interface.append((text[:index], text[index + 1 :].strip()))
+
+    elif tag["name"] == "returns":
+      returns = tag["text"]
+
+  if returns is not None:
+    interface.append(("return", returns))
+
+  if len(interface) != 0:
+    length = max(len(name) for name, _ in interface)
+    _ = '\n'.join(f'{name.rjust(length)}: {text}' for name, text in interface)
+    detailed_info.append(_)
+
   docs = entry.get( 'documentation', [] )
   detailed_info += [ doc[ 'text' ].strip() for doc in docs if doc ]
   detailed_info = '\n\n'.join( detailed_info )

The format (e.g. .rjust and ": ") is obviously a matter of taste.

sure, I don't see why not. Happy to review a PR with tests.

Would also like to see some example screenshots in YCM of GetDoc and the equivalent Hover, just to make sure it looks sane, but I have no objection to a contribution in this area.