Skip to content

Commit 771eefb

Browse files
committed
Adjust syntect-plugin for trishume/syntect#182
1 parent 508bbfc commit 771eefb

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

rust/syntect-plugin/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ serde_derive = "1.0"
1414
toml = "0.4"
1515

1616
[dependencies.syntect]
17-
version = "2.0"
17+
#version = "2.0"
1818
default-features = false
1919
features = ["parsing", "assets","dump-load-rs"]
20+
path = "/Users/rstocker/Projects/rust/syntect-3"
2021

2122
[dependencies.xi-plugin-lib]
2223
path = "../plugin-lib"

rust/syntect-plugin/examples/make_manifest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::path::{Path, PathBuf};
2525

2626
use xi_core::plugin_manifest::*;
2727
use xi_core::LanguageDefinition;
28-
use syntect::parsing::{SyntaxSet, SyntaxDefinition};
28+
use syntect::parsing::{SyntaxSet, SyntaxReference};
2929
use toml::Value;
3030

3131
const OUT_FILE_NAME: &str = "generated_manifest.toml";
@@ -68,7 +68,7 @@ fn main() -> Result<(), io::Error> {
6868
f.write_all(toml_str.as_ref())
6969
}
7070

71-
fn lang_from_syn<'a>(src: &'a SyntaxDefinition) -> LanguageDefinition {
71+
fn lang_from_syn<'a>(src: &'a SyntaxReference) -> LanguageDefinition {
7272
LanguageDefinition {
7373
name: src.name.as_str().into(),
7474
extensions: src.file_extensions.clone(),

rust/syntect-plugin/src/main.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ use xi_trace::{trace, trace_block};
3636
use xi_plugin_lib::{Cache, Plugin, StateCache, View, mainloop};
3737

3838
use syntect::parsing::{ParseState, ScopeStack, SyntaxSet, SCOPE_REPO,
39-
SyntaxDefinition, ScopeRepository};
39+
SyntaxReference, ScopeRepository};
4040
use stackmap::{StackMap, LookupResult};
4141

4242
const LINES_PER_RPC: usize = 10;
4343
const INDENTATION_PRIORITY: u64 = 100;
4444

4545
/// The state for syntax highlighting of one file.
46-
struct PluginState {
46+
struct PluginState<'a> {
4747
stack_idents: StackMap,
4848
offset: usize,
49-
initial_state: LineState,
49+
initial_state: LineState<'a>,
5050
spans_start: usize,
5151
// unflushed spans
5252
spans: Vec<ScopeSpan>,
@@ -60,15 +60,15 @@ type LockedRepo = MutexGuard<'static, ScopeRepository>;
6060
// Note: this needs to be option because the caching layer relies on Default.
6161
// We can't implement that because the actual initial state depends on the
6262
// syntax. There are other ways to handle this, but this will do for now.
63-
type LineState = Option<(ParseState, ScopeStack)>;
63+
type LineState<'a> = Option<(ParseState<'a>, ScopeStack)>;
6464

6565
/// The state of syntax highlighting for a collection of buffers.
6666
struct Syntect<'a> {
67-
view_state: HashMap<ViewId, PluginState>,
67+
view_state: HashMap<ViewId, PluginState<'a>>,
6868
syntax_set: &'a SyntaxSet,
6969
}
7070

71-
impl PluginState {
71+
impl<'a> PluginState<'a> {
7272
fn new() -> Self {
7373
PluginState {
7474
stack_idents: StackMap::default(),
@@ -81,7 +81,7 @@ impl PluginState {
8181
}
8282

8383
// compute syntax for one line, also accumulating the style spans
84-
fn compute_syntax(&mut self, line: &str, state: LineState) -> LineState {
84+
fn compute_syntax(&mut self, line: &str, state: LineState<'a>) -> LineState<'a> {
8585
let (mut parse_state, mut scope_state) = state.or_else(|| self.initial_state.clone()).unwrap();
8686
let ops = parse_state.parse_line(&line);
8787

@@ -127,7 +127,7 @@ impl PluginState {
127127

128128
#[allow(unused)]
129129
// Return true if there's any more work to be done.
130-
fn highlight_one_line(&mut self, ctx: &mut MyView) -> bool {
130+
fn highlight_one_line(&mut self, ctx: &mut MyView<'a>) -> bool {
131131
if let Some(line_num) = ctx.get_frontier() {
132132
let (line_num, offset, state) = ctx.get_prev(line_num);
133133
if offset != self.offset {
@@ -166,7 +166,7 @@ impl PluginState {
166166
false
167167
}
168168

169-
fn flush_spans(&mut self, ctx: &mut MyView) {
169+
fn flush_spans(&mut self, ctx: &mut MyView<'a>) {
170170
let _t = trace_block("PluginState::flush_spans", &["syntect"]);
171171
if !self.new_scopes.is_empty() {
172172
ctx.add_scopes(&self.new_scopes);
@@ -181,7 +181,7 @@ impl PluginState {
181181
}
182182
}
183183

184-
type MyView = View<StateCache<LineState>>;
184+
type MyView<'a> = View<StateCache<LineState<'a>>>;
185185

186186
impl<'a> Syntect<'a> {
187187
fn new(syntax_set: &'a SyntaxSet) -> Self {
@@ -192,10 +192,10 @@ impl<'a> Syntect<'a> {
192192
}
193193

194194
/// Wipes any existing state and starts highlighting with `syntax`.
195-
fn do_highlighting(&mut self, view: &mut MyView) {
195+
fn do_highlighting(&mut self, view: &mut MyView<'a>) {
196196
let initial_state = {
197197
let syntax = self.guess_syntax(view.get_path());
198-
Some((ParseState::new(syntax), ScopeStack::new()))
198+
Some((ParseState::new(self.syntax_set, syntax), ScopeStack::new()))
199199
};
200200

201201
let state = self.view_state.get_mut(&view.get_id()).unwrap();
@@ -208,7 +208,7 @@ impl<'a> Syntect<'a> {
208208
view.schedule_idle();
209209
}
210210

211-
fn guess_syntax(&'a self, path: Option<&Path>) -> &'a SyntaxDefinition {
211+
fn guess_syntax(&self, path: Option<&Path>) -> &'a SyntaxReference {
212212
let _t = trace_block("Syntect::guess_syntax", &["syntect"]);
213213
match path {
214214
Some(path) => self.syntax_set.find_syntax_for_file(path)
@@ -297,7 +297,7 @@ impl<'a> Syntect<'a> {
297297

298298

299299
impl<'a> Plugin for Syntect<'a> {
300-
type Cache = StateCache<LineState>;
300+
type Cache = StateCache<LineState<'a>>;
301301

302302
fn new_view(&mut self, view: &mut View<Self::Cache>) {
303303
let _t = trace_block("Syntect::new_view", &["syntect"]);

0 commit comments

Comments
 (0)