Sublime Forum

St3 to shows python methods arguments

#1

hi there,
i’m searching a way to have sublimetext3 to show python and pygame methods arguments.
for example if i type:

pygame.draw.line()
idealy st3 would show me in a popup:

line(Surface, color, start_pos, end_pos, width=1) -> Rect

would there be any plugin or package allowing to do something like this?

i tryed anaconda-st3 but, it doesn’t quite work with pygame as you can see on the ticket i opened here:

idle and bpython and pycharm do this but i would prefer to use st3 instead.

thanks

0 Likes

#2

You might want to try LSP package and install pyls (python-language-server).

0 Likes

#3

@deathaxe,
thanks for the reply, but, it doesn’t seem to work at all?
so far i’ve done this:

installed lsp (package in st3) and pyls (pip3 install python-language-server).
configured the lsp-user-settings to this:

"auto_complete_triggers": [ {"selector": "source.python", "characters": "."} ],

and sublime user-settings with this:

"mdpopups.use_sublime_highlighter": true

i’m not sure if i forgot some steps or not but at the moment it doesn’t do much.
no popup, no methods arguments … all parts installation seemed to went well.
is it supposed to show me some method argument popup on mouse over or on trigger “.” characters? because right now, it doesn’t ?

0 Likes

#4

There should be a “LSP: Setup Language Server” command in the palette, did you follow that?

0 Likes

#5

The default language-servers are disabled by default. You need to open a python file and call “LSP: Enable Language Server Globally” once.

0 Likes

#6

ok, thank you both for the help.
now it works for python builtins,
like if i type:

range() 

and put my mouse over it, it shows me a popup with the arguments like this:

range(start, stop=None, step=1)

which is nice.
but it doesn’t work well for pygame methods.
just like with jedi and anaconda here’s what i get:
pygame <-- popup: pygame is a set of python modules designed for writing games ..
pygame.draw <-- popup: draw = MissingModule("draw", geterror(), 1)
pygame.draw.line() <-- popup: no description available
pygame.Rect <-- popup: rect(left, top, width, height) -> rect

so it’s the same results as the ticket i opened for anaconda i linked to earlier.

i suppose this works best just for builtins ?

0 Likes

#7

Is your pygame library within python’s search path? If not Jedi doesn’t find and parse it correctly. pyls uses Jedi library to return the docstrings. If Jedi can’t handle this library, you won’t get proper information.

I added all “extra” libraries as well as ST’s install and package path to the “env” setting of pyls to include them into Jedi’s search path. This was required to get codeintel features to work for ST API and all packages/dependencies.

Btw.: Each dependency would needed to be added manually. It is not included in the example as I found a better way to do it automatically for me.

Example:

	"clients":
	{
		"pyls":
		{
			"enabled": true,
			"env": {
				"PYTHONPATH": "C:\\Apps\\Sublime;C:\\Apps\\Sublime\\Data\\Packages",
			},
		}
	},
0 Likes

#8

i will try this aswell, but in the same time i’m thinking: if pygame wasn’t in my python path, my code projects wouldn’t run at all, no ? since i’m able to run my pygame projects from shell and from st3, pygame library should be in correct place.

$ pip3 list | grep pygame
pygame (1.9.3)

$ ls /usr/local/lib/python3.6/dist-packages/ | grep pygame
pygame
pygame-1.9.3.dist-info

are you telling me it works for you on windows ?
you’re able to get methods arguments popups for pygame ?
please note that also i get some popups (from pyls and anaconda too) just not all of it, as shown in my previous post and in the ticket opened at anaconda (linked above).
pygame.Rect gets correct popup
pygame.draw.rect doesn’t get correct popup.
i wonder if it’s a problem on st3 for linux only ?

0 Likes

#9

i’ve found the cause:


jedi doesn’t seem to support import made in a try/except block.
so i suppose it wasn’t working on windows either.

until jedi figure this out, the workaround suggested to manually edit pygame’s init.py do work. now i do get my popups :slight_smile:

0 Likes

#10

I don’t use pygame. But yes it works well for most other libraries I use. But Jedi is not without flaws. There are couple of constructs it seems not to parse correctly. This is something the Jedi author can fix only. No client can do so.

0 Likes

#11

that’s why i finaly said the root cause was with jedi and not with st3 in my previous post.
now that i found the cause, i can see it wasn’t st3, nor pyls or anaconda’s problem.
which wasn’t so obvious at first. i just had a problem while using st3 for my python/pygame coding needs and it didn’t work as expected, that’s all i knew.
fortunately i got lucky, finding an easy (and a bit dirty) workaround :slight_smile:

anyway, thank you for the help

0 Likes