Zed 的 Common Lisp 扩展
Common Lisp Extension for Zed

原始链接: https://github.com/etyurkin/zed-cl

## Zed Common Lisp 支持:摘要 此 Zed 编辑器扩展为 Common Lisp 开发提供强大的支持,具有集成的语言服务器协议 (LSP) 服务器和 Jupyter 内核集成。主要功能包括智能、类型感知的代码补全——显示参数名称、类型并优先显示用户定义的符号——以及由 tree-sitter 语法提供的语法高亮。 该扩展支持多包工作流,具有包限定的补全和信息丰富的悬停文档。 集中式的“主 REPL”架构能够实现 Zed、多个 Jupyter 内核和 LSP 服务器之间无缝的状态共享,从而实现实时代码评估和同步。 **安装需要:** SBCL、Quicklisp,以及可选的 Jupyter 和 ZeroMQ。 设置包括通过 Zed 的扩展管理器安装扩展或克隆 GitHub 仓库。 安装后,LSP 会自动激活 `.lisp`、`.lsp`、`.cl`、`.asd` 和 `.ros` 文件。 Jupyter 集成需要额外的 `make` 命令来安装和验证内核。

黑客新闻 新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Zed 的 Common Lisp 扩展 (github.com/etyurkin) 6 分,mike_ivanov 发表于 1 天前 | 隐藏 | 过去 | 收藏 | 讨论 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

Common Lisp language support for the Zed editor with integrated LSP server and Jupyter kernel support.

🎯 Smart Type-Aware Code Completion

Intelligent completions that detect type declarations and provide contextual example values:

;; After defining and evaluating:
(defun greet (name)
  (declare (type string name))
  (format t "Hello, ~a!~%" name))

;; Typing (gree shows:
(greet name)  ← Parameter name placeholder

Smart parameter completion:

  • Shows parameter names from function signatures
  • Includes type information when available
  • Works with both built-in and user-defined functions
  • Syntax highlighting with tree-sitter grammar
  • Autocomplete with parameter snippets and type-aware placeholders
  • Multi-package support with package-qualified completion (my-utils::internal-helper)
  • Package labels showing which package each symbol comes from
  • User package prioritization - your symbols appear first in completions
  • Hover documentation showing signatures and docstrings
  • Package hover - hover over package names to see symbols in that package
  • Symbol information from both built-in Common Lisp and user definitions
  • Document sync for real-time updates
  • Master REPL integration for querying user-defined symbols

🔄 Jupyter REPL Integration

  • Shared Master REPL: All Jupyter kernels and the LSP server share a single REPL environment
  • Live sync: Definitions from Jupyter automatically available in Zed LSP
  • Bidirectional: Code evaluated in Zed available in Jupyter
  • Multi-kernel support: Run multiple Jupyter kernels with shared state
  • Auto-reconnect: Handles REPL restarts gracefully
  • Syntax highlighting for all Common Lisp constructs
  • Rainbow brackets support
  • Multi-line s-expression evaluation
  • ASDF system definition support
  1. Open Zed
  2. Open the command palette (Cmd+Shift+P)
  3. Search for "zed: extensions"
  4. Search for "Common Lisp"
  5. Click "Install"
git clone https://github.com/etyurkin/zed-cl
cd zed-cl

In Zed:

  1. Go to Extensions (Cmd+Shift+P → "zed: extensions")
  2. Click "Install Dev Extension"
  3. Select the cloned directory
  • SBCL: Install via brew install sbcl (macOS) or your package manager
  • Quicklisp: Install from quicklisp.org
  • Jupyter (optional): Install via pip install jupyter jupyterlab
  • ZeroMQ (for Jupyter): Install via brew install zeromq (macOS)

Once installed, the LSP server starts automatically when you open a .lisp file:

  1. Open or create a .lisp file
  2. Start typing - you'll see:
    • Autocomplete for Common Lisp built-ins
    • Hover documentation
    • Symbol information

For the full experience with REPL evaluation and shared state:

# Install Jupyter kernel
make install

# Verify installation
make verify

# Start Jupyter
jupyter lab
;; Define a function
(defun factorial (n)
  "Calculate factorial of n"
  (declare (type integer n))
  (if (<= n 1)
      1
      (* n (factorial (- n 1)))))

;; Select the function with Cmd+Shift+Up
;; Press Ctrl+Shift+Enter to evaluate it in the REPL

;; Now type (fact and you'll see completion with package info:
factorial [common-lisp-user]  ← Your definition appears first!
factorial [alexandria]        ← Library symbols appear after

;; Hover over 'factorial' to see the documentation
;; Define functions in custom packages
(defpackage :my-utils
  (:use :cl)
  (:export #:add-numbers #:multiply-numbers))

(in-package :my-utils)

(defun add-numbers (a b)
  "Add two numbers"
  (+ a b))

;; Select the above code
;; Press Ctrl+Shift+Enter to evaluate in the REPL

;; In another file, use package-qualified completion:
;; Type (my-utils:: to see all symbols in the package
;; Type (my-utils::add to complete to add-numbers

;; Hover over 'my-utils' to see all package symbols
;; Package tooltip shows:
;;   Package: my-utils
;;   User-defined package
;;   Symbols (2):
;;   - add-numbers (function)
;;   - multiply-numbers (function)

In one file:

(defvar *config*
  '(:database "mydb" :port 5432))

In another file:

(getf *config* :port)  ; => 5432
;; Hover over *config* shows the value!
;; Autocomplete suggests *config*

All files share the same REPL environment via the master REPL architecture.

Supported File Extensions

  • .lisp - Common Lisp source files
  • .lsp - Lisp source files
  • .l - Lisp files
  • .cl - Common Lisp files
  • .asd - ASDF system definitions
  • .ros - Roswell scripts
┌─────────────────────────────────┐
│      Master REPL Process        │
│  (Shared Lisp Environment)      │
└──────────┬──────────────────────┘
           │
    ┌──────┴───────┬──────────────┐
    │              │              │
┌───▼────┐    ┌───▼────┐    ┌───▼────┐
│Jupyter │    │Jupyter │    │  Zed   │
│Kernel 1│    │Kernel 2│    │  LSP   │
└────────┘    └────────┘    └────────┘

All components connect to a single master REPL for true state sharing.

This extension uses tree-sitter-commonlisp, automatically downloaded and compiled by Zed.

# Jupyter Kernel
make install        # Install Jupyter kernel
make verify         # Verify installation and dependencies
make uninstall      # Uninstall kernel
make test-jupyter   # Test kernel manually

# Master REPL
make start-repl     # Start master REPL server
make stop-repl      # Stop master REPL (resets environment)
make repl-status    # Check master REPL and kernel status

# Maintenance
make clean          # Clean temporary files
make help           # Show all available commands
  • Check Zed's language server logs
  • Ensure SBCL is installed: which sbcl
  • Check Zed's extension installation succeeded
  • Check master REPL is running: ls /tmp/cl-master-repl.sock
  • Verify LSP server is connected (check Zed's language server logs)
  • Try restarting Zed to reconnect to master REPL

Jupyter kernel won't start

  • Run make verify to check dependencies
  • Ensure Jupyter is installed: pip install jupyter jupyterlab
  • Ensure ZeroMQ is installed: brew install zeromq (macOS)

Contributions are welcome! Please feel free to submit issues or pull requests.

  1. Clone the repository
  2. Install dev extension in Zed
  3. Make changes
  4. Test with a .lisp file

MIT

联系我们 contact @ memedata.com