Skip to content

Commit db4a913

Browse files
authored
Merge pull request #580 from CosmicHorrorDev/deprecate-scope-repo
docs: Deprecate `SCOPE_REPO` for removal
2 parents 2a3a09d + b480f26 commit db4a913

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/html.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::easy::{HighlightFile, HighlightLines};
33
use crate::escape::Escape;
44
use crate::highlighting::{Color, FontStyle, Style, Theme};
55
use crate::parsing::{
6-
BasicScopeStackOp, ParseState, Scope, ScopeStack, ScopeStackOp, SyntaxReference, SyntaxSet,
7-
SCOPE_REPO,
6+
lock_global_scope_repo, BasicScopeStackOp, ParseState, Scope, ScopeStack, ScopeStackOp,
7+
SyntaxReference, SyntaxSet,
88
};
99
use crate::util::LinesWithEndings;
1010
use crate::Error;
@@ -242,7 +242,7 @@ pub enum ClassStyle {
242242
}
243243

244244
fn scope_to_classes(s: &mut String, scope: Scope, style: ClassStyle) {
245-
let repo = SCOPE_REPO.lock().unwrap();
245+
let repo = lock_global_scope_repo();
246246
for i in 0..(scope.len()) {
247247
let atom = scope.atom_at(i as usize);
248248
let atom_s = repo.atom_str(atom);
@@ -260,7 +260,7 @@ fn scope_to_classes(s: &mut String, scope: Scope, style: ClassStyle) {
260260
}
261261

262262
fn scope_to_selector(s: &mut String, scope: Scope, style: ClassStyle) {
263-
let repo = SCOPE_REPO.lock().unwrap();
263+
let repo = lock_global_scope_repo();
264264
for i in 0..(scope.len()) {
265265
let atom = scope.atom_at(i as usize);
266266
let atom_s = repo.atom_str(atom);

src/parsing/scope.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::collections::HashMap;
44
use std::fmt;
55
use std::mem;
66
use std::str::FromStr;
7-
use std::sync::Mutex;
7+
use std::sync::{Mutex, MutexGuard};
88

99
use once_cell::sync::Lazy;
1010
use serde::de::{Deserialize, Deserializer, Error, Visitor};
@@ -30,9 +30,23 @@ pub const ATOM_LEN_BITS: u16 = 3;
3030
/// Ths shouldn't be necessary for you to use. See the [`ScopeRepository`] docs.
3131
///
3232
/// [`ScopeRepository`]: struct.ScopeRepository.html
33+
#[deprecated(
34+
since = "5.3.0",
35+
note = "\
36+
Deprecated in anticipation of removal in the next semver-breaking release under the \
37+
justification that it's incredibly niche functionality to expose. If you rely on this \
38+
functionality then please express your particular use-case in the github issue: \
39+
https://github.com/trishume/syntect/issues/575\
40+
"
41+
)]
3342
pub static SCOPE_REPO: Lazy<Mutex<ScopeRepository>> =
3443
Lazy::new(|| Mutex::new(ScopeRepository::new()));
3544

45+
pub(crate) fn lock_global_scope_repo() -> MutexGuard<'static, ScopeRepository> {
46+
#[allow(deprecated)]
47+
SCOPE_REPO.lock().unwrap()
48+
}
49+
3650
/// A hierarchy of atoms with semi-standardized names used to accord semantic information to a
3751
/// specific piece of text.
3852
///
@@ -221,7 +235,7 @@ impl Scope {
221235
///
222236
/// Example: `Scope::new("meta.rails.controller")`
223237
pub fn new(s: &str) -> Result<Scope, ParseScopeError> {
224-
let mut repo = SCOPE_REPO.lock().unwrap();
238+
let mut repo = lock_global_scope_repo();
225239
repo.build(s.trim())
226240
}
227241

@@ -266,7 +280,7 @@ impl Scope {
266280
///
267281
/// This requires locking a global repo and shouldn't be done frequently.
268282
pub fn build_string(self) -> String {
269-
let repo = SCOPE_REPO.lock().unwrap();
283+
let repo = lock_global_scope_repo();
270284
repo.to_string(self)
271285
}
272286

src/parsing/yaml_load.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl SyntaxDefinition {
9595
return Err(ParseSyntaxError::EmptyFile);
9696
}
9797
let doc = &docs[0];
98-
let mut scope_repo = SCOPE_REPO.lock().unwrap();
98+
let mut scope_repo = lock_global_scope_repo();
9999
SyntaxDefinition::parse_top_level(
100100
doc,
101101
scope_repo.deref_mut(),

0 commit comments

Comments
 (0)