feat(core): support filetype syntax and lsp routing#69
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
src/highlighter.rswith compiled-in support for Rust, Markdown, JavaScript, TypeScript/TSX, JSON, TOML, YAML, Python, and Bash.rust,json, andshfenced blocks receive nested syntax highlighting.src/editor.rsso narrower injected spans override broad Markdown raw-block styling.src/config.rsandsrc/lsp/manager.rsto support document selectors, extension-based language IDs, workspace-root detection, and lazy per-workspace server startup.How to Test
redon a Markdown file that contains a heading, a list item, and fenced code blocks using languages such asrustandsh.main.rs,README.md,script.sh,config.toml, andpackage.json, and confirm each file renders with syntax highlighting appropriate to its extension..ts,.tsx,.js,.jsx,.mjs, and.cjsroute through the TypeScript server with the appropriate language ID.Targeted tests:
cargo test highlightercargo test