monaco-editor-lsp-next
Go to file
2025-03-12 15:04:29 +08:00
.github/workflows feat(workflow): split Docker build and push into separate workflows for Monaco and LSP images 2025-03-11 14:41:48 +08:00
docker/lsp/clangd feat(docker): simplify docker compose commands and add compose.yml for service configuration 2025-02-21 19:56:49 +08:00
prisma feat(prisma): add initial migration 2025-03-11 15:53:43 +08:00
public feat(public): add UI images for system, light and dark themes to public folder 2025-03-06 22:44:58 +08:00
src feat(auth): create route.ts for NextAuth API handler 2025-03-12 15:02:02 +08:00
.dockerignore chore(dockerignore): add exception for prisma/schema.prisma 2025-03-06 14:39:44 +08:00
.env.example chore(env): add .env.example with PostgreSQL connection string example 2025-03-06 16:58:53 +08:00
.env.local.example chore(example): add AUTH_SECRET to .env.local.example 2025-03-12 15:00:03 +08:00
.gitignore chore(gitignore): remove prisma/migrations from ignored files 2025-03-11 15:52:25 +08:00
bun.lock chore(deps): add @auth/prisma-adapter and update @prisma/client, prisma versions 2025-03-12 15:04:29 +08:00
components.json chore: initialize shadcn/ui 2025-02-19 09:07:30 +08:00
compose.local.yml chore(docker): change default USER to root in Dockerfile and remove user: root in Compose 2025-03-06 00:32:56 +08:00
compose.yml chore(docker): change default USER to root in Dockerfile and remove user: root in Compose 2025-03-06 00:32:56 +08:00
demo.png chore(images): replace demo image with new version 2025-03-05 10:30:27 +08:00
Dockerfile chore(docker): copy prisma folder before installing dependencies 2025-03-06 14:43:23 +08:00
eslint.config.mjs chore: initialize the project 2025-02-19 09:00:15 +08:00
LICENSE chore: add MIT License file to the repository 2025-02-19 18:38:49 +08:00
next.config.ts feat(next.config): add dockerode to serverExternalPackages 2025-02-26 21:18:33 +08:00
package.json chore(deps): add @auth/prisma-adapter and update @prisma/client, prisma versions 2025-03-12 15:04:29 +08:00
postcss.config.mjs chore(postcss): support GitHub Markdown theme switching 2025-03-06 21:19:48 +08:00
README.md docs(readme): clarify LSP configuration limitations and upcoming improvements 2025-03-10 11:44:10 +08:00
tailwind.config.ts feat(components/ui): add Sidebar-13 component from shadcn/ui 2025-03-03 14:51:13 +08:00
tsconfig.json chore: initialize the project 2025-02-19 09:00:15 +08:00

monaco-editor-lsp-next

A seamless Next.js integration of the Monaco Editor with robust LSP support all without SSR hassles.

demo

⚠️ LSP Configuration and Environment Variable Limitations

Warning: Pre-built Image LSP Configuration Limitations

The pre-built Docker image cfngc4594/monaco-editor-lsp-next is configured to connect exclusively to ws://localhost:4594/clangd and ws://localhost:4595/clangd. This is due to the LSP configuration being set via NEXT_PUBLIC environment variables during the image build process.

  • Build-Time Freezing: As per the Next.js official documentation, NEXT_PUBLIC variables are frozen at build time, and subsequent changes are ineffective.
  • Local LSP Server Dependency: Therefore, the pre-built image can only connect to the specified local LSP servers.
  • Custom Configuration Requirement: If you wish to define your own LSP configuration via environment variables, you cannot use the pre-built image. Instead, you must:
    • Clone the source code.
    • Set your desired environment variables.
    • Manually build the Docker image.

Upcoming Improvements (v0.0.1):

To address these limitations, v0.0.1 will implement the officially recommended API approach for retrieving LSP configurations, enabling runtime dynamic LSP server configuration without image rebuilding.

⚠️ WSL Users: Critical Configuration

🐧 Network Mode Requirement

When using Windows Subsystem for Linux (WSL), you must configure your network mode as Mirrored to ensure proper LSP server connectivity. Standard WSL network configurations may create IPv6 conflicts that block Monaco-LSP communication.

🔧 Mirror Mode Setup:

  1. Open WSL settings ⚙️
  2. Navigate to Network section 🌐
  3. Select Mirrored mode 🔄
  4. Restart WSL instance 💻

Complete these steps before launching the editor for seamless LSP integration! 🎉

🚀 Getting Started

Deploy the project quickly using pre-built Docker images:

# Clone the repository
git clone https://github.com/cfngc4594/monaco-editor-lsp-next
cd monaco-editor-lsp-next

# Start the application with pre-built images
docker compose up -d

🔨 Local Manual Build

Build the images locally and start the containers:

# Clone the repository
git clone https://github.com/cfngc4594/monaco-editor-lsp-next
cd monaco-editor-lsp-next

# Build and start containers using the local configuration
docker compose -f compose.local.yml up -d --build

🛠 Development Mode

Set up a development environment with hot-reloading:

# Clone the repository
git clone https://github.com/cfngc4594/monaco-editor-lsp-next
cd monaco-editor-lsp-next

# Start only the LSP containers
docker compose up -d lsp-c lsp-cpp
# Or use the local configuration
# docker compose -f compose.local.yml up -d --build lsp-c lsp-cpp

# Install dependencies and start the development server
bun install
bun run dev

⚙️ Technical Configuration

LSP Server Mapping

Language LSP Server Port
C clangd 4594
C++ clangd 4595

📦 Dependency Management

🔒 Version Lock Requirements

Critical Pairing:

Package Max Version Reference
monaco-editor ≤0.36.1 Compatibility Matrix
monaco-languageclient ≤5.0.1

Version Lock Rationale:

  1. API Stability

    • Newer monaco-editor (≥0.40.0) breaks monaco-languageclient integration
    • v0.36.1 matches @codingame/monaco-vscode-api@1.76.9 requirements
  2. LSP Feature Breakdown

    • Version mismatches disable:
      • Auto textDocument/didOpen events
      • textDocument/inlayHint resolution
      • textDocument/documentLink functionality
  3. Version Conflict

    • @codingame package versioning (e.g., 11.1.2) ≠ monaco-editor versions (e.g., 0.36.1)
    • @monaco-editor/react depends on monaco-editor versioning scheme

Failure Indicators:

  • ✔️ WebSocket connection established
  • Missing syntax highlighting
  • No autocomplete suggestions
  • Silent LSP initialization failures

🎨 Shiki Compatibility Notice

Syntax highlighting depends on rehype-pretty-code's deprecated getHighlighter API from shiki@legacy.

Key Points:

  • Affected File: src/components/mdx-preview.tsx

  • Dependency Chain: rehype-pretty-codeshiki@legacy

  • Version Constraints:

    "shiki": "<=2.5.0"
    "@shikijs/monaco": "<=2.5.0"
    

Maintenance Note:
While shiki@3.0.0+ introduces modern APIs (createHighlighter/getSingletonHighlighter), upgrading requires rehype-pretty-code updates. Track progress here.