clippy lints

pull/8/head
Blaž Hrastnik 3 years ago
parent 2088c45075
commit a16c6e2585

@ -274,13 +274,13 @@ fn is_word(ch: char) -> bool {
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
enum Category { enum Category {
Whitespace, Whitespace,
EOL, Eol,
Word, Word,
Punctuation, Punctuation,
} }
fn categorize(ch: char) -> Category { fn categorize(ch: char) -> Category {
if ch == '\n' { if ch == '\n' {
Category::EOL Category::Eol
} else if ch.is_ascii_whitespace() { } else if ch.is_ascii_whitespace() {
Category::Whitespace Category::Whitespace
} else if ch.is_ascii_punctuation() { } else if ch.is_ascii_punctuation() {

@ -1,5 +1,5 @@
use crate::{Change, Rope, RopeSlice, Transaction}; use crate::{Change, Rope, RopeSlice, Transaction};
pub use helix_syntax::LANG; pub use helix_syntax::Lang;
pub use helix_syntax::{get_language, get_language_name}; pub use helix_syntax::{get_language, get_language_name};
use std::collections::HashMap; use std::collections::HashMap;
@ -21,7 +21,7 @@ pub struct LanguageConfiguration {
// //
// root_path // root_path
// //
pub(crate) language_id: LANG, pub(crate) language_id: Lang,
pub(crate) highlight_config: OnceCell<Option<Arc<HighlightConfiguration>>>, pub(crate) highlight_config: OnceCell<Option<Arc<HighlightConfiguration>>>,
// tags_config OnceCell<> https://github.com/tree-sitter/tree-sitter/pull/583 // tags_config OnceCell<> https://github.com/tree-sitter/tree-sitter/pull/583
} }
@ -87,7 +87,7 @@ impl Loader {
LanguageConfiguration { LanguageConfiguration {
scope: "source.rust".to_string(), scope: "source.rust".to_string(),
file_types: vec!["rs".to_string()], file_types: vec!["rs".to_string()],
language_id: LANG::Rust, language_id: Lang::Rust,
highlight_config: OnceCell::new(), highlight_config: OnceCell::new(),
// //
path: "../helix-syntax/languages/tree-sitter-rust".into(), path: "../helix-syntax/languages/tree-sitter-rust".into(),
@ -95,7 +95,7 @@ impl Loader {
LanguageConfiguration { LanguageConfiguration {
scope: "source.toml".to_string(), scope: "source.toml".to_string(),
file_types: vec!["toml".to_string()], file_types: vec!["toml".to_string()],
language_id: LANG::Toml, language_id: Lang::Toml,
highlight_config: OnceCell::new(), highlight_config: OnceCell::new(),
// //
path: "../helix-syntax/languages/tree-sitter-toml".into(), path: "../helix-syntax/languages/tree-sitter-toml".into(),
@ -160,7 +160,7 @@ pub struct Syntax {
impl Syntax { impl Syntax {
// buffer, grammar, config, grammars, sync_timeout? // buffer, grammar, config, grammars, sync_timeout?
pub fn new( pub fn new(
/*language: LANG,*/ source: &Rope, /*language: Lang,*/ source: &Rope,
config: Arc<HighlightConfiguration>, config: Arc<HighlightConfiguration>,
) -> Self { ) -> Self {
// fetch grammar for parser based on language string // fetch grammar for parser based on language string
@ -779,10 +779,10 @@ impl HighlightConfiguration {
non_local_variable_patterns, non_local_variable_patterns,
injection_content_capture_index, injection_content_capture_index,
injection_language_capture_index, injection_language_capture_index,
local_scope_capture_index,
local_def_capture_index, local_def_capture_index,
local_def_value_capture_index, local_def_value_capture_index,
local_ref_capture_index, local_ref_capture_index,
local_scope_capture_index,
}) })
} }
@ -1475,7 +1475,7 @@ fn test_parser() {
.map(String::from) .map(String::from)
.collect(); .collect();
let language = get_language(LANG::Rust); let language = get_language(Lang::Rust);
let mut config = HighlightConfiguration::new( let mut config = HighlightConfiguration::new(
language, language,
&std::fs::read_to_string( &std::fs::read_to_string(

@ -13,13 +13,11 @@ fn get_debug() -> bool {
fn collect_tree_sitter_dirs(ignore: Vec<String>) -> Vec<String> { fn collect_tree_sitter_dirs(ignore: Vec<String>) -> Vec<String> {
let mut dirs = Vec::new(); let mut dirs = Vec::new();
for entry in fs::read_dir("languages").unwrap() { for entry in fs::read_dir("languages").unwrap().flatten() {
if let Ok(entry) = entry { let path = entry.path();
let path = entry.path(); let dir = path.file_name().unwrap().to_str().unwrap().to_string();
let dir = path.file_name().unwrap().to_str().unwrap().to_string(); if !ignore.contains(&dir) {
if !ignore.contains(&dir) { dirs.push(dir);
dirs.push(dir);
}
} }
} }
dirs dirs
@ -31,24 +29,22 @@ fn collect_src_files(dir: &str) -> (Vec<String>, Vec<String>) {
let mut c_files = Vec::new(); let mut c_files = Vec::new();
let mut cpp_files = Vec::new(); let mut cpp_files = Vec::new();
let path = PathBuf::from("languages").join(&dir).join("src"); let path = PathBuf::from("languages").join(&dir).join("src");
for entry in fs::read_dir(path).unwrap() { for entry in fs::read_dir(path).unwrap().flatten() {
if let Ok(entry) = entry { let path = entry.path();
let path = entry.path(); if path
if path .file_stem()
.file_stem() .unwrap()
.unwrap() .to_str()
.to_str() .unwrap()
.unwrap() .starts_with("binding")
.starts_with("binding") {
{ continue;
continue; }
} if let Some(ext) = path.extension() {
if let Some(ext) = path.extension() { if ext == "c" {
if ext == "c" { c_files.push(path.to_str().unwrap().to_string());
c_files.push(path.to_str().unwrap().to_string()); } else if ext == "cc" || ext == "cpp" || ext == "cxx" {
} else if ext == "cc" || ext == "cpp" || ext == "cxx" { cpp_files.push(path.to_str().unwrap().to_string());
cpp_files.push(path.to_str().unwrap().to_string());
}
} }
} }
} }

@ -13,7 +13,7 @@ macro_rules! mk_extern {
macro_rules! mk_enum { macro_rules! mk_enum {
( $( $camel:ident ),* ) => { ( $( $camel:ident ),* ) => {
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
pub enum LANG { pub enum Lang {
$( $(
$camel, $camel,
)* )*
@ -25,11 +25,11 @@ macro_rules! mk_enum {
macro_rules! mk_get_language { macro_rules! mk_get_language {
( $( ($camel:ident, $name:ident) ),* ) => { ( $( ($camel:ident, $name:ident) ),* ) => {
#[must_use] #[must_use]
pub fn get_language(lang: LANG) -> Language { pub fn get_language(lang: Lang) -> Language {
unsafe { unsafe {
match lang { match lang {
$( $(
LANG::$camel => $name(), Lang::$camel => $name(),
)* )*
} }
} }
@ -41,10 +41,10 @@ macro_rules! mk_get_language {
macro_rules! mk_get_language_name { macro_rules! mk_get_language_name {
( $( $camel:ident ),* ) => { ( $( $camel:ident ),* ) => {
#[must_use] #[must_use]
pub const fn get_language_name(lang: LANG) -> &'static str { pub const fn get_language_name(lang: Lang) -> &'static str {
match lang { match lang {
$( $(
LANG::$camel => stringify!($camel), Lang::$camel => stringify!($camel),
)* )*
} }
} }

Loading…
Cancel
Save