@repometry/language-csharp 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Idleware
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@repometry/language-csharp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "description": "C# for the Repometry tree-sitter plugin, with its grammar",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/idleware/repometry.git"
9
+ },
10
+ "homepage": "https://github.com/idleware/repometry#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/idleware/repometry/issues"
13
+ },
14
+ "keywords": [
15
+ "repometry",
16
+ "tree-sitter",
17
+ "csharp"
18
+ ],
19
+ "type": "module",
20
+ "engines": {
21
+ "node": ">=24"
22
+ },
23
+ "exports": {
24
+ ".": {
25
+ "types": "./target/main/ts/index.d.ts",
26
+ "default": "./target/main/ts/index.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "target/main",
31
+ "!target/main/**/*.map"
32
+ ],
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "scripts": {
37
+ "build": "node -e \"require('node:fs').rmSync('target/main', { recursive: true, force: true })\" && tsc -p tsconfig.json && node -e \"const fs = require('node:fs'); fs.cpSync('src/main/resources', 'target/main/resources', { recursive: true }); fs.cpSync('../../LICENSE', 'LICENSE')\"",
38
+ "prepack": "npm run build"
39
+ },
40
+ "dependencies": {
41
+ "@repometry/core": "0.5.0",
42
+ "@repometry/tree-sitter": "0.4.0"
43
+ }
44
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "package": "tree-sitter-c-sharp",
3
+ "version": "0.24.0",
4
+ "license": "MIT",
5
+ "source": "https://github.com/tree-sitter/tree-sitter-c-sharp/releases/download/v0.24.0/tree-sitter-c_sharp.wasm",
6
+ "sha256": "e137386fcdfc2562a058f8048c76ab77b0663a318cb62d8026cd4d2e94944231"
7
+ }
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2023 Max Brunsfeld, Damien Guard, Amaan Qureshi, and contributors.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ import type { LanguageUnit as Grammar } from '@repometry/tree-sitter';
2
+ type Node = Parameters<Grammar['name']>[0];
3
+ export declare function functionBody(node: Node): readonly Node[];
4
+ export declare const csharp: Grammar;
5
+ export {};
@@ -0,0 +1,141 @@
1
+ import { measures } from '@repometry/tree-sitter';
2
+ import manifest from '../resources/grammar.json' with { type: 'json' };
3
+ const classTypes = ['class_declaration', 'struct_declaration', 'interface_declaration', 'enum_declaration', 'record_declaration'];
4
+ const functionTypes = [
5
+ 'method_declaration', 'constructor_declaration', 'destructor_declaration', 'local_function_statement',
6
+ 'operator_declaration', 'conversion_operator_declaration', 'accessor_declaration',
7
+ 'lambda_expression', 'anonymous_method_expression', 'property_declaration', 'indexer_declaration',
8
+ ];
9
+ const controlBlocks = [
10
+ 'for_statement', 'foreach_statement', 'while_statement', 'do_statement', 'conditional_expression', 'catch_clause',
11
+ ];
12
+ const directiveTypes = new Set(['preproc_if', 'preproc_elif', 'preproc_else']);
13
+ const comments = new Set(['comment']);
14
+ function conditionalBody(wrapper) {
15
+ if (wrapper.type !== 'preproc_if')
16
+ return false;
17
+ for (let arm = wrapper; arm && directiveTypes.has(arm.type); arm = arm.childForFieldName('alternative')) {
18
+ if (arm.childForFieldName('body'))
19
+ return true;
20
+ }
21
+ return false;
22
+ }
23
+ export function functionBody(node) {
24
+ if (node.type === 'anonymous_method_expression') {
25
+ return node.namedChildren.filter(child => child.type === 'block');
26
+ }
27
+ if (node.type === 'property_declaration' || node.type === 'indexer_declaration') {
28
+ const value = node.childForFieldName('value');
29
+ return value?.type === 'arrow_expression_clause' ? [value] : [];
30
+ }
31
+ const direct = node.childForFieldName('body');
32
+ return direct ? [direct] : node.namedChildren.filter(conditionalBody);
33
+ }
34
+ function formalParameters(node) {
35
+ return node.childrenForFieldName('parameters').reduce((count, entry) => {
36
+ if (entry.type === 'implicit_parameter')
37
+ return count + 1;
38
+ if (entry.type !== 'parameter_list' && entry.type !== 'bracketed_parameter_list')
39
+ return count;
40
+ // The grammar flattens a params array's name beside wrapped parameters.
41
+ return count + entry.childrenForFieldName('name').length +
42
+ entry.namedChildren.filter(child => child.type === 'parameter').length;
43
+ }, 0);
44
+ }
45
+ function accessorParameters(node) {
46
+ const owner = node.parent?.parent;
47
+ return owner?.type === 'indexer_declaration' ? formalParameters(owner) : 0;
48
+ }
49
+ function name(node) {
50
+ const written = node.childForFieldName('name')?.text;
51
+ switch (node.type) {
52
+ case 'accessor_declaration': {
53
+ const owner = node.parent?.parent;
54
+ const member = owner?.type === 'indexer_declaration' ? 'this' : owner?.childForFieldName('name')?.text;
55
+ return member && written ? member + '.' + written : written;
56
+ }
57
+ case 'property_declaration': return written && written + '.get';
58
+ case 'indexer_declaration': return 'this.get';
59
+ case 'destructor_declaration': return written && '~' + written;
60
+ case 'operator_declaration':
61
+ case 'conversion_operator_declaration': {
62
+ const label = node.childForFieldName(node.type === 'operator_declaration' ? 'operator' : 'type')?.text;
63
+ return label && 'operator ' + label;
64
+ }
65
+ default: return written;
66
+ }
67
+ }
68
+ function alternativeBranches(wrapper) {
69
+ if (wrapper.type !== 'preproc_if')
70
+ return undefined;
71
+ const alternatives = [];
72
+ for (let arm = wrapper; arm && directiveTypes.has(arm.type); arm = arm.childForFieldName('alternative')) {
73
+ const children = arm.children;
74
+ const keyword = children.findIndex(child => child.type === 'else');
75
+ const alternate = arm.childForFieldName('alternative');
76
+ const statement = keyword < 0 ? undefined : children.slice(keyword + 1)
77
+ .find(child => child.isNamed && child.id !== alternate?.id && !comments.has(child.type));
78
+ if (statement)
79
+ alternatives.push(statement);
80
+ }
81
+ return alternatives.length ? alternatives : undefined;
82
+ }
83
+ function switchArm(node) {
84
+ const pattern = node.firstNamedChild;
85
+ const catchAll = pattern?.type === 'discard' ||
86
+ (pattern?.type === 'declaration_pattern' && pattern.childForFieldName('type')?.type === 'implicit_type');
87
+ return Number(!catchAll);
88
+ }
89
+ function operatorDecision(operator) {
90
+ return node => Number(node.childForFieldName('operator')?.type === operator);
91
+ }
92
+ const functionRule = { flow: 'function', requiresBody: true, body: functionBody, parameters: formalParameters };
93
+ const tokens = {
94
+ candidates: new Set([
95
+ ...classTypes, ...functionTypes, ...controlBlocks,
96
+ 'block', 'declaration_list', 'expression_statement', 'field_declaration', 'if_statement',
97
+ 'local_declaration_statement', 'return_statement', 'switch_body', 'switch_expression',
98
+ 'switch_expression_arm', 'switch_section', 'switch_statement', 'try_statement',
99
+ ]),
100
+ kinds: new Map([
101
+ ['identifier', 'identifier'], ['implicit_parameter', 'identifier'],
102
+ ['integer_literal', 'integer'], ['real_literal', 'float'], ['character_literal', 'character'],
103
+ ['string_literal', 'string'], ['verbatim_string_literal', 'string'], ['raw_string_literal', 'string'],
104
+ ['string_content', 'string-fragment'], ['boolean_literal', 'boolean'], ['null_literal', 'null'],
105
+ ]),
106
+ };
107
+ export const csharp = {
108
+ language: { id: 'csharp', label: 'C#', color: '#178600', extensions: ['.cs'], measures: [...measures, 'classes'] },
109
+ tool: { package: manifest.package, version: manifest.version },
110
+ asset: new URL('../resources/tree-sitter.wasm', import.meta.url),
111
+ prepareSource: text => text,
112
+ lineBreaks: /\r\n|[\n\r]/g,
113
+ columns: 'codepoints',
114
+ name,
115
+ recoverDeclarations: true,
116
+ ignoredFields: { preproc_if: 'condition', preproc_elif: 'condition' },
117
+ rules: {
118
+ ...Object.fromEntries(classTypes.map(type => [type, { flow: 'class' }])),
119
+ ...Object.fromEntries(functionTypes.map(type => [type, functionRule])),
120
+ accessor_declaration: { ...functionRule, parameters: accessorParameters },
121
+ if_statement: { flow: 'if', decision: true, alternativeBranches },
122
+ ...Object.fromEntries(controlBlocks.map(type => [type, { flow: 'nest', decision: true }])),
123
+ switch_statement: { flow: 'nest' },
124
+ switch_expression: { flow: 'nest' },
125
+ switch_section: { decision: node => Number(node.firstChild?.type === 'case') },
126
+ switch_expression_arm: { decision: switchArm },
127
+ when_clause: { decision: true },
128
+ catch_filter_clause: { decision: true },
129
+ binary_expression: { decision: operatorDecision('??') },
130
+ assignment_expression: { decision: operatorDecision('??=') },
131
+ return_statement: { exit: 'return' },
132
+ },
133
+ parens: new Set(['parenthesized_expression']),
134
+ comments,
135
+ extras: new Set(),
136
+ logicalTypes: new Set(['binary_expression']),
137
+ logicalOperators: new Set(['&&', '||']),
138
+ logicalCognitive: 'sequence',
139
+ moduleDepthLabel: 'Module · Control-flow depth',
140
+ tokens,
141
+ };
@@ -0,0 +1,7 @@
1
+ import { csharp } from './csharp.js';
2
+ export { csharp };
3
+ declare const _default: import("@repometry/core").PluginManifest<import("@repometry/core/internal/model/plugin-data.js").JsonValue> & {
4
+ readonly version: string;
5
+ create(): Awaited<ReturnType<import("@repometry/core").PluginManifest['create']>>;
6
+ };
7
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import { treeSitter } from '@repometry/tree-sitter';
2
+ import { csharp } from './csharp.js';
3
+ export { csharp };
4
+ export default treeSitter(csharp);
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.