8000 Variables of builtin types showing their value instead of docstring · SigmaTel71/python-lsp-server@739023d · GitHub
[go: up one dir, main page]

Skip to content

Commit 739023d

Browse files
SigmaTel71Vitaly Orekhov
authored andcommitted
Variables of builtin types showing their value instead of docstring
Initial implementation of better variable data lookup. docstring will continue to appear only if cursor was set on bare value.
1 parent 4211502 commit 739023d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pylsp/plugins/hover.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
@hookimpl
1212
def pylsp_hover(config, document, position):
13+
settings = config.plugin_settings("jedi_definition")
1314
code_position = _utils.position_to_jedi_linecolumn(document, position)
1415
definitions = document.jedi_script(use_document_path=True).infer(**code_position)
1516
word = document.word_at_position(position)
@@ -39,6 +40,24 @@ def pylsp_hover(config, document, position):
3940
),
4041
"",
4142
)
43+
44+
# If the variable type is in builtin module, it will be reasonable
45+
# to show its value instead of docstring.
46+
if definition.in_builtin_module():
47+
names = document.jedi_script(use_document_path=True).goto(
48+
follow_imports=settings.get("follow_imports", True),
49+
follow_builtin_imports=settings.get("follow_builtin_imports", True),
50+
**code_position)
51+
52+
if names:
53+
name = names[0]
54+
return {
55+
"contents": _utils.format_docstring(
56+
f"{definition.name} {name.description}",
57+
preferred_markup_kind,
58+
signatures=[signature] if signature else None
59+
)
60+
}
4261

4362
return {
4463
"contents": _utils.format_docstring(

0 commit comments

Comments
 (0)
0