Building a Python Code Completer
summary
Claim: a working Python code completer is simple to build and can be demoed live. Uses Python's ast.parse to replace the cursor with a sentinel, walks the AST to collect scope (assignments and function args), and returns contextually appropriate names; a minimal version is about 10 lines and runs in roughly five minutes. Notes limitations: CPython ast has no error recovery so completion relies on hacks or alternative parsers like Sculpt parser (used in Anvil) or jedi/tree-sitter, and types from remote APIs remain hard.
AI-written summary · about
chapters (10)
- 0:00Start
- 1:46Why Code Completion?
- 4:59Parsing
- 6:08Grammar file
- 7:35The "ast" module
- 18:11Simple extensions
- 19:12Backward reference
- 21:09Error recovery
- 21:50Alternative Parsers
- 25:51What Have We Learned?
related talks
17mUnlocking Python's AST: The Metaprogramming Superpower You Didn't Know You Had
27mDream in Code
24mThe AST and Me
32mCode as Data_ A Practical Introduction to Python’s Abstract Syntax Tree
36mHacking the Python AST
46mPython ships a ready-made frontend for your compiler
33mSource code processing with Python
27mStatic Code Analysis with Python
