Skip to content

Commit

Permalink
chore(language-scoping): Blanket impl Scoper for all LanguageScoper
Browse files Browse the repository at this point in the history
Might be a breaking change? Not sure.
  • Loading branch information
alexpovel committed Jul 28, 2024
1 parent 084df95 commit 6d8554b
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 52 deletions.
11 changes: 1 addition & 10 deletions src/scoping/langs/csharp.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{CodeQuery, Language, LanguageScoper, TSLanguage, TSQuery};
use crate::{
find::Find,
scoping::{langs::IGNORE, scope::RangesWithContext, Scoper},
};
use crate::{find::Find, scoping::langs::IGNORE};
use clap::ValueEnum;
use const_format::formatcp;
use std::{fmt::Debug, str::FromStr};
Expand Down Expand Up @@ -78,12 +75,6 @@ impl From<CustomCSharpQuery> for TSQuery {
}
}

impl Scoper for CSharp {
fn scope_raw<'viewee>(&self, input: &'viewee str) -> RangesWithContext<'viewee> {
self.scope_via_query(input).into()
}
}

impl LanguageScoper for CSharp {
fn lang() -> TSLanguage {
tree_sitter_c_sharp::language()
Expand Down
11 changes: 1 addition & 10 deletions src/scoping/langs/go.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{CodeQuery, Language, LanguageScoper, TSLanguage, TSQuery};
use crate::{
find::Find,
scoping::{langs::IGNORE, scope::RangesWithContext, Scoper},
};
use crate::{find::Find, scoping::langs::IGNORE};
use clap::ValueEnum;
use const_format::formatcp;
use std::{fmt::Debug, str::FromStr};
Expand Down Expand Up @@ -77,12 +74,6 @@ impl From<CustomGoQuery> for TSQuery {
}
}

impl Scoper for Go {
fn scope_raw<'viewee>(&self, input: &'viewee str) -> RangesWithContext<'viewee> {
self.scope_via_query(input).into()
}
}

impl LanguageScoper for Go {
fn lang() -> TSLanguage {
tree_sitter_go::language()
Expand Down
11 changes: 1 addition & 10 deletions src/scoping/langs/hcl.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{CodeQuery, Language, LanguageScoper, TSLanguage, TSQuery};
use crate::{
find::Find,
scoping::{langs::IGNORE, scope::RangesWithContext, Scoper},
};
use crate::{find::Find, scoping::langs::IGNORE};
use clap::ValueEnum;
use const_format::formatcp;
use std::{fmt::Debug, str::FromStr};
Expand Down Expand Up @@ -257,12 +254,6 @@ impl From<CustomHclQuery> for TSQuery {
}
}

impl Scoper for Hcl {
fn scope_raw<'viewee>(&self, input: &'viewee str) -> RangesWithContext<'viewee> {
self.scope_via_query(input).into()
}
}

impl LanguageScoper for Hcl {
fn lang() -> TSLanguage {
tree_sitter_hcl::language()
Expand Down
11 changes: 10 additions & 1 deletion src/scoping/langs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub(super) const IGNORE: &str = "_SRGN_IGNORE";
/// A scoper for a language.
///
/// Functions much the same, but provides specific language-related functionality.
pub trait LanguageScoper: Scoper + Find {
pub trait LanguageScoper: Find + Send + Sync {
/// The language's tree-sitter language.
fn lang() -> TSLanguage
where
Expand Down Expand Up @@ -204,3 +204,12 @@ pub trait LanguageScoper: Scoper + Find {
}
}
}

impl<T> Scoper for T
where
T: LanguageScoper,
{
fn scope_raw<'viewee>(&self, input: &'viewee str) -> super::scope::RangesWithContext<'viewee> {
self.scope_via_query(input).into()
}
}
8 changes: 1 addition & 7 deletions src/scoping/langs/python.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{CodeQuery, Find, Language, LanguageScoper, TSLanguage, TSQuery};
use crate::scoping::{langs::IGNORE, scope::RangesWithContext, Scoper};
use crate::scoping::langs::IGNORE;
use clap::ValueEnum;
use const_format::formatcp;
use std::{fmt::Debug, str::FromStr};
Expand Down Expand Up @@ -114,12 +114,6 @@ impl From<CustomPythonQuery> for TSQuery {
}
}

impl Scoper for Python {
fn scope_raw<'viewee>(&self, input: &'viewee str) -> RangesWithContext<'viewee> {
self.scope_via_query(input).into()
}
}

impl LanguageScoper for Python {
fn lang() -> TSLanguage {
tree_sitter_python::language()
Expand Down
7 changes: 0 additions & 7 deletions src/scoping/langs/rust.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::{CodeQuery, Find, Language, LanguageScoper, TSLanguage, TSQuery};
use crate::scoping::{scope::RangesWithContext, Scoper};
use clap::ValueEnum;
use std::{fmt::Debug, str::FromStr};
use tree_sitter::QueryError;
Expand Down Expand Up @@ -94,12 +93,6 @@ impl From<CustomRustQuery> for TSQuery {
}
}

impl Scoper for Rust {
fn scope_raw<'viewee>(&self, input: &'viewee str) -> RangesWithContext<'viewee> {
self.scope_via_query(input).into()
}
}

impl LanguageScoper for Rust {
fn lang() -> TSLanguage {
tree_sitter_rust::language()
Expand Down
7 changes: 0 additions & 7 deletions src/scoping/langs/typescript.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::{CodeQuery, Find, Language, LanguageScoper, TSLanguage, TSQuery};
use crate::scoping::{scope::RangesWithContext, Scoper};
use clap::ValueEnum;
use std::{fmt::Debug, str::FromStr};
use tree_sitter::QueryError;
Expand Down Expand Up @@ -57,12 +56,6 @@ impl From<CustomTypeScriptQuery> for TSQuery {
}
}

impl Scoper for TypeScript {
fn scope_raw<'viewee>(&self, input: &'viewee str) -> RangesWithContext<'viewee> {
self.scope_via_query(input).into()
}
}

impl LanguageScoper for TypeScript {
fn lang() -> TSLanguage {
tree_sitter_typescript::language_typescript()
Expand Down

0 comments on commit 6d8554b

Please sign in to comment.