tm_anode_api/
lib.rs

1use const_cstr::{const_cstr, ConstCStr};
2use machinery::{identifier, Identifier};
3use machinery_api::{
4    foundation::{ApplicationO, VersionT},
5    plugins::ui::DockingFindTabOptT,
6    Api,
7};
8use tree_sitter::Language;
9
10/// Anode editor API.
11#[repr(C)]
12pub struct AnodeApi {
13    /// Open an asset in an editor tab.
14    ///
15    /// Creates a new tab with this asset's contents open, or focuses the existing tab if one
16    /// already exists.
17    pub open_asset: unsafe extern "C" fn(app: *mut ApplicationO, opt: *const DockingFindTabOptT),
18}
19
20unsafe impl Send for AnodeApi {}
21unsafe impl Sync for AnodeApi {}
22
23impl Api for AnodeApi {
24    const NAME: ConstCStr = const_cstr!("tm_anode_api");
25    const VERSION: VersionT = VersionT {
26        major: 0,
27        minor: 1,
28        patch: 0,
29    };
30}
31
32/// Aspect for assets opened in an anode editor.
33pub struct AnodeAspectI {
34    /// Anode expects the asset's data to be a UTF-8 buffer **without nul terminator**.
35    pub property: u32,
36    /// Highlighting language description.
37    pub highlighting: *const Highlighting,
38}
39
40unsafe impl Send for AnodeAspectI {}
41unsafe impl Sync for AnodeAspectI {}
42
43pub const ASPECT_ANODE: Identifier = identifier!("tm_anode_aspect_i");
44
45/// Highlighting language description.
46///
47/// Highlighting is provided by tree-sitter, see [tree-sitter's documentation][1] on how to define
48/// new languages. String values are expected to be in UTF-8 arrays **without nul terminator**.
49///
50/// [1]: https://tree-sitter.github.io
51pub struct Highlighting {
52    pub language: Language,
53    pub highlight_query: *const u8,
54    pub highlight_query_len: usize,
55    pub injection_query: *const u8,
56    pub injection_query_len: usize,
57    pub locals_query: *const u8,
58    pub locals_query_len: usize,
59}
60
61unsafe impl Send for Highlighting {}
62unsafe impl Sync for Highlighting {}