# yegappan/lsp architecture

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

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

## Overview

##### Connection Flow

a) External Connections
- Vim Editor ↔ Plugin Interface (plugin/lsp.vim)
- LSP Client ↔ Language Servers

b) Internal Connections
- How feature modules communicate with the core LSP client
- Event flow for features like diagnostics and completion

##### Additional Details

Annotations for:

- Supported LSP features (list from README)
- Configuration options
- Server registration process
- Command handling flow

##### Implementation Notes

Callouts for:

- Vim9 script specifics
- Version requirements (Vim 9.0+)
- Language server integration points

Remember to emphasize the asynchronous nature of the LSP communication and how the plugin handles multiple language servers for different file types.

This design should help developers understand both the high-level architecture and the specific implementation details of the LSP plugin.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "External Interfaces"
        VIM[Vim Editor]
        LSP[Language Servers]
    end

    subgraph "Plugin Interface"
        PI["Plugin Interface"]:::interface
    end
    click PI "https://github.com/yegappan/lsp/blob/main/plugin/lsp.vim"

    subgraph "Core LSP Client"
        LSPClient["LSP Client"]:::core
        LSPServer["LSP Server Handler"]:::core
        Capabilities["Capabilities Manager"]:::core
        Handlers["Event Handlers"]:::core
    end
    click LSPClient "https://github.com/yegappan/lsp/blob/main/autoload/lsp/lsp.vim"
    click LSPServer "https://github.com/yegappan/lsp/blob/main/autoload/lsp/lspserver.vim"
    click Capabilities "https://github.com/yegappan/lsp/blob/main/autoload/lsp/capabilities.vim"
    click Handlers "https://github.com/yegappan/lsp/blob/main/autoload/lsp/handlers.vim"

    subgraph "Code Intelligence"
        Completion["Completion"]:::feature
        Hover["Hover"]:::feature
        Signature["Signature Help"]:::feature
        InlayHints["Inlay Hints"]:::feature
    end
    click Completion "https://github.com/yegappan/lsp/blob/main/autoload/lsp/completion.vim"
    click Hover "https://github.com/yegappan/lsp/blob/main/autoload/lsp/hover.vim"
    click Signature "https://github.com/yegappan/lsp/blob/main/autoload/lsp/signature.vim"
    click InlayHints "https://github.com/yegappan/lsp/blob/main/autoload/lsp/inlayhints.vim"

    subgraph "Navigation"
        CallHierarchy["Call Hierarchy"]:::feature
        TypeHierarchy["Type Hierarchy"]:::feature
        Outline["Outline"]:::feature
    end
    click CallHierarchy "https://github.com/yegappan/lsp/blob/main/autoload/lsp/callhierarchy.vim"
    click TypeHierarchy "https://github.com/yegappan/lsp/blob/main/autoload/lsp/typehierarchy.vim"
    click Outline "https://github.com/yegappan/lsp/blob/main/autoload/lsp/outline.vim"

    subgraph "Diagnostics"
        Diag["Diagnostics"]:::feature
    end
    click Diag "https://github.com/yegappan/lsp/blob/main/autoload/lsp/diag.vim"

    subgraph "Symbol Management"
        Symbol["Symbol"]:::feature
        SemanticHL["Semantic Highlight"]:::feature
    end
    click Symbol "https://github.com/yegappan/lsp/blob/main/autoload/lsp/symbol.vim"
    click SemanticHL "https://github.com/yegappan/lsp/blob/main/autoload/lsp/semantichighlight.vim"

    subgraph "Code Manipulation"
        CodeAction["Code Actions"]:::feature
        CodeLens["Code Lens"]:::feature
        TextEdit["Text Edit"]:::feature
    end
    click CodeAction "https://github.com/yegappan/lsp/blob/main/autoload/lsp/codeaction.vim"
    click CodeLens "https://github.com/yegappan/lsp/blob/main/autoload/lsp/codelens.vim"
    click TextEdit "https://github.com/yegappan/lsp/blob/main/autoload/lsp/textedit.vim"

    subgraph "Infrastructure"
        Util["Utilities"]:::util
        Buffer["Buffer Management"]:::util
        Offset["Offset Handler"]:::util
        Markdown["Markdown Parser"]:::util
    end
    click Util "https://github.com/yegappan/lsp/blob/main/autoload/lsp/util.vim"
    click Buffer "https://github.com/yegappan/lsp/blob/main/autoload/lsp/buffer.vim"
    click Offset "https://github.com/yegappan/lsp/blob/main/autoload/lsp/offset.vim"
    click Markdown "https://github.com/yegappan/lsp/blob/main/autoload/lsp/markdown.vim"

    subgraph "Configuration"
        Options["Options Manager"]:::config
    end
    click Options "https://github.com/yegappan/lsp/blob/main/autoload/lsp/options.vim"

    subgraph "Additional Features"
        Snippet["Snippet Support"]:::feature
        Selection["Selection Handler"]:::feature
    end
    click Snippet "https://github.com/yegappan/lsp/blob/main/autoload/lsp/snippet.vim"
    click Selection "https://github.com/yegappan/lsp/blob/main/autoload/lsp/selection.vi"

    %% Connections
    VIM --> PI
    PI --> LSPClient
    LSPClient <--> LSP
    LSPClient --> LSPServer
    LSPClient --> Capabilities
    LSPClient --> Handlers

    %% Feature connections
    LSPClient --> Completion
    LSPClient --> Hover
    LSPClient --> Signature
    LSPClient --> InlayHints
    LSPClient --> CallHierarchy
    LSPClient --> TypeHierarchy
    LSPClient --> Outline
    LSPClient --> Diag
    LSPClient --> Symbol
    LSPClient --> SemanticHL
    LSPClient --> CodeAction
    LSPClient --> CodeLens
    LSPClient --> TextEdit
    LSPClient --> Snippet
    LSPClient --> Selection

    %% Infrastructure connections
    Util --> LSPClient
    Buffer --> LSPClient
    Offset --> LSPClient
    Markdown --> LSPClient
    Options --> LSPClient

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef feature fill:#4CAF50,stroke:#2E7D32,color:white
    classDef util fill:#FFC107,stroke:#FFA000,color:black
    classDef config fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef interface fill:#607D8B,stroke:#455A64,color:white

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Feature Modules"]:::feature
        L3["Utility Modules"]:::util
        L4["Configuration"]:::config
        L5["Interface"]:::interface
    end
```
