Sublime Forum

Sublime Text Basic Code Autocompletion

#1

Hello!

When I use the command goto_definition, it opens a list of all available code completions in a C++ project for example. That works great. However, when I’m typing within the function my_amazing_function(| <-- cursor, it would be helpful if it could show the first (or all of) the function definitions. They way I’m imagining it, it wouldn’t need full-blown IntelliSense or anything. Just a simple popup window that shows all the source function signatures. It could even start to get “smarter” by highlighting the specific parameter I’m filling out. But that’s it. I don’t want to have to install a separate program to do this, and it seems like Sublime Text already has enough built-in to do something simple.

my_amazing_function(|)
                   |---------------------------|
                   | int maf(int a, int b)     |
                   | int maf(int a)            |
                   |---------------------------|

I’m not sure if this already exists (but I tried searching for a while and could not find anything).

Then the last question would be, if it doesn’t exist, is this possible to create with a Sublime Text plugin today? I was looking at the API Reference and there’s the SymbolLocation which at least would get you started. The problem is you would have to actually read each of those files to get the method stub.

Thanks!

Nick

0 Likes

#2

It’s not simple. There is no signature analysis (which can be quite language-specific) in ST. However, LSP + clang can offer that. Most likely when you want an IDE feature, you most likely can find it in a language server.

0 Likes

#3

But that’s exactly what I’m saying - I don’t want it to be a fully-blown IDE feature and I don’t want it to use an LSP (so I’m OK with it not working perfectly). How would it not be simple? I just want to do some really basic text matching. For example you could imagine the algorithm as follows:

  1. read the line at the file with the symbol name
  2. on the right side, read until you’ve hit a '{'
  3. on the left side, read until you get one at least one word and then a newline

Then that string is used in the popup.

Or even simpler, just show the whole line where that function symbol is defined. You could also extend this to work for C-like languages.

0 Likes

#4

Yes, that’s made a lot simpler using your given assumption but still I am not aware of any plugin, which only provides signature help. You can disable all other features in LSP except autocompletion but I guess that’s still heavy for you.

0 Likes

#5

I think this provides path, row and col. With your assumption, your request seems can be done with SymbolLocation.

0 Likes

#6

I made this plugin: https://github.com/nickav/DefinitionPreview

Hopefully some functionality similar to this can be added in a future release of Sublime Text.

0 Likes