Sublime Forum

WebGL Completions and Tooltips

#1

I’m working on completions and tool tips for WebGL in ST3 but I’m finding the documentation really lacking in the tooltips department, everything is very vague and I can’t seem to find just a simple example that takes a completion list, and then displays tooltips off to the side somewhere. Is there a good resource that someone could recommend? I read these:

http://docs.sublimetext.info/en/latest/extensibility/plugins.html#plugins-completions-example

http://docs.sublimetext.info/en/latest/reference/api.html#sublime_plugin.EventListener.on_query_completions

But it doesn’t really show me how to do anything useful with just a simple completion list…Any tips would be fantastic.

Edit* There are examples out there, but they are very complex, full on plugins for this so there’s a lot of cruft that just looks like gibberish because I don’t even know how a simple case of this looks. That’s more why I want something a bit more simple and straightforward.

0 Likes

#2

Here is a minimal completion script with scope verification:

import sublime, sublime_plugin

class EventListener( sublime_plugin.EventListener ):

	def on_query_completions( self, view, prefix, locations ):

		#■■■  Get Scope  ■■■#

		region = view.sel()[0].a
		scope  = view.scope_name( region )

		#■■■  Verify Scope  ■■■#

		validScopes = []
		validScopes.append( "source.python" )

		validScope_Found = False

		for validScope in validScopes:
			if sublime.score_selector( scope, validScope ) != 0:
				validScope_Found = True

		if validScope_Found == False:
			return

		#■■■  Define Completions  ■■■#

		completionData = []
		completionData.append( ( "CompletionText1", "CompletionDescription1" ) )
		completionData.append( ( "CompletionText2", "CompletionDescription2" ) )
		completionData.append( ( "CompletionText3", "CompletionDescription3" ) )
		
		# NOTE:
		# I personally use the same value for "text" & "description" when possible to avoid confusion
		# EG: completionData.append( ( "CompletionText4", "CompletionText4" ) )

		#■■■  Return Completions  ■■■#

		completions = []

		for completionSet in completionData:
			text, description = completionSet
			completions.append( ( description, text ) )

		return( completions )

 



 
Just FYI, I’m working on a completion plugin that allows devs & users to easily implement contextual completion sets via YAML.

2 Likes

Is there any way to trigger autocompletion on non-word characters?
Custom Auto Complete list (mandatory list items)
Interface Suggestions
#3

I’m so happy right now I could cry…Thank you so much!

1 Like

#4

No problem, glad to have helped :grin:

So is that what you meant by tooltips?  Based on the context, I kind of guessed that you meant completions, but there is also a way to create tooltips ( technically popups ) as shown in the following image:

0 Likes

#5

That is exactly what I meant, I wanted a tooltip to pop out on completions, but that actually looks better than what I had in mind

1 Like

#6

@Trevor266

 
Forgot to mention - there are currently some bugs that affect auto-complete:

Completion triggers with characters not in [a-zA-Z0-9_-] prevent buffer completions

on_query_completions fails to return custom completions when some characters are used

 

If you use some particular symbols and/or attempt to include snippets in your completions, they will show up BUT they will also cancel out the regular document completions ( only your custom completions will be shown ).

0 Likes