📎 Webclip
Mikko Ohtamaa: Javascript autocompletions and having one for Sublime Text 2
The article says JavaScript autocompletion is hard because the language does not expose static type information while code is being written, and because frameworks use incompatible ways to define classes, modules, and namespaces. It then reviews several ways to add type hints and feed them into editor completion systems.
Reading notes#
- JavaScript lacks static typing, so an editor cannot know the type of values such as
this,$, orjQuerybefore the code runs. - The absence of native classes and modules means each framework invents its own conventions, which makes automatic type extraction harder.
- Editors can use generated or manually maintained type files, such as
.sublime-completionsfiles. - JsDoc comments can carry class and namespace information, especially for code organized with RequireJS.
- TypeScript can provide type information either through external
.d.tsfiles or by writing code in TypeScript itself. - Sublime Text 2 has a TypeScript plug-in for autocompletions.
- SublimeCodeIntel uses OpenKomodo CodeIntel, which is open source and written in Python, but the author says he could not get its JsDoc support working.
- CTags is another backend Sublime Text 2 can use, though the author did not test it with JavaScript completion.
- A Three.js script shows a simpler route: scan the codebase with regexes and generate Sublime Text 2 completion files.
- The same idea can apply to other dynamically typed languages when the project controls its namespace conventions.
