editor_core_lang/lib.rs
1#![warn(missing_docs)]
2//! `editor-core-lang` - data-driven language configuration helpers for `editor-core`.
3//!
4//! This crate intentionally stays lightweight and does **not** depend on `lsp-types` or any
5//! parsing/highlighting systems. It provides small structs that hosts can use to configure
6//! editor-kernel features in a language-aware way.
7
8/// Comment tokens/config for a given language.
9///
10/// The editor kernel can use this to implement comment toggling in a UI-agnostic way.
11#[derive(Debug, Clone, PartialEq, Eq, Default)]
12pub struct CommentConfig {
13 /// Line comment token (e.g. `//`, `#`).
14 pub line: Option<String>,
15 /// Block comment start token (e.g. `/*`).
16 pub block_start: Option<String>,
17 /// Block comment end token (e.g. `*/`).
18 pub block_end: Option<String>,
19}
20
21impl CommentConfig {
22 /// Create a config that supports only line comments.
23 pub fn line(token: impl Into<String>) -> Self {
24 Self {
25 line: Some(token.into()),
26 block_start: None,
27 block_end: None,
28 }
29 }
30
31 /// Create a config that supports only block comments.
32 pub fn block(start: impl Into<String>, end: impl Into<String>) -> Self {
33 Self {
34 line: None,
35 block_start: Some(start.into()),
36 block_end: Some(end.into()),
37 }
38 }
39
40 /// Create a config that supports both line and block comments.
41 pub fn line_and_block(
42 line: impl Into<String>,
43 block_start: impl Into<String>,
44 block_end: impl Into<String>,
45 ) -> Self {
46 Self {
47 line: Some(line.into()),
48 block_start: Some(block_start.into()),
49 block_end: Some(block_end.into()),
50 }
51 }
52
53 /// Returns `true` if a line comment token is configured.
54 pub fn has_line(&self) -> bool {
55 self.line.as_deref().is_some_and(|s| !s.is_empty())
56 }
57
58 /// Returns `true` if both block comment tokens are configured.
59 pub fn has_block(&self) -> bool {
60 self.block_start.as_deref().is_some_and(|s| !s.is_empty())
61 && self.block_end.as_deref().is_some_and(|s| !s.is_empty())
62 }
63}