Sublime Forum

Autocomplete over all tabs/project

#1

Hi there,

first of all - thank you for this great editor!

I have one question: Is there a possibility to broaden the scope of the smart auto completion data base to all open files or even all files inside the current project instead of just the current file? That would be awesome.

Thanks,
Max

0 Likes

@ Overlay based completions
Php define + autocomplete
#2

That would be awesome [2]

0 Likes

#3

Bumping to the top…

Would love this feature: Have autocomplete work across buffers, not only the currently active file. Would work wonders for web development.

0 Likes

#4

+1 for global/language-aware auto completion. +2 if it’s aware of function signatures & arguments.

Essential for large projects. This would allow most of the people on my team to break the tractor-beam hold that Eclipse has on them and move to an editor that doesn’t have all the visual appeal of a bucket of rusty nails. My Python sucks, but I’ll set aside some time this weekend to see how much work this would be – perhaps easier if a TAGS-like file format can be made that a Sublime plugin can slurp down.

0 Likes

#5

Agree. It will be great for my C#, C++ projects…

0 Likes

#6

There is SublimeCodeIntel which offers code completion for some languages.

There is a ctags package for Sublime (github.com/SublimeText/CTags), too.

I vaguely remember that there is also a package dedicated to C/C++ projects, but I forgot its name.

0 Likes

#7

+1 for autocompletion over files in a project, but only over files with the same extension

0 Likes

#8

I wrote a plugin that pulls completions from every open tab:

[code]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

[/code]

If you want to limit it to files with the same extension, add something like this:

        if(view.file_name() is None):
            extension = ''
        else:
            name, extension = view.file_name().rsplit('.',2)
        extension = '.' + extension

        views = ]
        for v in window.views():
            fileName = v.file_name()
            if (fileName is None or v.buffer_id() != view.buffer_id() and fileName.endswith(extension)):
                views.append(v)
        # get results from each tab
        results = [v.extract_completions(prefix) for v in views]
        # the rest is the same
0 Likes

#9

Nice, didn’t now about extract_completions method.
By the way, when was it introduced ?

0 Likes

#10

extract_completions has been around since ST1 days

0 Likes

#11

Well, it’s strange, I found it in ST 1 API documentation,
but this very useful method is not mentioned in new ST 2 API docs. So I didn’t know it exists.

0 Likes

#12

@iamnoah I’m not sure how to run that. Is it in package control?

0 Likes

#13

Just copy/paste/save as autocomplete_all.sublime-plugin and drop it in your /Packages/User folder.

0 Likes

#14

If you don’t have any luck with giving that file a “.sublime-plugin” extension (I didn’t), give it a “.py” extension.

Or go to Tools > New Plugin… then paste the code over the contents of the opened file.

0 Likes

#15

does anyone know how to modify this plugin to use all of the files in the project instead of only the open ones?

0 Likes

#16

Hello,

any news on the feature asked by intrepion ? As my python also sucks (or i did not manage to get enough into the docs), it would be great to just indicate what is there to modify in the given script. :smile:

0 Likes

#17

+1 for that!

0 Likes

#18

Here’s a package that autocompletes on open files. It’s in package control too as “all autocomplete”.

github.com/alienhard/SublimeAllAutocomplete

It’s not exactly what you asked (whole project), but it usually gets the job done.

0 Likes

#19

Why not use SublimeClang plug-in?

0 Likes