live-plugin

repository·master·Indexed 21 days ago

https://github.com/dkandalov/live-plugin

A wrapper for the Kotlin compiler API designed for the LivePlugin ecosystem to prevent classloading conflicts with IntelliJ IDEA. The project includes a kotlin-compiler-wrapper to resolve naming collisions and provides integration for treating live plugins as specialized 'Scratch' content within the IDE, including custom RootType registration, file editability, and syntax highlighting.

Tokens
1.4K
Snippets
0
Records
10
Agent score
26%

What's inside live-plugin

  1. Overview of the Kotlin Compiler Wrapper

    master
    The kotlin-compiler-wrapper is a specialized wrapper for the Kotlin compiler API designed for use within LivePlugin. Its primary purpose is to resolve classloading conflicts between the Kotlin compiler and IntelliJ IDEA. Because Kotlin contains classes with the exact same fully qualified names as classes in IntelliJ, this wrapper ensures that the correct classes are loaded by the appropriate classloader, preventing subtle errors such as expected type kotlin.String but was kotlin.String.
  2. Understand IntelliJ API naming conventions

    master

    When exploring the IntelliJ API, keep these naming patterns in mind:

    • Manager postfix: Generally indicates a class that acts as a "Facade" for a specific subsystem.
    • Ex postfix: Indicates an implementation that has extended functionality (e.g., ApplicationManagerEx).
  3. Follow IntelliJ threading rules

    master

    To avoid concurrency issues and UI freezes, follow these threading rules when interacting with the IntelliJ Platform:

    ContextRead OperationWrite Operation
    EDT (Event Dispatch Thread)Just do itUse runWriteAction{...}
    Other threadsUse runReadAction{...}Use invokeOnEDT{...} (N/A for direct writes)
  4. How Live Plugins are integrated into the IDE

    master

    The live-plugin implementation integrates live plugins into the IntelliJ IDEA environment by treating them as a specialized type of 'Scratch' content. This integration provides several key behaviors:

    • Scratch Root Type: Live plugins are registered under a custom RootType named LivePlugin. This allows them to be treated similarly to IDE Consoles and Scratches, enabling Kotlin intentions and features even when working outside of a formal project context.
    • Directory Completion: When creating a new directory in a project root, .live-plugins is suggested as a variant with the LivePlugin source root type.
    • File Editability: Files located within a live plugin are explicitly marked as writable via NonProjectFileWritingAccessExtension, bypassing standard restrictions on non-project files.
    • Syntax Highlighting: Syntax highlighting is automatically enabled for files within live plugins by providing a SyntaxHighlighterProvider that resolves the language based on the file's context.
    • Search and Usage: Live plugins are indexed and included in 'Find Usages' searches through a custom UsageTypeProvider and GlobalSearchScope named LivePlugins.
  5. Reference Action and Intention APIs

    master

    APIs for handling user interactions and editor intentions:

    • AnAction: The base class for all user interactions.
    • AnActionEvent: A container for information required to execute or update an AnAction.
    • ActionManager: Used to register, unregister, or find actions.
    • IntentionAction: Interface for intention actions (the "Alt-Enter" actions in the editor).
    • IntentionManager: Used to register or unregister intentions.
  6. Reference Core IntelliJ APIs

    master

    Commonly used core classes for application and project management:

    • Application: Access to core application-wide functionality and the IDEA thread model.
    • MessageBus: The core subscribe/publish messaging infrastructure.
    • Project: Represents an IntelliJ project; used for project-specific functionality.
    • ProjectManager: Used to open, close, or get a list of projects.
    • ProjectManagerListener: Callback interface for project open/close events.
    • DumbAware: A marker interface for actions and toolwindows that can function while indices are being updated.
  7. Reference Project Structure and UI APIs

    master

    APIs for managing project modules and user interface components:

    Project Structure

    • ProjectRootManager: Queries and modifies project root files and directories.
    • ModuleManager: Gets or modifies project modules.
    • ModuleRootManager: Contains module content and dependency information.

    UI Elements

    • Messages: Provides various dialogs (yes/no, ok/cancel).
    • DialogBuilder: A builder for creating custom dialogs.
    • ToolWindowManager: Accesses registered tool windows and manages balloon notifications.
    • ToolWindowFactory: Used to create tool windows.
  8. Reference File Editing and VFS APIs

    master

    APIs for interacting with text editors, documents, and the Virtual File System (VFS):

    • Editor: Represents an instance of the IDEA text editor.
    • CaretModel: Manages caret movement and position information.
    • SelectionModel: Manages text selection and retrieves selection info.
    • MarkupModel: Used for highlighting text ranges and painting gutter markers.
    • FileEditorManager: Used to open, close, or retrieve the current editor.
    • Document: Represents the in-memory contents of a text file.
    • FileDocumentManager: Retrieves a Document for a VirtualFile.
    • VirtualFile: Represents a file on disk, in an archive, or on an HTTP server.
    • VirtualFileSystem: An abstraction for file system operations like delete, move, or rename.
    • VirtualFileListener: Receives notifications regarding changes in the VFS.
    • VirtualFileManager: Used to add VirtualFile listeners and refresh the VirtualFileSystem.
  9. Reference PSI (Program Structure Interface) APIs

    master

    APIs for interacting with the syntax tree and code structure:

    • PsiElement: The base interface for all elements in the PSI tree.
    • PsiFile: A PSI element representing a file.
    • PsiManager: Used to obtain a PsiFile for a given VirtualFile.
    • PsiUtil classes: Miscellaneous utility methods for PSI manipulation.