Skip to content

Commit

Permalink
(DOCSP-44543): Add support for missing Drivers languages (#151)
Browse files Browse the repository at this point in the history
* Add support for missing Drivers languages

* Add support for both PHP comment types

* No joy for Jupyter Notebooks
  • Loading branch information
dacharyc authored Oct 18, 2024
1 parent 5e3dd73 commit 6c5f261
Show file tree
Hide file tree
Showing 23 changed files with 156 additions and 9 deletions.
5 changes: 5 additions & 0 deletions integrationTests/snip/expected/sample.snippet.c-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
6 changes: 6 additions & 0 deletions integrationTests/snip/expected/sample.snippet.go-test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "fmt"

func main() {
fmt.Println("hello world")
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* Here's some block comment on multiple lines.
*/
auto something = SomeClass::state::something;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Here's a comment with an octothorp
<?php
echo "Have an octothorpe! #";
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Here's a comment with slashes
<?php
echo "Fun with PHP!";
?>
3 changes: 3 additions & 0 deletions integrationTests/snip/expected/sample.snippet.php-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
echo "Hello World!";
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("This line will be printed.")
1 change: 1 addition & 0 deletions integrationTests/snip/expected/sample.snippet.ruby-test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "Hello World"
3 changes: 3 additions & 0 deletions integrationTests/snip/expected/sample.snippet.rust-test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello World!");
}
5 changes: 5 additions & 0 deletions integrationTests/snip/expected/sample.snippet.sc-test.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Hello {
def main(args: Array[String]) = {
println("Hello, world")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Hello {
def main(args: Array[String]) = {
println("Hello, world")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Here's some block comment on a single line */
auto something = SomeClass::state::something;
8 changes: 8 additions & 0 deletions integrationTests/snip/input/sample.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// :snippet-start: c-test
#include <stdio.h>
int main() {
// printf() displays the string inside quotation // :remove:
printf("Hello, World!");
return 0;
}
// :snippet-end:
12 changes: 12 additions & 0 deletions integrationTests/snip/input/sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
11 changes: 11 additions & 0 deletions integrationTests/snip/input/sample.go
Original file line number Diff line number Diff line change
@@ -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:
22 changes: 22 additions & 0 deletions integrationTests/snip/input/sample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// :snippet-start: php-test
# Sometimes comments start with octothorps :remove:
<?php
echo "Hello World!";
?>
// :snippet-end:

# :snippet-start: php-octothorp-test
# Here's a comment with an octothorp
#And one without a space just for testing :remove:
<?php
echo "Have an octothorpe! #";
?>
# :snippet-end:

// :snippet-start: php-slash-test
// Here's a comment with slashes
//and one without a space just because :remove:
<?php
echo "Fun with PHP!";
?>
// :snippet-end:
4 changes: 4 additions & 0 deletions integrationTests/snip/input/sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# :snippet-start: python-test
# My comment is the coolest, for real. :remove:
print("This line will be printed.")
# :snippet-end:
4 changes: 4 additions & 0 deletions integrationTests/snip/input/sample.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# :snippet-start: ruby-test
# Here's a comment :remove:
puts "Hello World"
# :snippet-end:
6 changes: 6 additions & 0 deletions integrationTests/snip/input/sample.rs
Original file line number Diff line number Diff line change
@@ -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:
8 changes: 8 additions & 0 deletions integrationTests/snip/input/sample.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// :snippet-start: sc-test
object Hello {
// Arrrrrrrrrrgs! :remove:
def main(args: Array[String]) = {
println("Hello, world")
}
}
// :snippet-end:
8 changes: 8 additions & 0 deletions integrationTests/snip/input/sample.scala
Original file line number Diff line number Diff line change
@@ -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:
8 changes: 8 additions & 0 deletions src/bluehawk/actions/snip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,23 @@ 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<string, string> = new Map([
[".c", "c"],
[".cpp", "cpp"],
[".cs", "csharp"],
[".go", "golang"],
[".gradle", "groovy"],
[".java", "java"],
[".js", "javascript"],
[".jsx", "javascript"],
[".json", "json"],
[".kt", "kotlin"],
[".m", "objectivec"],
[".php", "php"],
[".py", "python"],
[".rb", "ruby"],
[".rs", "rust"],
[".sc", "scala"],
[".scala", "scala"],
[".swift", "swift"],
[".ts", "typescript"],
[".tsx", "typescript"],
Expand Down
31 changes: 22 additions & 9 deletions src/bluehawk/getBluehawk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,27 @@ export const getBluehawk = async (): Promise<Bluehawk> => {
".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",
Expand All @@ -78,7 +81,12 @@ export const getBluehawk = async (): Promise<Bluehawk> => {
}
);

// Add all supported extensions here.
bluehawk.addLanguage([".php"], {
languageId: "PHP",
lineComments: [/#|\/\//],
blockComments: [[/\/\*/, /\*\//]],
});

bluehawk.addLanguage([".py"], {
languageId: "Python",
lineComments: [/# ?/],
Expand All @@ -90,6 +98,11 @@ export const getBluehawk = async (): Promise<Bluehawk> => {
],
});

bluehawk.addLanguage([".rb"], {
languageId: "Ruby",
lineComments: [/# ?/],
});

bluehawk.addLanguage(["", ".txt", ".rst", ".md", ".json"], {
languageId: "text",
});
Expand Down

0 comments on commit 6c5f261

Please sign in to comment.