Home Download Buy Blog Forum Support

Code assist on Less variables

Code assist on Less variables

Postby Granze on Tue Mar 27, 2012 9:24 am

Is there a way to get code assist typing "@" to comple Less variables?
The variables are not necessarily in the same file.

Thanks
Granze
 
Posts: 3
Joined: Tue Mar 20, 2012 1:44 pm

Re: Code assist on Less variables

Postby aziz on Tue Mar 27, 2012 3:25 pm

It would be extremely rad if we could have had this. but I doubt it! it needs parsing your less files and all your imports that makes it a little bit slow!
PlainTasks: my opinionated todo plugin
tmThemeEditor color-scheme editor for SumblimeText and Textmate (code on github)
aziz
 
Posts: 40
Joined: Thu Jan 12, 2012 6:29 pm

Re: Code assist on Less variables

Postby agibsonsw on Tue Mar 27, 2012 3:50 pm

You can create File Settings, syntax specific, and copy this:

Code: Select all
{
    // Additional situations to trigger auto complete
   "auto_complete_triggers": [ {"selector": "text.html", "characters": "@"} ]
}

Change the 'selector' to, possibly, 'source.less' :?:

It is possible to tap into 'on_query_completions' and create a completions list which is only for less, and extracts @-completions from, for example, all open less-files. I suspect someone may have already created something similar ;)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Code assist on Less variables

Postby agibsonsw on Tue Mar 27, 2012 3:53 pm

Here's some code I found, but it needs to be adapted to only search within .less files:

Code: Select all
import sublime_plugin, sublime

class AutocompleteAll(sublime_plugin.EventListener):

    def on_query_completions(self, view, prefix, locations):
        window = sublime.active_window()
        # get results from each tab
        results = [v.extract_completions(prefix) for v in window.views() if v.buffer_id() != view.buffer_id()]
        results = [(item,item) for sublist in results for item in sublist] #flatten
        results = list(set(results)) # make unique
        results.sort() # sort
        return results
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Code assist on Less variables

Postby agibsonsw on Tue Mar 27, 2012 4:06 pm

Something like this:

Code: Select all
import sublime_plugin, sublime

class AutocompleteLess(sublime_plugin.EventListener):

    def on_query_completions(self, view, prefix, locations):
      if not view.match_selector(locations[0], 'source.less -string -comment -constant'):
         return []
        window = sublime.active_window()
        # get results from each tab
        results = [v.extract_completions(prefix) for v in window.views() if v.buffer_id() != view.buffer_id()
         and v.match_selector(0, 'source.less')]
        results = [(item,item) for sublist in results for item in sublist] #flatten
        results = list(set(results)) # make unique
        results.sort() # sort
        return results

but I haven't tested it :)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Code assist on Less variables

Postby Granze on Thu Mar 29, 2012 7:28 am

agibsonsw wrote:Something like this:

Code: Select all
import sublime_plugin, sublime

class AutocompleteLess(sublime_plugin.EventListener):

    def on_query_completions(self, view, prefix, locations):
      if not view.match_selector(locations[0], 'source.less -string -comment -constant'):
         return []
        window = sublime.active_window()
        # get results from each tab
        results = [v.extract_completions(prefix) for v in window.views() if v.buffer_id() != view.buffer_id()
         and v.match_selector(0, 'source.less')]
        results = [(item,item) for sublist in results for item in sublist] #flatten
        results = list(set(results)) # make unique
        results.sort() # sort
        return results

but I haven't tested it :)

I've tried this but doesn't seems to work.
Granze
 
Posts: 3
Joined: Tue Mar 20, 2012 1:44 pm

Re: Code assist on Less variables

Postby agibsonsw on Thu Mar 29, 2012 12:10 pm

Is there an error message in the Console (Ctrl ' )?

It probably doesn't recognise 'source.less'. Isn't this CSS? So perhaps 'source.css' and delete '-string -comment -constant' for the moment, to see if this is the issue.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm


Return to General Discussion

Who is online

Users browsing this forum: demetris, Google [Bot] and 18 guests