From 6c5f2612111c3f6813b66fe95d5d05f07ff9e9e1 Mon Sep 17 00:00:00 2001 From: Dachary Date: Fri, 18 Oct 2024 11:06:06 -0400 Subject: [PATCH] (DOCSP-44543): Add support for missing Drivers languages (#151) * Add support for missing Drivers languages * Add support for both PHP comment types * No joy for Jupyter Notebooks --- .../snip/expected/sample.snippet.c-test.c | 5 +++ .../snip/expected/sample.snippet.go-test.go | 6 ++++ ...ample.snippet.multi-line-block-comment.cpp | 4 +++ .../sample.snippet.php-octothorp-test.php | 4 +++ .../sample.snippet.php-slash-test.php | 4 +++ .../snip/expected/sample.snippet.php-test.php | 3 ++ .../expected/sample.snippet.python-test.py | 1 + .../snip/expected/sample.snippet.ruby-test.rb | 1 + .../snip/expected/sample.snippet.rust-test.rs | 3 ++ .../snip/expected/sample.snippet.sc-test.sc | 5 +++ .../expected/sample.snippet.scala-test.scala | 5 +++ ...mple.snippet.single-line-block-comment.cpp | 2 ++ integrationTests/snip/input/sample.c | 8 +++++ integrationTests/snip/input/sample.cpp | 12 +++++++ integrationTests/snip/input/sample.go | 11 +++++++ integrationTests/snip/input/sample.php | 22 +++++++++++++ integrationTests/snip/input/sample.py | 4 +++ integrationTests/snip/input/sample.rb | 4 +++ integrationTests/snip/input/sample.rs | 6 ++++ integrationTests/snip/input/sample.sc | 8 +++++ integrationTests/snip/input/sample.scala | 8 +++++ src/bluehawk/actions/snip.ts | 8 +++++ src/bluehawk/getBluehawk.ts | 31 +++++++++++++------ 23 files changed, 156 insertions(+), 9 deletions(-) create mode 100644 integrationTests/snip/expected/sample.snippet.c-test.c create mode 100644 integrationTests/snip/expected/sample.snippet.go-test.go create mode 100644 integrationTests/snip/expected/sample.snippet.multi-line-block-comment.cpp create mode 100644 integrationTests/snip/expected/sample.snippet.php-octothorp-test.php create mode 100644 integrationTests/snip/expected/sample.snippet.php-slash-test.php create mode 100644 integrationTests/snip/expected/sample.snippet.php-test.php create mode 100644 integrationTests/snip/expected/sample.snippet.python-test.py create mode 100644 integrationTests/snip/expected/sample.snippet.ruby-test.rb create mode 100644 integrationTests/snip/expected/sample.snippet.rust-test.rs create mode 100644 integrationTests/snip/expected/sample.snippet.sc-test.sc create mode 100644 integrationTests/snip/expected/sample.snippet.scala-test.scala create mode 100644 integrationTests/snip/expected/sample.snippet.single-line-block-comment.cpp create mode 100644 integrationTests/snip/input/sample.c create mode 100644 integrationTests/snip/input/sample.go create mode 100644 integrationTests/snip/input/sample.php create mode 100644 integrationTests/snip/input/sample.py create mode 100644 integrationTests/snip/input/sample.rb create mode 100644 integrationTests/snip/input/sample.rs create mode 100644 integrationTests/snip/input/sample.sc create mode 100644 integrationTests/snip/input/sample.scala diff --git a/integrationTests/snip/expected/sample.snippet.c-test.c b/integrationTests/snip/expected/sample.snippet.c-test.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/integrationTests/snip/expected/sample.snippet.c-test.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/integrationTests/snip/expected/sample.snippet.go-test.go b/integrationTests/snip/expected/sample.snippet.go-test.go new file mode 100644 index 00000000..50382185 --- /dev/null +++ b/integrationTests/snip/expected/sample.snippet.go-test.go @@ -0,0 +1,6 @@ +import "fmt" + +func main() { + fmt.Println("hello world") +} + diff --git a/integrationTests/snip/expected/sample.snippet.multi-line-block-comment.cpp b/integrationTests/snip/expected/sample.snippet.multi-line-block-comment.cpp new file mode 100644 index 00000000..a15179ff --- /dev/null +++ b/integrationTests/snip/expected/sample.snippet.multi-line-block-comment.cpp @@ -0,0 +1,4 @@ +/* + * Here's some block comment on multiple lines. + */ +auto something = SomeClass::state::something; diff --git a/integrationTests/snip/expected/sample.snippet.php-octothorp-test.php b/integrationTests/snip/expected/sample.snippet.php-octothorp-test.php new file mode 100644 index 00000000..beb60081 --- /dev/null +++ b/integrationTests/snip/expected/sample.snippet.php-octothorp-test.php @@ -0,0 +1,4 @@ +# Here's a comment with an octothorp + diff --git a/integrationTests/snip/expected/sample.snippet.php-slash-test.php b/integrationTests/snip/expected/sample.snippet.php-slash-test.php new file mode 100644 index 00000000..83aeecd2 --- /dev/null +++ b/integrationTests/snip/expected/sample.snippet.php-slash-test.php @@ -0,0 +1,4 @@ +// Here's a comment with slashes + diff --git a/integrationTests/snip/expected/sample.snippet.php-test.php b/integrationTests/snip/expected/sample.snippet.php-test.php new file mode 100644 index 00000000..b9f1d5be --- /dev/null +++ b/integrationTests/snip/expected/sample.snippet.php-test.php @@ -0,0 +1,3 @@ + diff --git a/integrationTests/snip/expected/sample.snippet.python-test.py b/integrationTests/snip/expected/sample.snippet.python-test.py new file mode 100644 index 00000000..a3bd307b --- /dev/null +++ b/integrationTests/snip/expected/sample.snippet.python-test.py @@ -0,0 +1 @@ +print("This line will be printed.") diff --git a/integrationTests/snip/expected/sample.snippet.ruby-test.rb b/integrationTests/snip/expected/sample.snippet.ruby-test.rb new file mode 100644 index 00000000..b85a0422 --- /dev/null +++ b/integrationTests/snip/expected/sample.snippet.ruby-test.rb @@ -0,0 +1 @@ +puts "Hello World" diff --git a/integrationTests/snip/expected/sample.snippet.rust-test.rs b/integrationTests/snip/expected/sample.snippet.rust-test.rs new file mode 100644 index 00000000..47ad8c63 --- /dev/null +++ b/integrationTests/snip/expected/sample.snippet.rust-test.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello World!"); +} diff --git a/integrationTests/snip/expected/sample.snippet.sc-test.sc b/integrationTests/snip/expected/sample.snippet.sc-test.sc new file mode 100644 index 00000000..5db496d2 --- /dev/null +++ b/integrationTests/snip/expected/sample.snippet.sc-test.sc @@ -0,0 +1,5 @@ +object Hello { + def main(args: Array[String]) = { + println("Hello, world") + } +} diff --git a/integrationTests/snip/expected/sample.snippet.scala-test.scala b/integrationTests/snip/expected/sample.snippet.scala-test.scala new file mode 100644 index 00000000..5db496d2 --- /dev/null +++ b/integrationTests/snip/expected/sample.snippet.scala-test.scala @@ -0,0 +1,5 @@ +object Hello { + def main(args: Array[String]) = { + println("Hello, world") + } +} diff --git a/integrationTests/snip/expected/sample.snippet.single-line-block-comment.cpp b/integrationTests/snip/expected/sample.snippet.single-line-block-comment.cpp new file mode 100644 index 00000000..06321995 --- /dev/null +++ b/integrationTests/snip/expected/sample.snippet.single-line-block-comment.cpp @@ -0,0 +1,2 @@ +/* Here's some block comment on a single line */ +auto something = SomeClass::state::something; diff --git a/integrationTests/snip/input/sample.c b/integrationTests/snip/input/sample.c new file mode 100644 index 00000000..a3a6a0b0 --- /dev/null +++ b/integrationTests/snip/input/sample.c @@ -0,0 +1,8 @@ +// :snippet-start: c-test +#include +int main() { + // printf() displays the string inside quotation // :remove: + printf("Hello, World!"); + return 0; +} +// :snippet-end: \ No newline at end of file diff --git a/integrationTests/snip/input/sample.cpp b/integrationTests/snip/input/sample.cpp index 6bd17884..b6c0a7bd 100644 --- a/integrationTests/snip/input/sample.cpp +++ b/integrationTests/snip/input/sample.cpp @@ -4,4 +4,16 @@ auto something = SomeClass::someProperty; // :snippet-start: failing-cpp-test auto something = SomeClass::state::something; +// :snippet-end: + +// :snippet-start: multi-line-block-comment +/* + * Here's some block comment on multiple lines. + */ +auto something = SomeClass::state::something; +// :snippet-end: + +// :snippet-start: single-line-block-comment +/* Here's some block comment on a single line */ +auto something = SomeClass::state::something; // :snippet-end: \ No newline at end of file diff --git a/integrationTests/snip/input/sample.go b/integrationTests/snip/input/sample.go new file mode 100644 index 00000000..92327c69 --- /dev/null +++ b/integrationTests/snip/input/sample.go @@ -0,0 +1,11 @@ +package main + +// :snippet-start: go-test +import "fmt" + +func main() { + // To FMT or LOG, *that* is the question // :remove: + fmt.Println("hello world") +} + +// :snippet-end: diff --git a/integrationTests/snip/input/sample.php b/integrationTests/snip/input/sample.php new file mode 100644 index 00000000..06d467df --- /dev/null +++ b/integrationTests/snip/input/sample.php @@ -0,0 +1,22 @@ +// :snippet-start: php-test +# Sometimes comments start with octothorps :remove: + +// :snippet-end: + +# :snippet-start: php-octothorp-test +# Here's a comment with an octothorp +#And one without a space just for testing :remove: + +# :snippet-end: + +// :snippet-start: php-slash-test +// Here's a comment with slashes +//and one without a space just because :remove: + +// :snippet-end: diff --git a/integrationTests/snip/input/sample.py b/integrationTests/snip/input/sample.py new file mode 100644 index 00000000..896ce275 --- /dev/null +++ b/integrationTests/snip/input/sample.py @@ -0,0 +1,4 @@ +# :snippet-start: python-test +# My comment is the coolest, for real. :remove: +print("This line will be printed.") +# :snippet-end: \ No newline at end of file diff --git a/integrationTests/snip/input/sample.rb b/integrationTests/snip/input/sample.rb new file mode 100644 index 00000000..cf9e4642 --- /dev/null +++ b/integrationTests/snip/input/sample.rb @@ -0,0 +1,4 @@ +# :snippet-start: ruby-test +# Here's a comment :remove: +puts "Hello World" +# :snippet-end: \ No newline at end of file diff --git a/integrationTests/snip/input/sample.rs b/integrationTests/snip/input/sample.rs new file mode 100644 index 00000000..f060bc45 --- /dev/null +++ b/integrationTests/snip/input/sample.rs @@ -0,0 +1,6 @@ +// :snippet-start: rust-test +fn main() { + // Print text to the console. This is a boring comment. :remove: + println!("Hello World!"); +} +// :snippet-end: \ No newline at end of file diff --git a/integrationTests/snip/input/sample.sc b/integrationTests/snip/input/sample.sc new file mode 100644 index 00000000..06186e46 --- /dev/null +++ b/integrationTests/snip/input/sample.sc @@ -0,0 +1,8 @@ +// :snippet-start: sc-test +object Hello { + // Arrrrrrrrrrgs! :remove: + def main(args: Array[String]) = { + println("Hello, world") + } +} +// :snippet-end: \ No newline at end of file diff --git a/integrationTests/snip/input/sample.scala b/integrationTests/snip/input/sample.scala new file mode 100644 index 00000000..5853eaf0 --- /dev/null +++ b/integrationTests/snip/input/sample.scala @@ -0,0 +1,8 @@ +// :snippet-start: scala-test +object Hello { + // Why do we pass arguments - that sounds confrontational. :remove: + def main(args: Array[String]) = { + println("Hello, world") + } +} +// :snippet-end: diff --git a/src/bluehawk/actions/snip.ts b/src/bluehawk/actions/snip.ts index 3b54fb28..128dd680 100644 --- a/src/bluehawk/actions/snip.ts +++ b/src/bluehawk/actions/snip.ts @@ -87,8 +87,10 @@ export const formatInRst = async ( // nasty hack to cover the suffixes/rst languages we use most often // TODO: switch to a better mapping const rstLanguageMap: Map = new Map([ + [".c", "c"], [".cpp", "cpp"], [".cs", "csharp"], + [".go", "golang"], [".gradle", "groovy"], [".java", "java"], [".js", "javascript"], @@ -96,6 +98,12 @@ export const formatInRst = async ( [".json", "json"], [".kt", "kotlin"], [".m", "objectivec"], + [".php", "php"], + [".py", "python"], + [".rb", "ruby"], + [".rs", "rust"], + [".sc", "scala"], + [".scala", "scala"], [".swift", "swift"], [".ts", "typescript"], [".tsx", "typescript"], diff --git a/src/bluehawk/getBluehawk.ts b/src/bluehawk/getBluehawk.ts index 4b9bdf06..ddd7aa42 100644 --- a/src/bluehawk/getBluehawk.ts +++ b/src/bluehawk/getBluehawk.ts @@ -52,24 +52,27 @@ export const getBluehawk = async (): Promise => { ".c", ".cpp", ".cs", + ".dart", + ".go", + ".gradle", + ".groovy", + ".gsh", + ".gvy", + ".gy", ".h", ".hpp", - ".kt", ".java", ".js", - ".dart", ".jsx", + ".kt", ".m", ".mm", + ".rs", + ".sc", + ".scala", ".swift", ".ts", ".tsx", - ".gradle", - ".groovy", - ".gvy", - ".gy", - ".gsh", - ".go", ], { languageId: "C-like", @@ -78,7 +81,12 @@ export const getBluehawk = async (): Promise => { } ); - // Add all supported extensions here. + bluehawk.addLanguage([".php"], { + languageId: "PHP", + lineComments: [/#|\/\//], + blockComments: [[/\/\*/, /\*\//]], + }); + bluehawk.addLanguage([".py"], { languageId: "Python", lineComments: [/# ?/], @@ -90,6 +98,11 @@ export const getBluehawk = async (): Promise => { ], }); + bluehawk.addLanguage([".rb"], { + languageId: "Ruby", + lineComments: [/# ?/], + }); + bluehawk.addLanguage(["", ".txt", ".rst", ".md", ".json"], { languageId: "text", });