# terminalfi/lsp-copilot architecture

> Architecture diagram of the GitHub repository terminalfi/lsp-copilot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/terminalfi/lsp-copilot
- Repository: https://github.com/terminalfi/lsp-copilot

## Overview

##### Project Type & Purpose
- The README clarifies that LSP-copilot is a Sublime Text plugin that provides GitHub Copilot support to the LSP plugin. Its purpose is to supply inline code completions, panel completions, phantoms, and even a chat interface by leveraging the Copilot service.
- The project combines both the client-facing plugin and a language server component (located in the language-server directory) which manages communication with Copilot’s backend.

##### Analyzing the File Structure
- Top-Level Directories & Files:
- Files like boot.py, Makefile, README.md, and configuration files demonstrate standard project setup.
- The “plugin” folder contains the main Python source code. It holds modules for commands, UI elements (under plugin/ui), settings, listeners, helpers, decorators, and templates (the latter likely used to render UI panels or completion popups).
- The “language-server” folder features a package.json and a package-lock.json along with a .gitignore, signalling a Node.js–based service. This part likely interacts with GitHub Copilot’s API.
- Other configuration files such as LSP-copilot.sublime-settings, copilotignore files, and several Sublime Text command definitions tie the integration into Sublime Text.
- Architectural Patterns:
- The separation into a “plugin” (Sublime Text extension) versus “language-server” suggests a clear division of responsibilities often seen in client-server patterns within editor extensions.
- Use of templates and separate UI modules implies an MVC-like pattern for rendering and updating the user interface.

To accurately represent the project’s architecture, include the following components:

a. Main Components:
- Sublime Text Editor Environment – the host platform where the plugin runs.
- LSP-copilot Plugin (Python-based):
- Handles user commands (e.g., sign-in, code completions, chat interactions).
- Manages UI components (inline completion popups, phantoms, and panels) as found in the plugin/ui and templates directories.
- Loads settings from LSP-copilot.sublime-settings.
- Language Server (Node.js-based):
- Initiates a child process or separate service that communicates with GitHub Copilot.
- Uses package.json–driven dependencies to interact with external Copilot APIs.
- External Copilot Service (GitHub Copilot / OpenAI Codex):
- Receives requests from the language server for code suggestions.
- Sends back completions and other suggestions.
- Network & Authentication Component:
- Initiates the sign-in process (execute “Copilot: Sign In” command), manages the authentication workflow with GitHub, and handles subscriptions.

b. Relationships & Interactions:
- The user interacts with Sublime Text and triggers commands (via the command palette or key bindings).
- The plugin (acting as the LSP client) communicates with the language server, sending both user requests and receiving completion data.
- The language server relays requests to the external Copilot service, likely handling authentication details, proxy settings, and telemetry data as configured.
- Data flows back reciprocally: from Copilot service to the language server, then to the plugin, which updates the Sublime Text UI accordingly.

c. Architectural Patterns & Design Principles:
- Separation of concerns: Dividing UI logic (plugin) from backend communication (language server).
- Client-Server communication: Clearly mark the interactions via LSP protocols.
- Modular design: The structure (with distinct directories for various functionalities such as commands, listeners, and UI elements) assists in isolating functionalities.

d. Technologies, Frameworks & Libraries:
- Python for the Sublime Text plugin components.
- Node.js (with NPM dependencies defined in package.json) for the language server.
- Sublime Text’s Package Control system to manage installation.
- The Language Server Protocol (LSP) indicating that standard LSP methods and configuration are employed.
- Use of templating (Jinja templates in plugin/templates) for dynamic UI rendering.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    ST["Sublime Text Editor Environment"]:::editor
    subgraph "LSP-copilot Plugin (Python)"
        Plugin_Core["Core Plugin Logic"]:::plugin
        Plugin_UI["UI Components (chat, popup, panel)"]:::plugin
        Plugin_Settings["Settings Loader"]:::plugin
    end
    LangServer["Language Server (Node.js)"]:::lang
    AuthNet["Authentication & Networking"]:::auth
    Copilot["GitHub Copilot / OpenAI Codex Service"]:::external

    %% Flow connections
    ST -->|"triggers"| Plugin_Core
    Plugin_Core -->|"LSP-request"| LangServer
    LangServer -->|"API-request"| Copilot
    Copilot -->|"API-response"| LangServer
    LangServer -->|"completion-data"| Plugin_Core
    Plugin_Core -->|"sign-in"| AuthNet
    AuthNet -->|"auth-request"| Copilot

    %% Additional internal connections within Plugin
    Plugin_Core -->|"updates"| Plugin_UI
    Plugin_Core -->|"loads"| Plugin_Settings

    %% Click Events
    click ST "https://github.com/terminalfi/lsp-copilot/blob/master/Default.sublime-keymap"
    click ST "https://github.com/terminalfi/lsp-copilot/blob/master/LSP-copilot.sublime-commands"
    click ST "https://github.com/terminalfi/lsp-copilot/blob/master/Main.sublime-commands"
    click ST "https://github.com/terminalfi/lsp-copilot/blob/master/Main.sublime-menu"
    click Plugin_Core "https://github.com/terminalfi/lsp-copilot/tree/master/plugin/"
    click Plugin_UI "https://github.com/terminalfi/lsp-copilot/tree/master/plugin/ui/"
    click Plugin_UI "https://github.com/terminalfi/lsp-copilot/tree/master/plugin/templates/"
    click Plugin_Settings "https://github.com/terminalfi/lsp-copilot/blob/master/LSP-copilot.sublime-settings"
    click LangServer "https://github.com/terminalfi/lsp-copilot/tree/master/language-server/"

    %% Classes and styles
    classDef editor fill:#FFF3B0,stroke:#B8860B,stroke-width:2px;
    classDef plugin fill:#B0E0E6,stroke:#4682B4,stroke-width:2px;
    classDef lang fill:#98FB98,stroke:#2E8B57,stroke-width:2px;
    classDef auth fill:#FFDAB9,stroke:#FF8C00,stroke-width:2px;
    classDef external fill:#E6E6FA,stroke:#8A2BE2,stroke-width:2px;
```
