on master help sign in
clippy lints
commita16c6e25852d985d90e56981a3aba62be012071d authorBlaž Hrastnik <blaz@mxxn.io> dateMon 1 Mar 2021, 17:37 (6 years ago) parent2088c45
4 files changed+35−39
helix-core/src/state.rs+2−2 helix-core/src/syntax.rs+7−7 helix-syntax/build.rs+21−25 helix-syntax/src/lib.rs+5−5
helix-core/src/state.rs+2−2
@@ -274,13 +274,13 @@ fn is_word(ch: char) -> bool {
274274#[derive(Debug, Eq, PartialEq)]
275275enum Category {
276276 Whitespace,
277− EOL,
277+ Eol,
278278 Word,
279279 Punctuation,
280280}
281281fn categorize(ch: char) -> Category {
282282 if ch == '\n' {
283− Category::EOL
283+ Category::Eol
284284 } else if ch.is_ascii_whitespace() {
285285 Category::Whitespace
286286 } else if ch.is_ascii_punctuation() {
helix-core/src/syntax.rs+7−7
@@ -1,5 +1,5 @@
11use crate::{Change, Rope, RopeSlice, Transaction};
2−pub use helix_syntax::LANG;
2+pub use helix_syntax::Lang;
33pub use helix_syntax::{get_language, get_language_name};
44
55use std::collections::HashMap;
@@ -21,7 +21,7 @@ pub struct LanguageConfiguration {
2121 //
2222 // root_path
2323 //
24− pub(crate) language_id: LANG,
24+ pub(crate) language_id: Lang,
2525 pub(crate) highlight_config: OnceCell<Option<Arc<HighlightConfiguration>>>,
2626 // tags_config OnceCell<> https://github.com/tree-sitter/tree-sitter/pull/583
2727}
@@ -87,7 +87,7 @@ impl Loader {
8787 LanguageConfiguration {
8888 scope: "source.rust".to_string(),
8989 file_types: vec!["rs".to_string()],
90− language_id: LANG::Rust,
90+ language_id: Lang::Rust,
9191 highlight_config: OnceCell::new(),
9292 //
9393 path: "../helix-syntax/languages/tree-sitter-rust".into(),
@@ -95,7 +95,7 @@ impl Loader {
9595 LanguageConfiguration {
9696 scope: "source.toml".to_string(),
9797 file_types: vec!["toml".to_string()],
98− language_id: LANG::Toml,
98+ language_id: Lang::Toml,
9999 highlight_config: OnceCell::new(),
100100 //
101101 path: "../helix-syntax/languages/tree-sitter-toml".into(),
@@ -160,7 +160,7 @@ pub struct Syntax {
160160impl Syntax {
161161 // buffer, grammar, config, grammars, sync_timeout?
162162 pub fn new(
163− /*language: LANG,*/ source: &Rope,
163+ /*language: Lang,*/ source: &Rope,
164164 config: Arc<HighlightConfiguration>,
165165 ) -> Self {
166166 // fetch grammar for parser based on language string
@@ -779,10 +779,10 @@ impl HighlightConfiguration {
779779 non_local_variable_patterns,
780780 injection_content_capture_index,
781781 injection_language_capture_index,
782+ local_scope_capture_index,
782783 local_def_capture_index,
783784 local_def_value_capture_index,
784785 local_ref_capture_index,
785− local_scope_capture_index,
786786 })
787787 }
788788
@@ -1475,7 +1475,7 @@ fn test_parser() {
14751475 .map(String::from)
14761476 .collect();
14771477
1478− let language = get_language(LANG::Rust);
1478+ let language = get_language(Lang::Rust);
14791479 let mut config = HighlightConfiguration::new(
14801480 language,
14811481 &std::fs::read_to_string(
helix-syntax/build.rs+21−25
@@ -13,13 +13,11 @@ fn get_debug() -> bool {
1313
1414fn collect_tree_sitter_dirs(ignore: Vec<String>) -> Vec<String> {
1515 let mut dirs = Vec::new();
16− for entry in fs::read_dir("languages").unwrap() {
17− if let Ok(entry) = entry {
18− let path = entry.path();
19− let dir = path.file_name().unwrap().to_str().unwrap().to_string();
20− if !ignore.contains(&dir) {
21− dirs.push(dir);
22− }
16+ for entry in fs::read_dir("languages").unwrap().flatten() {
17+ let path = entry.path();
18+ let dir = path.file_name().unwrap().to_str().unwrap().to_string();
19+ if !ignore.contains(&dir) {
20+ dirs.push(dir);
2321 }
2422 }
2523 dirs
@@ -31,24 +29,22 @@ fn collect_src_files(dir: &str) -> (Vec<String>, Vec<String>) {
3129 let mut c_files = Vec::new();
3230 let mut cpp_files = Vec::new();
3331 let path = PathBuf::from("languages").join(&dir).join("src");
34− for entry in fs::read_dir(path).unwrap() {
35− if let Ok(entry) = entry {
36− let path = entry.path();
37− if path
38− .file_stem()
39− .unwrap()
40− .to_str()
41− .unwrap()
42− .starts_with("binding")
43− {
44− continue;
45− }
46− if let Some(ext) = path.extension() {
47− if ext == "c" {
48− c_files.push(path.to_str().unwrap().to_string());
49− } else if ext == "cc" || ext == "cpp" || ext == "cxx" {
50− cpp_files.push(path.to_str().unwrap().to_string());
51− }
32+ for entry in fs::read_dir(path).unwrap().flatten() {
33+ let path = entry.path();
34+ if path
35+ .file_stem()
36+ .unwrap()
37+ .to_str()
38+ .unwrap()
39+ .starts_with("binding")
40+ {
41+ continue;
42+ }
43+ if let Some(ext) = path.extension() {
44+ if ext == "c" {
45+ c_files.push(path.to_str().unwrap().to_string());
46+ } else if ext == "cc" || ext == "cpp" || ext == "cxx" {
47+ cpp_files.push(path.to_str().unwrap().to_string());
5248 }
5349 }
5450 }
helix-syntax/src/lib.rs+5−5
@@ -13,7 +13,7 @@ macro_rules! mk_extern {
1313macro_rules! mk_enum {
1414 ( $( $camel:ident ),* ) => {
1515 #[derive(Clone, Copy, Debug, PartialEq)]
16− pub enum LANG {
16+ pub enum Lang {
1717 $(
1818 $camel,
1919 )*
@@ -25,11 +25,11 @@ macro_rules! mk_enum {
2525macro_rules! mk_get_language {
2626 ( $( ($camel:ident, $name:ident) ),* ) => {
2727 #[must_use]
28− pub fn get_language(lang: LANG) -> Language {
28+ pub fn get_language(lang: Lang) -> Language {
2929 unsafe {
3030 match lang {
3131 $(
32− LANG::$camel => $name(),
32+ Lang::$camel => $name(),
3333 )*
3434 }
3535 }
@@ -41,10 +41,10 @@ macro_rules! mk_get_language {
4141macro_rules! mk_get_language_name {
4242 ( $( $camel:ident ),* ) => {
4343 #[must_use]
44− pub const fn get_language_name(lang: LANG) -> &'static str {
44+ pub const fn get_language_name(lang: Lang) -> &'static str {
4545 match lang {
4646 $(
47− LANG::$camel => stringify!($camel),
47+ Lang::$camel => stringify!($camel),
4848 )*
4949 }
5050 }