дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-09 11:15:40 +02:00
feat(editor): Highlight languages without a CodeMirror mode from tree-sitter
Elixir files opened as plain text: highlighting only came from @codemirror/language-data, which has no Elixir mode. Grammars now carry their own highlights.scm; `doc_highlights` folds its captures into a small kind vocabulary (inner nodes and later patterns win, interpolation clears the string colour), memoised per document version on the incremental tree. The editor maps kinds onto Lezer tags, so colours follow the active scheme, and requests them only when no CodeMirror mode exists. Enabled for Elixir; other grammar-only languages need their query wired. Claude-Session: https://claude.ai/code/session_01B65qLEKnkeYTGdbwhLpjCu
Цей коміт міститься в:
1 джерело
4f74f22624
коміт
1572fc36ea
14 files changed
+543
-7
No files matched your search
@@ -1,6 +1,6 @@
|
||||
use crate::state::AppState;
|
||||
use ide_core::{ChangeSet, DocId, IdeError, IdeResult, OutlineItem, Range};
|
||||
use ide_language::FoldRange;
|
||||
use ide_language::{FoldRange, SyntaxHighlights};
|
||||
use ide_text::LineEnding;
|
||||
use ide_workspace::{DocumentInfo, HistoryEntry};
|
||||
use std::path::PathBuf;
|
||||
@@ -136,6 +136,22 @@ pub async fn doc_folding(window: Window, state: State<'_, AppState>, doc: DocId)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Tree-sitter highlighting for languages the UI has no CodeMirror mode for;
|
||||
/// empty when the grammar has no highlights query or the document is large.
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn doc_highlights(window: Window, state: State<'_, AppState>, doc: DocId) -> IdeResult<SyntaxHighlights> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || {
|
||||
let snap = project.documents.text_snapshot(doc)?;
|
||||
if snap.large {
|
||||
return Ok(SyntaxHighlights::default());
|
||||
}
|
||||
Ok(project.syntax.highlights(doc, &snap.language, snap.version, &snap.text))
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// Extend Selection (⌥↑): syntax ranges around `offset`, innermost first.
|
||||
/// Large documents fall back to word / line / document ranges.
|
||||
#[tauri::command]
|
||||
|
||||
@@ -74,6 +74,7 @@ pub fn builder() -> tauri_specta::Builder<tauri::Wry> {
|
||||
doc::doc_set_line_ending,
|
||||
doc::doc_outline,
|
||||
doc::doc_folding,
|
||||
doc::doc_highlights,
|
||||
doc::doc_selection_ranges,
|
||||
syntax::syntax_support,
|
||||
syntax::syntax_node_at,
|
||||
|
||||
Reference in new issue
Заблокувати користувача