TabNine was created as a language-agnostic autocompleter. The core idea behind TabNine is that by indexing your code and detecting statistical patterns within it, TabNine can make better suggestions than a completer which understands your programming language. This brings additional gains in responsiveness, reliability, and ease of configuration because TabNine doesn’t need to compile your code.
Nonetheless, there are some situations where you would rather use a semantic completer than TabNine. For example, if you don’t know what methods are contained in the class
Math, you could type
Math. and see what suggestions are provided by the semantic completer. Also, semantic completers can provide documentation and type signatures together with their suggestions.
That’s why TabNine now supports semantic completion. TabNine continues to be language-agnostic: semantic completion is provided by external software which TabNine communicates with using the Language Server Protocol. TabNine comes with default install scripts for several common language servers, and this is fully configurable, so you can use a different language server or add semantic completion for a new language if you wish. You can read more about how to configure it here.
Here’s an example:
Here, TabNine uses the language server to provide type signatures and documentation for the suggestions. Also note that TabNine is using its index to sort the language server’s suggestions in order of frequency, placing
with_capacity at the top.
The skeptical reader asks: why use TabNine together with a language server when I could simply use the language server instead? Here are three ways in which TabNine improves the user experience over the language server alone:
Many language servers are slow. If the language server is slow, TabNine will provide its own results while querying the language server in the background. TabNine typically returns its results in 20 milliseconds or so, while Jedi, a completion engine for Python, usually takes around 500 milliseconds. Rather than waiting for Jedi, TabNine will provide its results immediately and cache Jedi’s suggestions to be returned instantly once you type more characters.
Language servers don’t always have the right completion. When you use an autocompleter, you give it half-written code that may contain syntax errors, type errors, or references to functions that you haven’t written yet. These cases are challenging for language servers because they need to make long chains of inferences to determine what completions to suggest, so breaking any link in this chain can disrupt the entire process. TabNine is robust to half-written code because it does not parse the code, so there are no long-distance effects.
Multi-token completion. TabNine can improve the language server’s suggestions by suggesting multiple tokens at once. For example:
In this example, TabNine uses Jedi to infer that
zis a string and has an
encodemethod. Then TabNine uses its own multi-token completion engine to suggest
encode('utf8')rather than simply
Semantic completion is part of TabNine 1.0.7. You can read the full changelog here.