Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: How does code completion (as in IDEs) work on a technical level?
6 points by cweagans on Feb 13, 2015 | hide | past | favorite | 3 comments
Conceptually, I understand the parts, but I'm having trouble translating that to working code. I've been doing some research and came across Jedi (https://github.com/davidhalter/jedi), which is an autocomplete library for Python.

Is there some guide somewhere that walks through the process of building something like Jedi for some other language (even an imaginary one)?

While it's tangential to this particular discussion, my goal (eventually) is to learn what I need to know to be able to build something like Jedi for PHP. There's only a handful of options for PHP code completion, and none of them provide the level of intelligence of a proprietary IDE like PhpStorm. That needs to change, IMO.



Start small. Make a function that takes a string which is part of an English word and returns a list of completions for that word. If on Linux, use the word list in `/usr/share/dict/words`.

The next step up is to improve on that function. F.e. if the string is "disc" a good candidate probably is "discussion" but not "discus" unless that word previously occurs in the document.

Then continue from there. Coding is learnt by doing not by reading guides.


Well, yeah. I mean, that's straightforward enough, but what people frequently leave out is what "improve on that function" entails, especially when you start getting into really weird codebases.

Like I said, I understand the overall components - I need a lexer/parser to parse the code into a usable data structure that I can then examine to pull out information about that code. I also need some way for that parser to not puke if the syntax isn't perfect (for instance, if I'm typing in a line of code, that line of code isn't going to be syntactically perfect).

I've been a developer for a number of years now. I know how to learn stuff. The problem is that this particular problem is so nebulous and infrequently solved in a publicly viewable way that I don't even know what I don't know, hence the idea of looking at a guide for some simple, imaginary language. If I can see the basics without all of the eventual code rot and cruft, I can go from there. A sample implementation in pretty much any language would also be adequate - I can do without the prose.


Take a look at IntelliJ IDEA CE source. It's an open source project. Also, read this description of how to implement a language support in IntelliJ: https://confluence.jetbrains.com/display/IDEADEV/Developing+...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: