Skip to content

Commit 650fec1

Browse files
Add C# source symbol parsers
Reference: aboutcode-org/scancode.io#1431 Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 923081e commit 650fec1

5 files changed

Lines changed: 104 additions & 0 deletions

File tree

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ install_requires =
4949
tree-sitter-bash==0.21.0
5050
tree-sitter-c==0.21.1
5151
tree-sitter-cpp==0.22.0
52+
tree-sitter-c-sharp==0.23.1
5253
tree-sitter-go==0.21.0
5354
tree-sitter-java==0.21.0
5455
tree-sitter-javascript==0.21.2

src/source_inspector/symbols_tree_sitter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ def traverse(node, symbols, strings, language_info):
160160
"identifiers": ["identifier"],
161161
"string_literals": ["string_literal"],
162162
},
163+
"C#": {
164+
"wheel": "tree_sitter_c_sharp",
165+
"identifiers": ["identifier"],
166+
"string_literals": ["string_literal"],
167+
},
163168
"Go": {
164169
"wheel": "tree_sitter_go",
165170
"identifiers": ["identifier"],
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using MediaBrowser.Model.Configuration;
4+
using MediaBrowser.Model.Entities;
5+
6+
namespace Jellyfin.Api.Models.LibraryDtos;
7+
8+
/// <summary>
9+
/// Library type options dto.
10+
/// </summary>
11+
public class LibraryTypeOptionsDto
12+
{
13+
/// <summary>
14+
/// Gets or sets the type.
15+
/// </summary>
16+
public string? Type { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets the metadata fetchers.
20+
/// </summary>
21+
public IReadOnlyList<LibraryOptionInfoDto> MetadataFetchers { get; set; } = Array.Empty<LibraryOptionInfoDto>();
22+
23+
/// <summary>
24+
/// Gets or sets the image fetchers.
25+
/// </summary>
26+
public IReadOnlyList<LibraryOptionInfoDto> ImageFetchers { get; set; } = Array.Empty<LibraryOptionInfoDto>();
27+
28+
/// <summary>
29+
/// Gets or sets the supported image types.
30+
/// </summary>
31+
public IReadOnlyList<ImageType> SupportedImageTypes { get; set; } = Array.Empty<ImageType>();
32+
33+
/// <summary>
34+
/// Gets or sets the default image options.
35+
/// </summary>
36+
public IReadOnlyList<ImageOption> DefaultImageOptions { get; set; } = Array.Empty<ImageOption>();
37+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"files": [
3+
{
4+
"path": "LibraryTypeOptionsDto.cs",
5+
"type": "file",
6+
"source_symbols": [
7+
"System",
8+
"System",
9+
"Collections",
10+
"Generic",
11+
"MediaBrowser",
12+
"Model",
13+
"Configuration",
14+
"MediaBrowser",
15+
"Model",
16+
"Entities",
17+
"Jellyfin",
18+
"Api",
19+
"Models",
20+
"LibraryDtos",
21+
"LibraryTypeOptionsDto",
22+
"Type",
23+
"IReadOnlyList",
24+
"LibraryOptionInfoDto",
25+
"MetadataFetchers",
26+
"Array",
27+
"Empty",
28+
"LibraryOptionInfoDto",
29+
"IReadOnlyList",
30+
"LibraryOptionInfoDto",
31+
"ImageFetchers",
32+
"Array",
33+
"Empty",
34+
"LibraryOptionInfoDto",
35+
"IReadOnlyList",
36+
"ImageType",
37+
"SupportedImageTypes",
38+
"Array",
39+
"Empty",
40+
"ImageType",
41+
"IReadOnlyList",
42+
"ImageOption",
43+
"DefaultImageOptions",
44+
"Array",
45+
"Empty",
46+
"ImageOption"
47+
],
48+
"source_strings": [],
49+
"scan_errors": []
50+
}
51+
]
52+
}

tests/test_symbols_tree_sitter.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ def test_symbols_scanner_long_cli(self):
6060
expected_loc = self.get_test_loc("if_ath.c-expected.json")
6161
check_json_scan(expected_loc, result_file, regen=REGEN_TEST_FIXTURES)
6262

63+
def test_symbols_strings_c_sharp(self):
64+
test_file = self.get_test_loc("LibraryTypeOptionsDto.cs")
65+
result_file = self.get_temp_file("json")
66+
args = ["--treesitter-symbol-and-string", test_file, "--json-pp", result_file]
67+
run_scan_click(args)
68+
69+
expected_loc = self.get_test_loc("LibraryTypeOptionsDto.cs-expected.json")
70+
check_json_scan(expected_loc, result_file, regen=True)
71+
6372
def test_symbols_strings_objective_c(self):
6473
test_file = self.get_test_loc("BrazeSDKAuthDelegateWrapper.m")
6574
result_file = self.get_temp_file("json")

0 commit comments

Comments
 (0)