From 01e67ee577a565112a85d5ddef1f228549df1bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=E9=87=91=E5=8F=AF=E6=98=8E?= Date: Sun, 13 Aug 2023 08:41:40 +0200 Subject: [PATCH 1/3] feat: add support for scala (resolves #288) --- ftplugin/_scala.vim | 108 ------------ ftplugin/scala.vim | 16 ++ helper/.editorconfig | 3 + helper/Cargo.lock | 12 +- helper/Cargo.toml | 1 + helper/src/config.rs | 1 + helper/src/docblock.rs | 2 + helper/src/lib.rs | 1 + helper/src/r/docs/roxygen2.yaml | 36 ++-- helper/src/scala/docs/scaladoc.yaml | 45 +++++ helper/src/scala/mod.rs | 1 + helper/src/scala/parser.rs | 165 ++++++++++++++++++ helper/test.r | 20 --- test/filetypes/r/functions.vader | 6 + test/filetypes/scala/classes.vader | 109 ++++++++++++ test/filetypes/scala/functions.vader | 34 ++++ test/filetypes/scala/lambda_expressions.vader | 26 +++ 17 files changed, 439 insertions(+), 147 deletions(-) delete mode 100644 ftplugin/_scala.vim create mode 100644 ftplugin/scala.vim create mode 100644 helper/src/scala/docs/scaladoc.yaml create mode 100644 helper/src/scala/mod.rs create mode 100644 helper/src/scala/parser.rs delete mode 100644 helper/test.r create mode 100644 test/filetypes/scala/classes.vader create mode 100644 test/filetypes/scala/functions.vader create mode 100644 test/filetypes/scala/lambda_expressions.vader diff --git a/ftplugin/_scala.vim b/ftplugin/_scala.vim deleted file mode 100644 index 00aaed07..00000000 --- a/ftplugin/_scala.vim +++ /dev/null @@ -1,108 +0,0 @@ -" ============================================================================== -" The Scala documentation should follow the 'ScalaDoc' conventions. -" see https://docs.scala-lang.org/style/scaladoc.html -" ============================================================================== - -let s:save_cpo = &cpoptions -set cpoptions&vim - -let b:doge_supported_doc_standards = ['scaladoc'] -let b:doge_doc_standard = doge#buffer#get_doc_standard('scala') - -" " ============================================================================== -" " -" " Define our base for every pattern. -" " -" " ============================================================================== -" " The parameters.match describes the following pattern: -" " : = -" " ============================================================================== -" let s:pattern_base = { -" \ 'parameters': { -" \ 'match': '\m\%(\%(val\s\+\)\?\([[:alnum:]_]\+\)\)\%(\s*:\s*\([^,(\)=]\+\)\)\?\%(\s*=\s*[^,(\)]\+\)\?', -" \ 'tokens': ['name', 'type'], -" \ 'format': '@param {name} {type} !description', -" \ }, -" \ 'insert': 'above', -" \} -" -" " ============================================================================== -" " -" " Define the pattern types. -" " -" " ============================================================================== -" -" " ------------------------------------------------------------------------------ -" " Matches regular functions. -" " ------------------------------------------------------------------------------ -" " (x: Int) => x + 1 -" " val getTheAnswer = () => 42 -" " ------------------------------------------------------------------------------ -" let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { -" \ 'match': '\m^\%(val\s\+\%([[:alnum:]_]\+\)\s*=\s*\)\?(\(.\{-}\))\s*=>\s*', -" \ 'tokens': ['parameters'], -" \}) -" -" " ------------------------------------------------------------------------------ -" " Matches class methods. -" " ------------------------------------------------------------------------------ -" " def urlBuilder(ssl: Boolean = true, domainName: String = 'some domain value'): (String, String) => String = {} -" " -" " def main(args: Array[String]): Unit = -" " println("Hello, Scala developer!") -" " -" " def move(dx: Int, dy: Int): Unit = {} -" " ------------------------------------------------------------------------------ -" let s:class_method_pattern = doge#helpers#deepextend(s:pattern_base, { -" \ 'match': '\m^\%(\%(public\|private\|protected\|override\)\s\+\)*def\s\+\%([[:alnum:]_]\+\)\%(\[.*\]\)\?\%(\s*=\s*\)\?(\(.\{-}\)):', -" \ 'tokens': ['parameters'], -" \}) -" -" " ------------------------------------------------------------------------------ -" " Matches classes. -" " ------------------------------------------------------------------------------ -" " class Cat(val name: String) extends Pet -" " class IntIterator(to: Int) extends Iterator[Int] {} -" " protected case class LoremIpsum(name: String, age: Int) extends B with C with D {} -" " ------------------------------------------------------------------------------ -" let s:class_pattern = doge#helpers#deepextend(s:pattern_base, { -" \ 'match': '\m^\%(\%(public\|private\|protected\|package\|case\)\s\+\)*class\s\+\%([[:alnum:]_]\+\)\%(\[.*\]\)\?(\(.\{-}\))\([^{]\+{\)\?', -" \ 'tokens': ['parameters'], -" \}) -" -" " ============================================================================== -" " -" " Define the doc standards. -" " -" " ============================================================================== -" call doge#buffer#register_doc_standard('scaladoc', [ -" \ doge#helpers#deepextend(s:function_pattern, { -" \ 'template': [ -" \ '/** !description', -" \ ' *', -" \ '%(parameters| * {parameters})%', -" \ ' * @return !description', -" \ ' */', -" \ ], -" \ }), -" \ doge#helpers#deepextend(s:class_method_pattern, { -" \ 'template': [ -" \ '/** !description', -" \ ' *', -" \ '%(parameters| * {parameters})%', -" \ ' * @return !description', -" \ ' */', -" \ ], -" \ }), -" \ doge#helpers#deepextend(s:class_pattern, { -" \ 'template': [ -" \ '/** !description', -" \ ' *', -" \ '%(parameters| * {parameters})%', -" \ ' */', -" \ ], -" \ }), -" \]) - -let &cpoptions = s:save_cpo -unlet s:save_cpo diff --git a/ftplugin/scala.vim b/ftplugin/scala.vim new file mode 100644 index 00000000..542f1e02 --- /dev/null +++ b/ftplugin/scala.vim @@ -0,0 +1,16 @@ +" ============================================================================== +" The Scala documentation should follow the 'ScalaDoc' conventions. +" see https://docs.scala-lang.org/style/scaladoc.html +" ============================================================================== + +let s:save_cpo = &cpoptions +set cpoptions&vim + +let b:doge_parser = 'scala' +let b:doge_insert = 'above' + +let b:doge_supported_doc_standards = ['scaladoc'] +let b:doge_doc_standard = doge#buffer#get_doc_standard('scala') + +let &cpoptions = s:save_cpo +unlet s:save_cpo diff --git a/helper/.editorconfig b/helper/.editorconfig index b1971556..424139b2 100644 --- a/helper/.editorconfig +++ b/helper/.editorconfig @@ -9,5 +9,8 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true +[*.yaml] +indent_size = 2 + [*.md] trim_trailing_whitespace = false diff --git a/helper/Cargo.lock b/helper/Cargo.lock index 0ca0a387..bf6a5789 100644 --- a/helper/Cargo.lock +++ b/helper/Cargo.lock @@ -699,6 +699,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-scala" +version = "0.20.0" +source = "git+https://github.com/tree-sitter/tree-sitter-scala?rev=f14629b#f14629b4d53f72356ce8f6d4ac8c54d21b4e74dd" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-typescript" version = "0.20.2" @@ -796,7 +805,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vim-doge-helper" -version = "4.1.1" +version = "4.2.0" dependencies = [ "clap", "regex", @@ -816,6 +825,7 @@ dependencies = [ "tree-sitter-r", "tree-sitter-ruby", "tree-sitter-rust", + "tree-sitter-scala", "tree-sitter-typescript", ] diff --git a/helper/Cargo.toml b/helper/Cargo.toml index 0c275b6e..da838c4d 100644 --- a/helper/Cargo.toml +++ b/helper/Cargo.toml @@ -27,3 +27,4 @@ tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "3429d8c" } tree-sitter-php = { git = "https://github.com/tree-sitter/tree-sitter-php", rev = "d43130f" } tree-sitter-r = { git = "https://github.com/r-lib/tree-sitter-r", rev = "c55f8b4" } +tree-sitter-scala = { git = "https://github.com/tree-sitter/tree-sitter-scala", rev = "f14629b" } diff --git a/helper/src/config.rs b/helper/src/config.rs index d1ffefe5..a5188088 100644 --- a/helper/src/config.rs +++ b/helper/src/config.rs @@ -34,6 +34,7 @@ pub fn load_doc_config_str<'a>(parser_name: &'a str, doc_name: &'a str) -> &'a s "bash_google" => include_str!("bash/docs/google.yaml"), "rust_rustdoc" => include_str!("rust/docs/rustdoc.yaml"), "r_roxygen2" => include_str!("r/docs/roxygen2.yaml"), + "scala_scaladoc" => include_str!("scala/docs/scaladoc.yaml"), _ => panic!("Unsupported {} doc: {}", parser_name, doc_name), } diff --git a/helper/src/docblock.rs b/helper/src/docblock.rs index cc75b360..39d68131 100644 --- a/helper/src/docblock.rs +++ b/helper/src/docblock.rs @@ -18,6 +18,7 @@ use crate::ruby::parser::RubyParser; use crate::rust::parser::RustParser; use crate::typescript::parser::TypescriptParser; use crate::r::parser::RParser; +use crate::scala::parser::ScalaParser; fn replace_indent_placeholders(docblock: &str, use_tabs: bool, indent: usize) -> String { @@ -139,6 +140,7 @@ pub fn generate( "cpp" => Box::new(CppParser::new(code, line, &node_types)) as Box, "typescript" => Box::new(TypescriptParser::new(code, line, &node_types, options)) as Box, "r" => Box::new(RParser::new(code, line, &node_types)) as Box, + "scala" => Box::new(ScalaParser::new(code, line, &node_types)) as Box, _ => panic!("Unsupported parser: {}", &parser_name), }; diff --git a/helper/src/lib.rs b/helper/src/lib.rs index 53ebd84b..a741f201 100644 --- a/helper/src/lib.rs +++ b/helper/src/lib.rs @@ -16,3 +16,4 @@ pub mod c; pub mod cpp; pub mod typescript; pub mod r; +pub mod scala; diff --git a/helper/src/r/docs/roxygen2.yaml b/helper/src/r/docs/roxygen2.yaml index b6c84b99..b46ec006 100644 --- a/helper/src/r/docs/roxygen2.yaml +++ b/helper/src/r/docs/roxygen2.yaml @@ -5,21 +5,21 @@ templates: node_types: - function_definition template: | - #' [TODO:title of the function] - #' - #' [TODO:brief description] - {% if params %} - #' - {% for param in params %} - #' @param {{ param.name }} [TODO:description]{% if param.default_value %}. Default is {{ param.default_value }}.{% endif %} - {% endfor %} - {% endif %} - #' - #' @return [TODO:description] - #' - #' @examples - #' {{ func_name }}([TODO:parameters]) - #' - #' @rdname {{ func_name }} - #' - #' @method {{ func_name }} + #' [TODO:title of the function] + #' + #' [TODO:brief description] + {% if params %} + #' + {% for param in params %} + #' @param {{ param.name }} [TODO:description]{% if param.default_value %}. Default is {{ param.default_value }}.{% endif %} + {% endfor %} + {% endif %} + #' + #' @return [TODO:description] + #' + #' @examples + #' {{ func_name }}([TODO:parameters]) + #' + #' @rdname {{ func_name }} + #' + #' @method {{ func_name }} diff --git a/helper/src/scala/docs/scaladoc.yaml b/helper/src/scala/docs/scaladoc.yaml new file mode 100644 index 00000000..be4e2937 --- /dev/null +++ b/helper/src/scala/docs/scaladoc.yaml @@ -0,0 +1,45 @@ +# https://docs.scala-lang.org/style/scaladoc.html + +templates: + lambda_expression: + node_types: + - lambda_expression + template: | + /** [TODO:description] + * + {% if params %} + {% for param in params %} + * @param {{ param.name }} [TODO:description] + {% endfor %} + {% endif %} + * @return [TODO:description] + */ + + function: + node_types: + - function_definition + template: | + /** [TODO:description] + * + {% if params %} + {% for param in params %} + * @param {{ param.name }} [TODO:description] + {% endfor %} + {% endif %} + * @return [TODO:description] + */ + + class: + node_types: + - class_definition + template: | + {% if params %} + /** [TODO:description] + * + {% for param in params %} + * @param {{ param.name }} [TODO:description] + {% endfor %} + */ + {% else %} + /** [TODO:description] */ + {% endif %} diff --git a/helper/src/scala/mod.rs b/helper/src/scala/mod.rs new file mode 100644 index 00000000..67c567fa --- /dev/null +++ b/helper/src/scala/mod.rs @@ -0,0 +1 @@ +pub mod parser; diff --git a/helper/src/scala/parser.rs b/helper/src/scala/parser.rs new file mode 100644 index 00000000..f5adceaf --- /dev/null +++ b/helper/src/scala/parser.rs @@ -0,0 +1,165 @@ +use tree_sitter::{Parser, Node}; +use serde_json::{Map, Value}; + +use crate::base_parser::BaseParser; +use crate::traverse; + +pub struct ScalaParser<'a> { + code: &'a str, + tree: tree_sitter::Tree, + line: &'a usize, + node_types: &'a [&'a str], +} + +impl<'a> BaseParser for ScalaParser<'a> { + fn parse(&self) -> Option, String>> { + self.parse_node(&self.tree.root_node()) + } + + fn get_code_bytes(&self) -> &[u8] { + &self.code.as_bytes() + } +} + +impl<'a> ScalaParser<'a> { + pub fn new(code: &'a str, line: &'a usize, node_types: &'a [&'a str]) -> Self { + let mut parser = Parser::new(); + parser.set_language(tree_sitter_scala::language()).unwrap(); + + let tree = parser.parse(code, None).unwrap(); + + Self { code, tree, line, node_types } + } + + fn parse_node(&self, node: &Node) -> Option, String>> { + for child_node in traverse::PreOrder::new(node.walk()) { + if child_node.start_position().row + 1 == *self.line && self.node_types.contains(&child_node.kind()) { + return match child_node.kind() { + "lambda_expression" => Some(self.parse_lambda_expression(&child_node)), + "function_definition" => Some(self.parse_function(&child_node)), + "class_definition" => Some(self.parse_class(&child_node)), + _ => None, + }; + } + } + + None + } + + fn parse_lambda_expression(&self, node: &Node) -> Result, String> { + let mut tokens = Map::new(); + + for child_node in node.children(&mut node.walk()) { + match child_node.kind() { + "bindings" => { + let mut params = Vec::new(); + + child_node + .children(&mut child_node.walk()) + .filter(|node| node.kind() == "binding") + .for_each(|node| { + let mut param = Map::new(); + + let name = node + .children(&mut node.walk()) + .filter(|node| node.kind() == "identifier") + .next() + .and_then(|node| Some(self.get_node_text(&node))) + .unwrap(); + param.insert("name".to_string(), Value::String(name)); + + let type_identifier = node + .children(&mut node.walk()) + .filter(|node| node.kind() == "type_identifier") + .next() + .and_then(|node| Some(self.get_node_text(&node))); + if type_identifier.is_some() { + param.insert("type".to_string(), Value::String(type_identifier.unwrap())); + } + + params.push(Value::Object(param)); + }); + + if !params.is_empty() { + tokens.insert("params".to_string(), Value::Array(params)); + } + }, + _ => {}, + } + } + + Ok(tokens) + } + + fn parse_function(&self, node: &Node) -> Result, String> { + let mut tokens = Map::new(); + + for child_node in node.children(&mut node.walk()) { + match child_node.kind() { + "parameters" => { + let mut params = Vec::new(); + + child_node + .children(&mut child_node.walk()) + .filter(|node| node.kind() == "parameter") + .for_each(|node| { + let mut param = Map::new(); + + let name = node + .children(&mut node.walk()) + .filter(|node| node.kind() == "identifier") + .next() + .and_then(|node| Some(self.get_node_text(&node))) + .unwrap(); + param.insert("name".to_string(), Value::String(name)); + + params.push(Value::Object(param)); + }); + + if !params.is_empty() { + tokens.insert("params".to_string(), Value::Array(params)); + } + }, + _ => {}, + } + } + + Ok(tokens) + } + + fn parse_class(&self, node: &Node) -> Result, String> { + let mut tokens = Map::new(); + + for child_node in node.children(&mut node.walk()) { + match child_node.kind() { + "class_parameters" => { + let mut params = Vec::new(); + + child_node + .children(&mut child_node.walk()) + .filter(|node| node.kind() == "class_parameter") + .for_each(|node| { + let mut param = Map::new(); + + let name = node + .children(&mut node.walk()) + .filter(|node| node.kind() == "identifier") + .next() + .and_then(|node| Some(self.get_node_text(&node))) + .unwrap(); + param.insert("name".to_string(), Value::String(name)); + + params.push(Value::Object(param)); + }); + + if !params.is_empty() { + tokens.insert("params".to_string(), Value::Array(params)); + } + }, + _ => {}, + } + } + + Ok(tokens) + } +} diff --git a/helper/test.r b/helper/test.r deleted file mode 100644 index 702a51c2..00000000 --- a/helper/test.r +++ /dev/null @@ -1,20 +0,0 @@ -myFunc.default <- function() {} - -myFunc.default <- function( - p1, - p2.sub1 = FALSE, - p3.sub1 = 20, - p4.sub1 = 1/15, - ... -) { - # ... -} - -myFunc = function( - p1 = TRUE, p2_sub1= TRUE, p3 = FALSE, - p4 = 'libs', p5 = NULL, ..., p7 = 'default', - p8 = c('lorem', 'ipsum+dor', 'sit', 'amet'), - p9 = TRUE, p10 = list(), p11 = TRUE -) { - # ... -} diff --git a/test/filetypes/r/functions.vader b/test/filetypes/r/functions.vader index a73bcffc..0861495b 100644 --- a/test/filetypes/r/functions.vader +++ b/test/filetypes/r/functions.vader @@ -1,3 +1,6 @@ +# ============================================================================== +# Left-assignment function +# ============================================================================== Given r (left-assignment function): myFunc.default <- function( p1, @@ -62,6 +65,9 @@ Expect cpp (generated comment): #' @method myFunc.default myFunc.default <- function() {} +# ============================================================================== +# Regular function +# ============================================================================== Given r (regular function assignment): myFunc = function( p1 = TRUE, p2_sub1= TRUE, p3 = FALSE, diff --git a/test/filetypes/scala/classes.vader b/test/filetypes/scala/classes.vader new file mode 100644 index 00000000..cf527977 --- /dev/null +++ b/test/filetypes/scala/classes.vader @@ -0,0 +1,109 @@ +# ============================================================================== +# Subtype classes that extend traits +# ============================================================================== +Given scala (subtype class): + trait Pet: + val name: String + + class Cat(val name: String) extends Pet + +Do (trigger doge): + :4\ + \ + +Expect scala (generated comment): + trait Pet: + val name: String + + /** [TODO:description] + * + * @param name [TODO:description] + */ + class Cat(val name: String) extends Pet + +# ============================================================================== +# Case class +# ============================================================================== +Given scala (case class with params): + protected case class LoremIpsum(name: String, age: Int) extends B with C with D + +Do (trigger doge): + \ + +Expect scala (generated comment): + /** [TODO:description] + * + * @param name [TODO:description] + * @param age [TODO:description] + */ + protected case class LoremIpsum(name: String, age: Int) extends B with C with D + +Given scala (case class without params): + protected case class LoremIpsum() + +Do (trigger doge): + \ + +Expect scala (generated comment): + /** [TODO:description] */ + protected case class LoremIpsum() + +# ============================================================================== +# Classes that extend traits +# ============================================================================== +Given scala (classes that extend traits): + trait Iterator[A]: + def next(): A + + class IntIterator(to: Int) extends Iterator[Int] {} + + class IntIterator(to: Int) extends Iterator[Int]: + def x: Int = _x + def x_=(newValue: Int): Unit = + if newValue < bound then + _x = newValue + else + printWarning() + end IntIterator + +Do (trigger doge): + :4\ + \ + :10\ + \ + :15\ + \ + :20\ + \ + +Expect scala (generated comment): + trait Iterator[A]: + def next(): A + + /** [TODO:description] + * + * @param to [TODO:description] + */ + class IntIterator(to: Int) extends Iterator[Int] {} + + /** [TODO:description] + * + * @param to [TODO:description] + */ + class IntIterator(to: Int) extends Iterator[Int]: + /** [TODO:description] + * + * @return [TODO:description] + */ + def x: Int = _x + /** [TODO:description] + * + * @param newValue [TODO:description] + * @return [TODO:description] + */ + def x_=(newValue: Int): Unit = + if newValue < bound then + _x = newValue + else + printWarning() + end IntIterator diff --git a/test/filetypes/scala/functions.vader b/test/filetypes/scala/functions.vader new file mode 100644 index 00000000..a90e4b9d --- /dev/null +++ b/test/filetypes/scala/functions.vader @@ -0,0 +1,34 @@ +# ============================================================================== +# Function with return type +# ============================================================================== +Given scala (function with return type): + def urlBuilder(ssl: Boolean = true, domainName: String): (String, String) => String = {} + +Do (trigger doge): + \ + +Expect scala (generated comment): + /** [TODO:description] + * + * @param ssl [TODO:description] + * @param domainName [TODO:description] + * @return [TODO:description] + */ + def urlBuilder(ssl: Boolean = true, domainName: String): (String, String) => String = {} + +# ============================================================================== +# Function without return type +# ============================================================================== +Given scala (function without return type): + def main(args: Array[String]) = println("Hello, Scala developer!") + +Do (trigger doge): + \ + +Expect scala (generated comment): + /** [TODO:description] + * + * @param args [TODO:description] + * @return [TODO:description] + */ + def main(args: Array[String]) = println("Hello, Scala developer!") diff --git a/test/filetypes/scala/lambda_expressions.vader b/test/filetypes/scala/lambda_expressions.vader new file mode 100644 index 00000000..8a628827 --- /dev/null +++ b/test/filetypes/scala/lambda_expressions.vader @@ -0,0 +1,26 @@ +# ============================================================================== +# Lambda expressions +# ============================================================================== +Given scala (lambda expressions): + (x: Int) => x + 1 + + val getTheAnswer = () => 42 + +Do (trigger doge): + \ + :8\ + \ + +Expect scala (generated comment): + /** [TODO:description] + * + * @param x [TODO:description] + * @return [TODO:description] + */ + (x: Int) => x + 1 + + /** [TODO:description] + * + * @return [TODO:description] + */ + val getTheAnswer = () => 42 From 7b8548def328b1741a3a60271cb14ab4ec054afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=E9=87=91=E5=8F=AF=E6=98=8E?= Date: Sun, 13 Aug 2023 08:55:23 +0200 Subject: [PATCH 2/3] chore: delete unused _coffee.vim and _kotlin.vim --- ftplugin/_coffee.vim | 72 ----------------------- ftplugin/_kotlin.vim | 133 ------------------------------------------- 2 files changed, 205 deletions(-) delete mode 100644 ftplugin/_coffee.vim delete mode 100644 ftplugin/_kotlin.vim diff --git a/ftplugin/_coffee.vim b/ftplugin/_coffee.vim deleted file mode 100644 index 232cc3b5..00000000 --- a/ftplugin/_coffee.vim +++ /dev/null @@ -1,72 +0,0 @@ -" ============================================================================== -" The CoffeeScript documentation should follow the 'jsdoc' conventions, since -" there is no official CoffeeScript documentation. -" see https://jsdoc.app -" ============================================================================== - -let s:save_cpo = &cpoptions -set cpoptions&vim - -let b:doge_supported_doc_standards = ['jsdoc'] -let b:doge_doc_standard = doge#buffer#get_doc_standard('coffee') - -" " ============================================================================== -" " -" " Define our base for every pattern. -" " -" " ============================================================================== -" let s:pattern_base = { -" \ 'parameters': { -" \ 'format': '@param {!type} {name} !description', -" \ }, -" \ 'insert': 'above', -" \} -" -" " ============================================================================== -" " -" " Define the pattern types. -" " -" " ============================================================================== -" let s:prototype_function_pattern = doge#helpers#deepextend(s:pattern_base, { -" \ 'match': '\m^\([[:alnum:]_$]\+\)::\([[:alnum:]_$]\+\)\s*=\s*[-=]>', -" \ 'tokens': ['className', 'funcName'], -" \}) -" -" let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { -" \ 'match': '\m^\([[:alnum:]_$]\+\)\s*=\s*(\(.\{-}\))\s*[-=]>', -" \ 'tokens': ['funcName', 'parameters'], -" \ 'parameters': { -" \ 'match': '\m\([^,]\+\)', -" \ 'tokens': ['name'], -" \ }, -" \}) -" -" " ============================================================================== -" " -" " Define the doc standards. -" " -" " ============================================================================== -" call doge#buffer#register_doc_standard('jsdoc', [ -" \ doge#helpers#deepextend(s:prototype_function_pattern, { -" \ 'template': [ -" \ '###', -" \ '!description', -" \ '', -" \ '@function {className}#{funcName}', -" \ '###', -" \ ], -" \ }), -" \ doge#helpers#deepextend(s:function_pattern, { -" \ 'template': [ -" \ '###', -" \ '!description', -" \ '', -" \ '@function {funcName|}', -" \ '%(parameters|{parameters})%', -" \ '###', -" \ ], -" \ }), -" \]) - -let &cpoptions = s:save_cpo -unlet s:save_cpo diff --git a/ftplugin/_kotlin.vim b/ftplugin/_kotlin.vim deleted file mode 100644 index c318c809..00000000 --- a/ftplugin/_kotlin.vim +++ /dev/null @@ -1,133 +0,0 @@ -" ============================================================================== -" The Kotlin documentation should follow the 'KDoc' conventions. -" see https://kotlinlang.org/docs/reference/kotlin-doc.html -" ============================================================================== - -let s:save_cpo = &cpoptions -set cpoptions&vim - -let b:doge_supported_doc_standards = ['kdoc'] -let b:doge_doc_standard = doge#buffer#get_doc_standard('kotlin') - -" " ============================================================================== -" " -" " Define our base for every pattern. -" " -" " ============================================================================== -" " The parameters.match describes the following pattern: -" " : -" " -" " (map: MutableMap, str: String.() -> Unit) -" " -" " (str: String.() -> Unit, map: MutableMap) -" " -" " (num: <*>, str: String.() -> Unit, map: MutableMap) -" " -" " (map: MutableMap>, str: String.() -> Unit) -" " -" " (map: MutableMap, str: String) -" " -" " (onetime: Boolean = true, callback: () -> Unit) -" " ============================================================================== -" let s:pattern_base = { -" \ 'parameters': { -" \ 'match': '\m\%(\%(var\|val\)\s\+\)\?\([[:alnum:]_]\+\)\%(\s*:\s*\%([[:alnum:]_]\+\)\?\%(<[[:alnum:][:space:]_,<>:?*]\{-1,}>\|[^,]\+\)\?\)\?', -" \ 'tokens': ['name'], -" \ 'format': '@param {name} !description' -" \ }, -" \ 'insert': 'above', -" \} -" -" " ============================================================================== -" " -" " Define the pattern types. -" " -" " ============================================================================== -" -" " ------------------------------------------------------------------------------ -" " Matches regular functions, class methods and extension functions. -" " ------------------------------------------------------------------------------ -" " fun MutableList.swap(index1: Int, index2: Int) { -" " fun listenForPackageChanges(onetime: Boolean = true, callback: () -> Unit) = object : BroadcastReceiver() {} -" " inline fun > printAllValues() {} -" " fun id(x: T): T = x -" " fun readOut(group: Group) {} -" " fun readIn(group: Group) {} -" " fun acceptAnyList(list: List) {} -" " inline fun Gson.fromJson(json: JsonElement): T = this.fromJson(json, T::class.java) -" " open fun f() { println("Foo.f()") } -" " ------------------------------------------------------------------------------ -" let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { -" \ 'match': '\m^\%(\%(public\|protected\|private\|final\|inline\|abstract\|override\|operator\|open\|data\)\s\+\)*fun\s\+\%([^(]\+\)\s*(\(.\{-}\))\%(\s*:\s*[[:alnum:]_:\.]\+\%(<[[:alnum:][:space:]_,<>:?*]\{-}>\)\??\?\)\?\s*[={]', -" \ 'tokens': ['parameters'], -" \}) -" -" " ------------------------------------------------------------------------------ -" " Matches classes. -" " ------------------------------------------------------------------------------ -" " class Outer() {} -" " inner class Inner() {} -" " data class User(val name: String, val age: Int) {} -" " enum class Color(val rgb: Int) {} -" " class Person constructor(firstName: String) {} -" " class C private constructor(a: Int) {} -" " class Person(firstName: String) {} -" " class MyView() : View()) {} -" " inline class Name(val s: String) {} -" " abstract class Vehicle(val name: String, val color: String, val weight: Double) {} -" " external class MyClass() {} -" " ------------------------------------------------------------------------------ -" let s:class_pattern = doge#helpers#deepextend(s:pattern_base, { -" \ 'match': '\m^\%(\%(inner\|inline\|data\|enum\|external\|open\|abstract\|sealed\)\s\+\)*class\s\+\%([[:alnum:]_]\+\%(<[[:alnum:][:space:]_,<>:?*]\{-}>\)\?\)\s*\%(\%(public\|private\|protected\)\s*\)\?\%(constructor\s*\)\?(\(.\{-}\))', -" \ 'tokens': ['parameters'], -" \ 'parameters': { -" \ 'format': '@property {name} !description', -" \ }, -" \}) -" -" " ------------------------------------------------------------------------------ -" " Matches class constructors. -" " ------------------------------------------------------------------------------ -" " constructor(parent: Person, query: Query<*, >) {} -" " ------------------------------------------------------------------------------ -" let s:class_constructor_pattern = doge#helpers#deepextend(s:pattern_base, { -" \ 'match': '\m^\%(\%(public\|private\|protected\)\s\+\)\?constructor\s*(\(.\{-}\))', -" \ 'tokens': ['parameters'], -" \}) -" -" -" " ============================================================================== -" " -" " Define the doc standards. -" " -" " ============================================================================== -" call doge#buffer#register_doc_standard('kdoc', [ -" \ doge#helpers#deepextend(s:function_pattern, { -" \ 'template': [ -" \ '/**', -" \ ' * !description', -" \ '%(parameters| * {parameters})%', -" \ ' * @return !description', -" \ ' */', -" \ ], -" \ }), -" \ doge#helpers#deepextend(s:class_pattern, { -" \ 'template': [ -" \ '/**', -" \ ' * !description', -" \ '%(parameters| * {parameters})%', -" \ ' */', -" \ ], -" \ }), -" \ doge#helpers#deepextend(s:class_constructor_pattern, { -" \ 'template': [ -" \ '/**', -" \ ' * !description', -" \ '%(parameters| * {parameters})%', -" \ ' */', -" \ ], -" \ }), -" \]) - -let &cpoptions = s:save_cpo -unlet s:save_cpo From 3a5f19ac795bcf9445dc367e3f1494f7e25f3193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=E9=87=91=E5=8F=AF=E6=98=8E?= Date: Sun, 13 Aug 2023 09:00:39 +0200 Subject: [PATCH 3/3] chore(addon-info.json): adjust plugin name --- addon-info.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon-info.json b/addon-info.json index 40a2ab12..8c063bb7 100644 --- a/addon-info.json +++ b/addon-info.json @@ -1,5 +1,5 @@ { - "name": "doge", + "name": "vim-doge", "description": "(Do)cumentation (Ge)nerator", "author": "Kim Koomen" }