$ show microsoft/vscode-black-formatter
This repository is the official Microsoft Visual Studio Code extension for the Black Python code formatter. It provides formatting support for Python files directly within VS Code, including full-document, range, and multi-range formatting, as well as notebook cell formatting. The architecture follows a client-server LSP pattern: a TypeScript extension (client) communicates via stdio or named pipe with a Python LSP server that invokes Black. The server is built on pygls and lsprotocol, with a shared infrastructure library (`@vscode/common-python-lsp`) for common LSP utilities. The extension bundles Black as a dependency and supports flexible configuration (custom paths, interpreters, arguments). It includes comprehensive unit and integration tests for both TypeScript and Python components, with test fixtures covering edge cases like unformatted/formatted pairs, notebook scenarios, and internationalization. While the implementation is solid and follows established patterns for VS Code formatter extensions, it relies heavily on a shared submodule and has some minor version inconsistencies (e.g., outdated minimum version constant in the server code). The project is under active development (pre-release status) with automated CI/CD, dependency management via Dependabot, and AI-assisted workflows for issue triage and template synchronization.
The LLM identified 3 files worth highlighting for reuse:
Provides `get_text_edits` function that computes minimal text edits from old to new string using difflib, with an optional Levenshtein-based accelerator and a configurable timeout fallback to a simple single-document replacement. This is a self-contained utility (only depends on standard library and lightweight lsp_utils/compat wrappers) that could be extracted for any LSP server needing efficient text diff generation.
A reusable LspSession class that wraps a subprocess running an LSP server, providing methods for initialize, shutdown, notifications, and formatting requests (textDocument/formatting, rangeFormatting, notebook cell formatting). It handles JSON-RPC communication and can be used by any project to test an LSP server without relying on Visual Studio Code.
Injects mock pygls and lsprotocol modules into sys.modules to allow unit testing the LSP server logic (`lsp_server.py`) without the full extension environment. This pattern enables isolated testing of server modules that import from these frameworks and is adaptable for other LSP server test suites.