Skip to content

feat(core): support filetype syntax and lsp routing#69

Merged
fcoury merged 3 commits into
masterfrom
syntax-filetypes
May 29, 2026
Merged

feat(core): support filetype syntax and lsp routing#69
fcoury merged 3 commits into
masterfrom
syntax-filetypes

Conversation

@fcoury
Copy link
Copy Markdown
Contributor

@fcoury fcoury commented May 28, 2026

Why

Red previously treated syntax highlighting and language-server startup as effectively Rust-centered behavior. That made Markdown files appear mostly unhighlighted, made non-Rust files miss language-aware rendering, and made it difficult to route files to the right language server when a single server handles multiple document types. This PR makes filetype detection explicit so syntax highlighting, Markdown code fences, and LSP document selection can follow the file being edited.

What Changed

  • Added a Tree-sitter highlighter registry in src/highlighter.rs with compiled-in support for Rust, Markdown, JavaScript, TypeScript/TSX, JSON, TOML, YAML, Python, and Bash.
  • Replaced the Markdown highlight query with theme-compatible scopes and added Markdown fenced-code injections so rust, json, and sh fenced blocks receive nested syntax highlighting.
  • Updated rendering style selection in src/editor.rs so narrower injected spans override broad Markdown raw-block styling.
  • Expanded LSP configuration in src/config.rs and src/lsp/manager.rs to support document selectors, extension-based language IDs, workspace-root detection, and lazy per-workspace server startup.
  • Added default LSP configs and sample config documentation for the supported common file types.

How to Test

  1. Start red on a Markdown file that contains a heading, a list item, and fenced code blocks using languages such as rust and sh.
  2. Confirm the Markdown heading/list syntax is colored and the code inside each fenced block receives the nested language highlighting instead of a single raw-block style.
  3. Open representative files such as main.rs, README.md, script.sh, config.toml, and package.json, and confirm each file renders with syntax highlighting appropriate to its extension.
  4. With the relevant language servers installed, open files with configured extensions and confirm the matching LSP starts only for matching documents. For TypeScript-family files, verify .ts, .tsx, .js, .jsx, .mjs, and .cjs route through the TypeScript server with the appropriate language ID.
  5. As a regression check, open an unknown extension and a Markdown fence with an unknown language name; both should remain usable and skip language-specific highlighting rather than erroring.

Targeted tests:

  • cargo test highlighter
  • cargo test

fcoury added 3 commits May 28, 2026 19:17
Add a compiled Tree-sitter language registry for common file types and select highlighting by buffer extension.

Extend LSP configuration with document selectors while preserving existing single-language server configs.
Parse Markdown fenced code blocks as Tree-sitter injections and merge their spans back into the outer document. Resolve fence languages through the highlighter registry so aliases and registered extensions can target supported parsers.

Prefer narrower, later style spans during rendering so injected syntax can override broad Markdown raw-block styling.
Register the Tree-sitter Bash grammar for shell file extensions and Markdown code fences. This lets `.sh`, `.bash`, and `.zsh` files plus `bash`, `sh`, `shell`, and `zsh` fences use the compiled-in highlighter.

Document Bash as syntax-highlighted and keep the LSP wording separate from the syntax list.
@fcoury fcoury merged commit 24fbc9b into master May 29, 2026
15 checks passed
@fcoury fcoury deleted the syntax-filetypes branch May 29, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant