Upgrade to Pro — share decks privately, control downloads, hide ads and more …

IntelliJ Plugins

IntelliJ Plugins

A brief introduction to IntelliJ plugin architectures and a guide on how to navigate the IntelliJ APIs. Since everything is extendable in IntelliJ you are enabled to build nearly anything you can imagine, but the breadth of APIs and lack of thorough documentation also means starting out is very daunting. Through this presentation you will gain an understanding of the IntelliJ API design and the skills to get started on building tools.

Video: https://www.youtube.com/watch?v=-l5ChzRiUHE&feature=youtu.be

Alec Strong

August 04, 2016
Tweet

More Decks by Alec Strong

Other Decks in Programming

Transcript

  1. • IntelliJ’s representation of a file. • One for every

    file. • Exists during entire lifecycle of IntelliJ • When underlying file is deleted, VirtualFile
 remains but isValid() returns false. • VirtualFileListener • VirtualFileManager java.io.File VirtualFile
  2. • Loaded in memory on request (cached). • Text level

    changes (deleteString, insertString) • The editor references a single document • DocumentListener java.io.File VirtualFile Document
  3. • Standard AST - rule and terminal nodes. • The

    file is its own rule and is the
 root (FileASTNode) • Traversal done at runtime
 (findChildByType) java.io.File VirtualFile ASTNode Document
  4. • Program Structure Interface • Similar to documents, weakly reference

    by VirtualFile • The architecture used for all IntelliJ features 
 (autocomplete, refactoring, find usages, etc.) • Maps one to one with ASTNodes (getNode()). • PsiTreeUtil java.io.File VirtualFile ASTNode PsiFile/
 PsiElement Document
  5. • Parser Definitions are per-language • XML and Java already

    have ParserDefinitions
 (XMLParserDefinition and JavaParserDefinition) • Extend the class to implement for custom
 languages. • Provides implementations of a Lexer and Parser
 for the language to generate the ASTNode tree. • Provides methods to convert ASTNode to PsiElement java.io.File VirtualFile ASTNode PsiFile/
 PsiElement Document ParserDefinition
  6. Application • Only ever one • Manages concurrency (runReadAction/runWriteAction) •

    Contains state for current IDEA instance (isEAP(),
 getStartTime()) • Contains state of your current thread (isReadAccessAllowed(), isWriteAccessAllowed())
  7. Application Project • One instance per project (IntelliJ window) •

    Many Managers are per-project and require a project to
 be passed in.
  8. Components • Components provide lifecycle callback for Applications, Projects
 and

    modules • A component is created per instance of Application/Project/Module • Optionally ask for the wrapped object in constructor.
  9. Extension Points • Implement an extension point and IntelliJ will

    instantiate your class
 per application. • Typically defined per-language to avoid unnecessary execution. • Possible to create your own extension point so other plugins can
 extend your functionality.
  10. Documentation • In your editor, type “(ThingYouCareAbout)Manager” and attempt autocomplete.

    • Open source! kotlin, go, rust, sqldelight. • Look at their plugin.xml files for ideas. • Official intellij documentation 
 (www.jetbrains.org/intellij/sdk/docs/basics/types_of_plugins.html) • Jetbrains community forums. • AOSP