diff --git a/Cargo.lock b/Cargo.lock index d9c2a89..12aa76b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -634,6 +634,16 @@ dependencies = [ "tree-sitter-language", ] +[[package]] +name = "tree-sitter-d" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66c6fa0082e20747a92c5c863cadb7775fbe344f212837f03fc0f7187adf6fd1" +dependencies = [ + "cc", + "tree-sitter-language", +] + [[package]] name = "tree-sitter-haskell" version = "0.23.1" @@ -716,6 +726,7 @@ dependencies = [ "streaming-iterator", "sugar_path", "tree-sitter", + "tree-sitter-d", "tree-sitter-haskell", "tree-sitter-javascript", "tree-sitter-language", diff --git a/Cargo.toml b/Cargo.toml index 8b31e83..f027460 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ path = "src/main.rs" [dependencies] tree-sitter = ">=0.20" npezza93_tree-sitter-tags = ">=0.21.2" +tree-sitter-d = ">=0.8.2" tree-sitter-javascript = ">=0.20" tree-sitter-ruby = ">=0.20" tree-sitter-rust = ">=0.20" diff --git a/README.md b/README.md index ba285de..d021bc0 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ ttags $(git ls-files) ### Supported languages +- [x] D - [x] Haskell - [x] JavaScript - [x] Nix diff --git a/d/tags.scm b/d/tags.scm new file mode 100644 index 0000000..b596e50 --- /dev/null +++ b/d/tags.scm @@ -0,0 +1,21 @@ +(module_def (module_declaration (module_fqn) @name)) @definition.module + +(struct_declaration (struct) . (identifier) @name) @definition.class +(interface_declaration (interface) . (identifier) @name) @definition.interface +(enum_declaration (enum) . (identifier) @name) @definition.type + +(class_declaration (class) . (identifier) @name) @definition.class +(constructor (this) @name) @definition.method +(destructor (this) @name) @definition.method +(postblit (this) @name) @definition.method + +(manifest_declarator . (identifier) @name) @definition.type + +(function_declaration (identifier) @name) @definition.function + +(union_declaration (union) . (identifier) @name) @definition.type + +(anonymous_enum_declaration (enum_member . (identifier) @name)) @definition.constant + +(enum_declaration (enum_member . (identifier) @name)) @definition.constant + diff --git a/src/d.rs b/src/d.rs new file mode 100644 index 0000000..472cde8 --- /dev/null +++ b/src/d.rs @@ -0,0 +1,30 @@ +use npezza93_tree_sitter_tags::{Tag as TSTag, TagsConfiguration}; +use std::str; + +use crate::default_generate_tags; +use crate::tag::Tag; + +pub fn config() -> TagsConfiguration { + TagsConfiguration::new( + tree_sitter_d::LANGUAGE.into(), include_str!("../d/tags.scm"), + "", + ) + .unwrap() +} + +default_generate_tags!(); + +fn create_tag<'a>(name: &'a str, node_name: &'a str, tag: &'a TSTag, filename: &'a str) -> Tag { + let row = tag.span.start.row; + + let kind = match node_name { + "method" | "function" => "f", + "class" | "interface" => "c", + "module" => "m", + "constant" => "C", + "type" => "e", + _ => node_name, + }; + + Tag::new(name, filename, row + 1, kind) +} diff --git a/src/lib.rs b/src/lib.rs index 0fa7cbc..6187722 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ use std::error::Error; pub mod cli; pub mod config; +pub mod d; pub mod generate; pub mod haskell; pub mod javascript; diff --git a/src/tagger.rs b/src/tagger.rs index 8857792..32a040e 100644 --- a/src/tagger.rs +++ b/src/tagger.rs @@ -7,6 +7,7 @@ use std::path::Path; use std::process::exit; use crate::config::Config; +use crate::d; use crate::haskell; use crate::javascript; use crate::nix; @@ -17,6 +18,7 @@ use crate::tag::Tag; pub struct Tagger<'a> { pub context: TagsContext, + pub d_config: TagsConfiguration, pub ruby_config: TagsConfiguration, pub javascript_config: TagsConfiguration, pub rust_config: TagsConfiguration, @@ -29,6 +31,7 @@ pub struct Tagger<'a> { impl Tagger<'_> { pub fn new(config: &'_ Config) -> Tagger<'_> { let context = TagsContext::new(); + let d_config = d::config(); let ruby_config = ruby::config(); let javascript_config = javascript::config(); let rust_config = rust::config(); @@ -39,6 +42,7 @@ impl Tagger<'_> { Tagger { config, context, + d_config, ruby_config, javascript_config, rust_config, @@ -113,9 +117,12 @@ impl Tagger<'_> { fn type_mapping(&mut self, kind: Option<&str>, filename: &str, contents: &[u8]) -> Vec { match kind { + Some("d") => { + d::generate_tags(&mut self.context, &self.d_config, filename, contents) + }, Some("rb") => { ruby::generate_tags(&mut self.context, &self.ruby_config, filename, contents) - } + }, Some("js") => javascript::generate_tags( &mut self.context, &self.javascript_config,