@ctxo/lang-csharp 0.7.0-alpha.0
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 +21 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.js +800 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
- package/tools/ctxo-roslyn/Program.cs +637 -0
- package/tools/ctxo-roslyn/ctxo-roslyn.csproj +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alper Hankendi
|
|
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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { ILanguageAdapter, SymbolNode, GraphEdge, ComplexityMetrics, SymbolKind, CtxoLanguagePlugin } from '@ctxo/plugin-api';
|
|
2
|
+
import Parser, { Tree, SyntaxNode } from 'tree-sitter';
|
|
3
|
+
|
|
4
|
+
interface RoslynFileResult {
|
|
5
|
+
type: 'file';
|
|
6
|
+
file: string;
|
|
7
|
+
symbols: RoslynSymbol[];
|
|
8
|
+
edges: RoslynEdge[];
|
|
9
|
+
complexity: RoslynComplexity[];
|
|
10
|
+
}
|
|
11
|
+
interface RoslynSymbol {
|
|
12
|
+
symbolId: string;
|
|
13
|
+
name: string;
|
|
14
|
+
kind: string;
|
|
15
|
+
startLine: number;
|
|
16
|
+
endLine: number;
|
|
17
|
+
startOffset?: number;
|
|
18
|
+
endOffset?: number;
|
|
19
|
+
}
|
|
20
|
+
interface RoslynEdge {
|
|
21
|
+
from: string;
|
|
22
|
+
to: string;
|
|
23
|
+
kind: string;
|
|
24
|
+
}
|
|
25
|
+
interface RoslynComplexity {
|
|
26
|
+
symbolId: string;
|
|
27
|
+
cyclomatic: number;
|
|
28
|
+
cognitive: number;
|
|
29
|
+
}
|
|
30
|
+
interface RoslynProjectGraph {
|
|
31
|
+
type: 'projectGraph';
|
|
32
|
+
projects: Array<{
|
|
33
|
+
name: string;
|
|
34
|
+
path: string;
|
|
35
|
+
}>;
|
|
36
|
+
edges: Array<{
|
|
37
|
+
from: string;
|
|
38
|
+
to: string;
|
|
39
|
+
kind: string;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
interface RoslynBatchResult {
|
|
43
|
+
files: RoslynFileResult[];
|
|
44
|
+
projectGraph: RoslynProjectGraph | null;
|
|
45
|
+
totalFiles: number;
|
|
46
|
+
elapsed: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
declare class RoslynAdapter implements ILanguageAdapter {
|
|
50
|
+
readonly extensions: readonly [".cs"];
|
|
51
|
+
readonly tier: "full";
|
|
52
|
+
private roslynProjectDir;
|
|
53
|
+
private solutionPath;
|
|
54
|
+
private rootDir;
|
|
55
|
+
private cache;
|
|
56
|
+
private keepAlive;
|
|
57
|
+
private initialized;
|
|
58
|
+
isSupported(filePath: string): boolean;
|
|
59
|
+
isReady(): boolean;
|
|
60
|
+
initialize(rootDir: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Run batch analysis for all .cs files in the solution.
|
|
63
|
+
* Call this once before extractSymbols/extractEdges for best performance.
|
|
64
|
+
*/
|
|
65
|
+
batchIndex(): Promise<RoslynBatchResult | null>;
|
|
66
|
+
extractSymbols(filePath: string, _source: string): Promise<SymbolNode[]>;
|
|
67
|
+
extractEdges(filePath: string, _source: string): Promise<GraphEdge[]>;
|
|
68
|
+
extractComplexity(filePath: string, _source: string): Promise<ComplexityMetrics[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Start keep-alive process for watch mode.
|
|
71
|
+
*/
|
|
72
|
+
startKeepAlive(): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Incremental re-analysis of a single file (keep-alive mode).
|
|
75
|
+
*/
|
|
76
|
+
reindexFile(relativePath: string): Promise<RoslynFileResult | null>;
|
|
77
|
+
dispose(): Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Chooses between the full-tier Roslyn launcher and the syntax-tier tree-sitter
|
|
82
|
+
* adapter at initialize() time. Forwards extract*() calls to the active delegate
|
|
83
|
+
* and exposes the Roslyn delegate (when active) for cli optimizations such as
|
|
84
|
+
* watch-mode keep-alive and batch index pre-warm.
|
|
85
|
+
*/
|
|
86
|
+
declare class CSharpCompositeAdapter implements ILanguageAdapter {
|
|
87
|
+
private delegate;
|
|
88
|
+
private roslyn;
|
|
89
|
+
private treeSitter;
|
|
90
|
+
initialize(rootDir: string): Promise<void>;
|
|
91
|
+
dispose(): Promise<void>;
|
|
92
|
+
extractSymbols(filePath: string, source: string): Promise<SymbolNode[]>;
|
|
93
|
+
extractEdges(filePath: string, source: string): Promise<GraphEdge[]>;
|
|
94
|
+
extractComplexity(filePath: string, source: string): Promise<ComplexityMetrics[]>;
|
|
95
|
+
isSupported(filePath: string): boolean;
|
|
96
|
+
setSymbolRegistry(registry: Map<string, SymbolKind>): void;
|
|
97
|
+
/** Exposed for cli watch/index optimizations. Null when running in syntax tier. */
|
|
98
|
+
getRoslynDelegate(): RoslynAdapter | null;
|
|
99
|
+
/** Current active tier after initialize() resolves. */
|
|
100
|
+
getTier(): 'full' | 'syntax' | 'unavailable';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
type Language = Parameters<InstanceType<typeof Parser>['setLanguage']>[0];
|
|
104
|
+
|
|
105
|
+
declare abstract class TreeSitterAdapter implements ILanguageAdapter {
|
|
106
|
+
abstract readonly extensions: readonly string[];
|
|
107
|
+
readonly tier: "syntax";
|
|
108
|
+
protected parser: Parser;
|
|
109
|
+
protected symbolRegistry: Map<string, "function" | "class" | "interface" | "method" | "variable" | "type">;
|
|
110
|
+
constructor(language: Language);
|
|
111
|
+
isSupported(filePath: string): boolean;
|
|
112
|
+
setSymbolRegistry(registry: Map<string, SymbolKind>): void;
|
|
113
|
+
protected parse(source: string): Tree;
|
|
114
|
+
protected buildSymbolId(filePath: string, name: string, kind: SymbolKind): string;
|
|
115
|
+
protected nodeToLineRange(node: SyntaxNode): {
|
|
116
|
+
startLine: number;
|
|
117
|
+
endLine: number;
|
|
118
|
+
startOffset: number;
|
|
119
|
+
endOffset: number;
|
|
120
|
+
};
|
|
121
|
+
protected countCyclomaticComplexity(node: SyntaxNode, branchTypes: string[]): number;
|
|
122
|
+
abstract extractSymbols(filePath: string, source: string): Promise<SymbolNode[]>;
|
|
123
|
+
abstract extractEdges(filePath: string, source: string): Promise<GraphEdge[]>;
|
|
124
|
+
abstract extractComplexity(filePath: string, source: string): Promise<ComplexityMetrics[]>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
declare class CSharpAdapter extends TreeSitterAdapter {
|
|
128
|
+
readonly extensions: readonly [".cs"];
|
|
129
|
+
constructor();
|
|
130
|
+
extractSymbols(filePath: string, source: string): Promise<SymbolNode[]>;
|
|
131
|
+
extractEdges(filePath: string, source: string): Promise<GraphEdge[]>;
|
|
132
|
+
extractComplexity(filePath: string, source: string): Promise<ComplexityMetrics[]>;
|
|
133
|
+
private visitSymbols;
|
|
134
|
+
private extractMethodSymbols;
|
|
135
|
+
private visitEdges;
|
|
136
|
+
private visitComplexity;
|
|
137
|
+
private countParameters;
|
|
138
|
+
private isPublic;
|
|
139
|
+
private resolveBaseType;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
declare const plugin: CtxoLanguagePlugin;
|
|
143
|
+
|
|
144
|
+
export { CSharpAdapter, CSharpCompositeAdapter, RoslynAdapter, TreeSitterAdapter, plugin as default, plugin };
|