@birdcc/core 0.0.1-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/.oxfmtrc.json +16 -0
- package/LICENSE +674 -0
- package/README.md +343 -0
- package/dist/cross-file.d.ts +5 -0
- package/dist/cross-file.d.ts.map +1 -0
- package/dist/cross-file.js +264 -0
- package/dist/cross-file.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/prefix.d.ts +2 -0
- package/dist/prefix.d.ts.map +1 -0
- package/dist/prefix.js +76 -0
- package/dist/prefix.js.map +1 -0
- package/dist/range.d.ts +3 -0
- package/dist/range.d.ts.map +1 -0
- package/dist/range.js +7 -0
- package/dist/range.js.map +1 -0
- package/dist/semantic-diagnostics.d.ts +4 -0
- package/dist/semantic-diagnostics.d.ts.map +1 -0
- package/dist/semantic-diagnostics.js +75 -0
- package/dist/semantic-diagnostics.js.map +1 -0
- package/dist/snapshot.d.ts +7 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +22 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/symbol-table.d.ts +9 -0
- package/dist/symbol-table.d.ts.map +1 -0
- package/dist/symbol-table.js +118 -0
- package/dist/symbol-table.js.map +1 -0
- package/dist/template-cycles.d.ts +9 -0
- package/dist/template-cycles.d.ts.map +1 -0
- package/dist/template-cycles.js +95 -0
- package/dist/template-cycles.js.map +1 -0
- package/dist/type-checker.d.ts +4 -0
- package/dist/type-checker.d.ts.map +1 -0
- package/dist/type-checker.js +390 -0
- package/dist/type-checker.js.map +1 -0
- package/dist/types.d.ts +84 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
- package/scripts/benchmark-node-vs-regex.js +86 -0
- package/src/cross-file.ts +412 -0
- package/src/index.ts +42 -0
- package/src/prefix.ts +94 -0
- package/src/range.ts +12 -0
- package/src/semantic-diagnostics.ts +93 -0
- package/src/snapshot.ts +32 -0
- package/src/symbol-table.ts +171 -0
- package/src/template-cycles.ts +142 -0
- package/src/type-checker.ts +595 -0
- package/src/types.ts +101 -0
- package/test/core.test.ts +503 -0
- package/test/prefix.test.ts +40 -0
- package/tsconfig.json +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 🦅 BIRD Config Core (@birdcc/core)
|
|
4
|
+
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@birdcc/core) [](https://www.gnu.org/licenses/gpl-3.0) [](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
> [Overview](#overview) · [Features](#features) · [Installation](#installation) · [Usage](#usage) · [API Reference](#api-reference) · [Architecture](#architecture)
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
**@birdcc/core** is the semantic analysis engine for BIRD2 configuration files, providing symbol table construction, type checking, and cross-file resolution capabilities.
|
|
14
|
+
|
|
15
|
+
### Core Highlights
|
|
16
|
+
|
|
17
|
+
| Feature | Description |
|
|
18
|
+
| ------- | ----------- |
|
|
19
|
+
| 🔍 Symbol Table | Automatic collection of protocol/template/filter/function definitions |
|
|
20
|
+
| ⚠️ Semantic Checks | Detect duplicate definitions and undefined references |
|
|
21
|
+
| 📋 Diagnostics | Standardized diagnostic format with error/warning/info levels |
|
|
22
|
+
| 🔗 Cross-file | Support for `include` statements and cross-file symbol resolution |
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
### Symbol Table Construction
|
|
29
|
+
|
|
30
|
+
Automatically extracts and indexes:
|
|
31
|
+
|
|
32
|
+
- **`protocol`** — Protocol definitions (BGP/OSPF/Static/Direct/etc.)
|
|
33
|
+
- **`template`** — Protocol templates with inheritance support
|
|
34
|
+
- **`filter`** — Filter function definitions
|
|
35
|
+
- **`function`** — Custom function definitions
|
|
36
|
+
- **`table`** — Routing table declarations
|
|
37
|
+
|
|
38
|
+
### Semantic Validation
|
|
39
|
+
|
|
40
|
+
- **Duplicate Detection** — Identifies redefined symbols
|
|
41
|
+
- **Undefined References** — Detects references to non-existent templates
|
|
42
|
+
- **Type Checking** — Validates type compatibility in expressions
|
|
43
|
+
- **Scope Analysis** — Tracks variable scope within filters/functions
|
|
44
|
+
|
|
45
|
+
### Cross-file Resolution
|
|
46
|
+
|
|
47
|
+
- **`include` Support** — Parse and merge included configuration files
|
|
48
|
+
- **Circular Detection** — Detect circular include dependencies
|
|
49
|
+
- **Symbol Merging** — Combine symbol tables from multiple files
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Using pnpm (recommended)
|
|
57
|
+
pnpm add @birdcc/core
|
|
58
|
+
|
|
59
|
+
# Using npm
|
|
60
|
+
npm install @birdcc/core
|
|
61
|
+
|
|
62
|
+
# Using yarn
|
|
63
|
+
yarn add @birdcc/core
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Prerequisites
|
|
67
|
+
|
|
68
|
+
- Node.js >= 18
|
|
69
|
+
- TypeScript >= 5.0 (if using TypeScript)
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
### Basic Semantic Analysis
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { buildCoreSnapshot } from "@birdcc/core";
|
|
79
|
+
|
|
80
|
+
const config = `
|
|
81
|
+
protocol bgp upstream {
|
|
82
|
+
local as 65001;
|
|
83
|
+
neighbor 192.168.1.1 as 65002;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
protocol bgp upstream { // ← Duplicate definition!
|
|
87
|
+
local as 65001;
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
const snapshot = buildCoreSnapshot(config);
|
|
92
|
+
|
|
93
|
+
console.log(snapshot.symbols);
|
|
94
|
+
// [
|
|
95
|
+
// { kind: "protocol", name: "upstream", line: 2, column: 12 },
|
|
96
|
+
// { kind: "protocol", name: "upstream", line: 7, column: 12 }
|
|
97
|
+
// ]
|
|
98
|
+
|
|
99
|
+
console.log(snapshot.diagnostics);
|
|
100
|
+
// [
|
|
101
|
+
// {
|
|
102
|
+
// code: "semantic/duplicate-definition",
|
|
103
|
+
// message: "protocol 'upstream' is defined multiple times",
|
|
104
|
+
// severity: "error",
|
|
105
|
+
// ...
|
|
106
|
+
// }
|
|
107
|
+
// ]
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Using with Parser
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { parseBirdConfig } from "@birdcc/parser";
|
|
114
|
+
import { buildCoreSnapshotFromParsed } from "@birdcc/core";
|
|
115
|
+
|
|
116
|
+
const parsed = await parseBirdConfig(source);
|
|
117
|
+
const snapshot = buildCoreSnapshotFromParsed(parsed);
|
|
118
|
+
|
|
119
|
+
// Access symbols and diagnostics
|
|
120
|
+
console.log(`Found ${snapshot.symbols.length} symbols`);
|
|
121
|
+
console.log(`Found ${snapshot.diagnostics.length} issues`);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Cross-file Analysis
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { resolveCrossFileReferences } from "@birdcc/core";
|
|
128
|
+
|
|
129
|
+
const result = await resolveCrossFileReferences(mainFile, {
|
|
130
|
+
includePaths: ["./config", "./templates"],
|
|
131
|
+
maxDepth: 10,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
console.log(result.mergedSymbols);
|
|
135
|
+
console.log(result.diagnostics);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## API Reference
|
|
141
|
+
|
|
142
|
+
### Main Functions
|
|
143
|
+
|
|
144
|
+
#### `buildCoreSnapshot(text: string): CoreSnapshot`
|
|
145
|
+
|
|
146
|
+
Build a semantic analysis snapshot from raw text.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { buildCoreSnapshot } from "@birdcc/core";
|
|
150
|
+
|
|
151
|
+
const snapshot = buildCoreSnapshot(birdConfigText);
|
|
152
|
+
// snapshot.symbols → List of symbol definitions
|
|
153
|
+
// snapshot.diagnostics → List of diagnostic messages
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### `buildCoreSnapshotFromParsed(parsed: ParsedBirdDocument): CoreSnapshot`
|
|
157
|
+
|
|
158
|
+
Build a semantic analysis snapshot from an already parsed AST.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { parseBirdConfig } from "@birdcc/parser";
|
|
162
|
+
import { buildCoreSnapshotFromParsed } from "@birdcc/core";
|
|
163
|
+
|
|
164
|
+
const parsed = await parseBirdConfig(text);
|
|
165
|
+
const snapshot = buildCoreSnapshotFromParsed(parsed);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Core Types
|
|
169
|
+
|
|
170
|
+
#### `CoreSnapshot`
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
interface CoreSnapshot {
|
|
174
|
+
/** All symbol definitions */
|
|
175
|
+
symbols: SymbolDefinition[];
|
|
176
|
+
/** Template reference information */
|
|
177
|
+
references: SymbolReference[];
|
|
178
|
+
/** Semantic check diagnostics */
|
|
179
|
+
diagnostics: BirdDiagnostic[];
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
#### `SymbolDefinition`
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
interface SymbolDefinition {
|
|
187
|
+
kind: "protocol" | "template" | "filter" | "function" | "table";
|
|
188
|
+
name: string;
|
|
189
|
+
line: number;
|
|
190
|
+
column: number;
|
|
191
|
+
endLine: number;
|
|
192
|
+
endColumn: number;
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### `BirdDiagnostic`
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
interface BirdDiagnostic {
|
|
200
|
+
code: string;
|
|
201
|
+
message: string;
|
|
202
|
+
severity: "error" | "warning" | "info";
|
|
203
|
+
source: string;
|
|
204
|
+
range: {
|
|
205
|
+
line: number;
|
|
206
|
+
column: number;
|
|
207
|
+
endLine: number;
|
|
208
|
+
endColumn: number;
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Diagnostic Codes
|
|
214
|
+
|
|
215
|
+
| Code | Description | Level |
|
|
216
|
+
| ---- | ----------- | ----- |
|
|
217
|
+
| `semantic/duplicate-definition` | Duplicate symbol definition | error |
|
|
218
|
+
| `semantic/undefined-reference` | Reference to undefined template | error |
|
|
219
|
+
| `semantic/type-mismatch` | Type compatibility error | error |
|
|
220
|
+
| `semantic/invalid-scope` | Variable scope violation | warning |
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## Architecture
|
|
225
|
+
|
|
226
|
+
### Layer Position
|
|
227
|
+
|
|
228
|
+
```mermaid
|
|
229
|
+
flowchart TB
|
|
230
|
+
subgraph "Rule Engine"
|
|
231
|
+
A[@birdcc/linter]
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
subgraph "Semantic Analysis"
|
|
235
|
+
B[@birdcc/core]
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
subgraph "Syntax Parsing"
|
|
239
|
+
C[@birdcc/parser]
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
A -->|uses| B
|
|
243
|
+
B -->|uses| C
|
|
244
|
+
|
|
245
|
+
style A fill:#e1f5fe
|
|
246
|
+
style B fill:#fff3e0
|
|
247
|
+
style C fill:#e8f5e9
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Internal Components
|
|
251
|
+
|
|
252
|
+
```mermaid
|
|
253
|
+
flowchart TB
|
|
254
|
+
subgraph "Input"
|
|
255
|
+
SRC[BIRD Config Source]
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
subgraph "Parser Layer"
|
|
259
|
+
P[@birdcc/parser<br/>Tree-sitter]
|
|
260
|
+
AST[AST<br/>Abstract Syntax Tree]
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
subgraph "Core Layer"
|
|
264
|
+
SC[Symbol Collector]
|
|
265
|
+
ST[(Symbol Table)]
|
|
266
|
+
SEM[Semantic Checker]
|
|
267
|
+
DIAG[Diagnostics]
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
SRC --> P
|
|
271
|
+
P --> AST
|
|
272
|
+
AST --> SC
|
|
273
|
+
SC --> ST
|
|
274
|
+
ST --> SEM
|
|
275
|
+
SEM --> DIAG
|
|
276
|
+
|
|
277
|
+
style ST fill:#fff3e0
|
|
278
|
+
style DIAG fill:#ffebee
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Symbol Resolution Flow
|
|
282
|
+
|
|
283
|
+
```mermaid
|
|
284
|
+
sequenceDiagram
|
|
285
|
+
participant User as User Code
|
|
286
|
+
participant Core as @birdcc/core
|
|
287
|
+
participant Collector as SymbolCollector
|
|
288
|
+
participant Checker as SemanticChecker
|
|
289
|
+
participant Table as SymbolTable
|
|
290
|
+
|
|
291
|
+
User->>Core: buildCoreSnapshot(text)
|
|
292
|
+
Core->>Collector: collectSymbols(ast)
|
|
293
|
+
Collector->>Table: addSymbol(protocol)
|
|
294
|
+
Collector->>Table: addSymbol(template)
|
|
295
|
+
Collector->>Table: addSymbol(filter)
|
|
296
|
+
Collector->>Table: addSymbol(function)
|
|
297
|
+
Table-->>Collector: symbols[]
|
|
298
|
+
Collector-->>Core: symbols, references
|
|
299
|
+
Core->>Checker: validate(symbols, references)
|
|
300
|
+
Checker->>Table: checkDuplicates()
|
|
301
|
+
Checker->>Table: checkUndefinedRefs()
|
|
302
|
+
Table-->>Checker: validation results
|
|
303
|
+
Checker-->>Core: diagnostics[]
|
|
304
|
+
Core-->>User: CoreSnapshot
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## Related Packages
|
|
310
|
+
|
|
311
|
+
| Package | Description |
|
|
312
|
+
| ------- | ----------- |
|
|
313
|
+
| [@birdcc/parser](../parser/) | Tree-sitter grammar and parser |
|
|
314
|
+
| [@birdcc/linter](../linter/) | 32+ lint rules and diagnostics |
|
|
315
|
+
| [@birdcc/formatter](../formatter/) | Code formatting engine |
|
|
316
|
+
| [@birdcc/lsp](../lsp/) | LSP server implementation |
|
|
317
|
+
| [@birdcc/cli](../cli/) | Command-line interface |
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
### 📖 Documentation
|
|
322
|
+
|
|
323
|
+
- [BIRD Official Documentation](https://bird.network.cz/)
|
|
324
|
+
- [BIRD2 User Manual](https://bird.network.cz/doc/bird.html)
|
|
325
|
+
- [GitHub Project](https://github.com/bird-chinese-community/BIRD-LSP)
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## 📝 License
|
|
330
|
+
|
|
331
|
+
This project is licensed under the [GPL-3.0 License](https://github.com/bird-chinese-community/BIRD-LSP/blob/main/LICENSE).
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
<p align="center">
|
|
336
|
+
<sub>Built with ❤️ by the BIRD Chinese Community (BIRDCC)</sub>
|
|
337
|
+
</p>
|
|
338
|
+
|
|
339
|
+
<p align="center">
|
|
340
|
+
<a href="https://github.com/bird-chinese-community/BIRD-LSP">🕊 GitHub</a> ·
|
|
341
|
+
<a href="https://marketplace.visualstudio.com/items?itemName=birdcc.bird2-lsp">🛒 Marketplace</a> ·
|
|
342
|
+
<a href="https://github.com/bird-chinese-community/BIRD-LSP/issues">🐛 Report Issues</a>
|
|
343
|
+
</p>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CrossFileResolveOptions, CrossFileResolutionResult } from "./types.js";
|
|
2
|
+
export declare const DEFAULT_CROSS_FILE_MAX_DEPTH = 16;
|
|
3
|
+
export declare const DEFAULT_CROSS_FILE_MAX_FILES = 256;
|
|
4
|
+
export declare const resolveCrossFileReferences: (options: CrossFileResolveOptions) => Promise<CrossFileResolutionResult>;
|
|
5
|
+
//# sourceMappingURL=cross-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-file.d.ts","sourceRoot":"","sources":["../src/cross-file.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGV,uBAAuB,EACvB,yBAAyB,EAG1B,MAAM,YAAY,CAAC;AAQpB,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAC/C,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAwKhD,eAAO,MAAM,0BAA0B,GACrC,SAAS,uBAAuB,KAC/B,OAAO,CAAC,yBAAyB,CA4NnC,CAAC"}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, isAbsolute, normalize, relative, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
import { parseBirdConfig } from "@birdcc/parser";
|
|
5
|
+
import { buildCoreSnapshotFromParsed } from "./snapshot.js";
|
|
6
|
+
import { mergeSymbolTables, pushSymbolTableDiagnostics, } from "./symbol-table.js";
|
|
7
|
+
import { collectCircularTemplateDiagnostics } from "./template-cycles.js";
|
|
8
|
+
export const DEFAULT_CROSS_FILE_MAX_DEPTH = 16;
|
|
9
|
+
export const DEFAULT_CROSS_FILE_MAX_FILES = 256;
|
|
10
|
+
const PARSED_DOCUMENT_CACHE_LIMIT = 512;
|
|
11
|
+
const parsedDocumentCache = new Map();
|
|
12
|
+
const DEFAULT_RANGE = {
|
|
13
|
+
line: 1,
|
|
14
|
+
column: 1,
|
|
15
|
+
endLine: 1,
|
|
16
|
+
endColumn: 1,
|
|
17
|
+
};
|
|
18
|
+
const isFileUri = (uri) => uri.startsWith("file://");
|
|
19
|
+
const toFilePath = (uri) => {
|
|
20
|
+
if (isFileUri(uri)) {
|
|
21
|
+
return fileURLToPath(uri);
|
|
22
|
+
}
|
|
23
|
+
if (uri.startsWith("/")) {
|
|
24
|
+
return uri;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
};
|
|
28
|
+
const normalizeUriForPrefixMatch = (uri) => uri.replace(/\/+$/, "");
|
|
29
|
+
const toDefaultWorkspaceRootUri = (entryUri) => {
|
|
30
|
+
const entryPath = toFilePath(entryUri);
|
|
31
|
+
if (entryPath) {
|
|
32
|
+
return pathToFileURL(dirname(entryPath)).toString();
|
|
33
|
+
}
|
|
34
|
+
return normalize(dirname(entryUri));
|
|
35
|
+
};
|
|
36
|
+
const isWithinWorkspaceRoot = (candidateUri, workspaceRootUri) => {
|
|
37
|
+
const candidatePath = toFilePath(candidateUri);
|
|
38
|
+
const workspaceRootPath = toFilePath(workspaceRootUri);
|
|
39
|
+
if (candidatePath && workspaceRootPath) {
|
|
40
|
+
const resolvedRoot = normalize(workspaceRootPath);
|
|
41
|
+
const resolvedCandidate = normalize(candidatePath);
|
|
42
|
+
const relPath = relative(resolvedRoot, resolvedCandidate);
|
|
43
|
+
return (relPath.length === 0 ||
|
|
44
|
+
(!relPath.startsWith("..") && !isAbsolute(relPath)));
|
|
45
|
+
}
|
|
46
|
+
const normalizedRoot = normalizeUriForPrefixMatch(normalize(workspaceRootUri));
|
|
47
|
+
const normalizedCandidate = normalizeUriForPrefixMatch(normalize(candidateUri));
|
|
48
|
+
return (normalizedCandidate === normalizedRoot ||
|
|
49
|
+
normalizedCandidate.startsWith(`${normalizedRoot}/`));
|
|
50
|
+
};
|
|
51
|
+
const defaultReadFileText = async (uri) => {
|
|
52
|
+
const filePath = toFilePath(uri);
|
|
53
|
+
if (!filePath) {
|
|
54
|
+
throw new Error(`Unsupported non-file URI '${uri}'`);
|
|
55
|
+
}
|
|
56
|
+
return readFile(filePath, "utf8");
|
|
57
|
+
};
|
|
58
|
+
const resolveIncludeUri = (baseUri, includePath) => {
|
|
59
|
+
if (includePath.startsWith("file://")) {
|
|
60
|
+
return pathToFileURL(normalize(fileURLToPath(includePath))).toString();
|
|
61
|
+
}
|
|
62
|
+
if (isFileUri(baseUri)) {
|
|
63
|
+
const basePath = fileURLToPath(baseUri);
|
|
64
|
+
const resolvedPath = resolve(dirname(basePath), includePath);
|
|
65
|
+
return pathToFileURL(resolvedPath).toString();
|
|
66
|
+
}
|
|
67
|
+
return normalize(resolve(dirname(baseUri), includePath));
|
|
68
|
+
};
|
|
69
|
+
const includeDiagnostic = (uri, message, range = DEFAULT_RANGE) => ({
|
|
70
|
+
code: "semantic/missing-include",
|
|
71
|
+
message,
|
|
72
|
+
severity: "warning",
|
|
73
|
+
source: "core",
|
|
74
|
+
uri,
|
|
75
|
+
range: {
|
|
76
|
+
line: range.line,
|
|
77
|
+
column: range.column,
|
|
78
|
+
endLine: range.endLine,
|
|
79
|
+
endColumn: range.endColumn,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
const dedupeDiagnostics = (diagnostics) => {
|
|
83
|
+
const seen = new Set();
|
|
84
|
+
const output = [];
|
|
85
|
+
for (const diagnostic of diagnostics) {
|
|
86
|
+
const key = [
|
|
87
|
+
diagnostic.code,
|
|
88
|
+
diagnostic.message,
|
|
89
|
+
diagnostic.uri ?? "",
|
|
90
|
+
diagnostic.range.line,
|
|
91
|
+
diagnostic.range.column,
|
|
92
|
+
diagnostic.range.endLine,
|
|
93
|
+
diagnostic.range.endColumn,
|
|
94
|
+
].join(":");
|
|
95
|
+
if (seen.has(key)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
seen.add(key);
|
|
99
|
+
output.push(diagnostic);
|
|
100
|
+
}
|
|
101
|
+
return output;
|
|
102
|
+
};
|
|
103
|
+
const parseDocumentWithCache = async (uri, text, stats) => {
|
|
104
|
+
const cached = parsedDocumentCache.get(uri);
|
|
105
|
+
if (cached && cached.text === text) {
|
|
106
|
+
stats.parsedCacheHits += 1;
|
|
107
|
+
return cached.parsed;
|
|
108
|
+
}
|
|
109
|
+
stats.parsedCacheMisses += 1;
|
|
110
|
+
const parsed = await parseBirdConfig(text);
|
|
111
|
+
if (parsedDocumentCache.size >= PARSED_DOCUMENT_CACHE_LIMIT) {
|
|
112
|
+
const oldestKey = parsedDocumentCache.keys().next().value;
|
|
113
|
+
if (oldestKey) {
|
|
114
|
+
parsedDocumentCache.delete(oldestKey);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
parsedDocumentCache.set(uri, { text, parsed });
|
|
118
|
+
return parsed;
|
|
119
|
+
};
|
|
120
|
+
export const resolveCrossFileReferences = async (options) => {
|
|
121
|
+
const maxDepth = options.maxDepth ?? DEFAULT_CROSS_FILE_MAX_DEPTH;
|
|
122
|
+
const maxFiles = options.maxFiles ?? DEFAULT_CROSS_FILE_MAX_FILES;
|
|
123
|
+
const loadFromFileSystem = options.loadFromFileSystem ?? true;
|
|
124
|
+
const readFileText = options.readFileText ?? defaultReadFileText;
|
|
125
|
+
const workspaceRootUri = options.workspaceRootUri ?? toDefaultWorkspaceRootUri(options.entryUri);
|
|
126
|
+
const allowIncludeOutsideWorkspace = options.allowIncludeOutsideWorkspace ?? false;
|
|
127
|
+
const stats = {
|
|
128
|
+
loadedFromMemory: options.documents?.length ?? 0,
|
|
129
|
+
loadedFromFileSystem: 0,
|
|
130
|
+
skippedByDepth: 0,
|
|
131
|
+
skippedByFileLimit: 0,
|
|
132
|
+
missingIncludes: 0,
|
|
133
|
+
parsedCacheHits: 0,
|
|
134
|
+
parsedCacheMisses: 0,
|
|
135
|
+
};
|
|
136
|
+
const documentMap = new Map((options.documents ?? []).map((document) => [
|
|
137
|
+
document.uri,
|
|
138
|
+
{ uri: document.uri, text: document.text },
|
|
139
|
+
]));
|
|
140
|
+
const parsedDocuments = new Map();
|
|
141
|
+
const snapshots = {};
|
|
142
|
+
const queue = [{ uri: options.entryUri, depth: 0 }];
|
|
143
|
+
const queued = new Set([options.entryUri]);
|
|
144
|
+
const visited = new Set();
|
|
145
|
+
const diagnostics = [];
|
|
146
|
+
const ensureDocument = async (uri) => {
|
|
147
|
+
if (documentMap.has(uri)) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
if (!loadFromFileSystem) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
const text = await readFileText(uri);
|
|
155
|
+
documentMap.set(uri, { uri, text });
|
|
156
|
+
stats.loadedFromFileSystem += 1;
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
if (!(await ensureDocument(options.entryUri))) {
|
|
164
|
+
return {
|
|
165
|
+
entryUri: options.entryUri,
|
|
166
|
+
visitedUris: [],
|
|
167
|
+
symbolTable: { definitions: [], references: [] },
|
|
168
|
+
snapshots: {},
|
|
169
|
+
documents: {},
|
|
170
|
+
diagnostics: [
|
|
171
|
+
includeDiagnostic(options.entryUri, `Entry file not found or not readable: '${options.entryUri}'`),
|
|
172
|
+
],
|
|
173
|
+
stats,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
while (queue.length > 0) {
|
|
177
|
+
const current = queue.shift();
|
|
178
|
+
if (!current) {
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
if (visited.has(current.uri)) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (current.depth > maxDepth) {
|
|
185
|
+
stats.skippedByDepth += 1;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (visited.size >= maxFiles) {
|
|
189
|
+
stats.skippedByFileLimit += 1;
|
|
190
|
+
diagnostics.push(includeDiagnostic(current.uri, `Cross-file analysis stopped after reaching max files limit (${maxFiles})`));
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
visited.add(current.uri);
|
|
194
|
+
const document = documentMap.get(current.uri);
|
|
195
|
+
if (!document) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const parsed = await parseDocumentWithCache(current.uri, document.text, stats);
|
|
199
|
+
parsedDocuments.set(current.uri, parsed);
|
|
200
|
+
snapshots[current.uri] = buildCoreSnapshotFromParsed(parsed, {
|
|
201
|
+
uri: current.uri,
|
|
202
|
+
typeCheck: options.typeCheck,
|
|
203
|
+
});
|
|
204
|
+
for (const declaration of parsed.program.declarations) {
|
|
205
|
+
if (declaration.kind !== "include" || declaration.path.length === 0) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const includeUri = resolveIncludeUri(current.uri, declaration.path);
|
|
209
|
+
const includeRange = declaration.pathRange;
|
|
210
|
+
if (!allowIncludeOutsideWorkspace &&
|
|
211
|
+
!isWithinWorkspaceRoot(includeUri, workspaceRootUri)) {
|
|
212
|
+
diagnostics.push(includeDiagnostic(current.uri, `Include skipped outside workspace root '${workspaceRootUri}': '${declaration.path}'`, includeRange));
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (visited.has(includeUri) || queued.has(includeUri)) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (current.depth + 1 > maxDepth) {
|
|
219
|
+
stats.skippedByDepth += 1;
|
|
220
|
+
diagnostics.push(includeDiagnostic(current.uri, `Include skipped due to max depth (${maxDepth}): '${declaration.path}'`, includeRange));
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (visited.size + queue.length >= maxFiles) {
|
|
224
|
+
stats.skippedByFileLimit += 1;
|
|
225
|
+
diagnostics.push(includeDiagnostic(current.uri, `Include skipped due to max files limit (${maxFiles}): '${declaration.path}'`, includeRange));
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const loaded = await ensureDocument(includeUri);
|
|
229
|
+
if (!loaded) {
|
|
230
|
+
stats.missingIncludes += 1;
|
|
231
|
+
diagnostics.push(includeDiagnostic(current.uri, `Included file not found in workspace: '${declaration.path}'`, includeRange));
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
queue.push({ uri: includeUri, depth: current.depth + 1 });
|
|
235
|
+
queued.add(includeUri);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const mergedSymbolTable = mergeSymbolTables(Object.values(snapshots).map((snapshot) => snapshot.symbolTable));
|
|
239
|
+
pushSymbolTableDiagnostics(mergedSymbolTable, diagnostics);
|
|
240
|
+
for (const [uri, snapshot] of Object.entries(snapshots)) {
|
|
241
|
+
for (const diagnostic of snapshot.diagnostics) {
|
|
242
|
+
if (diagnostic.code === "semantic/duplicate-definition" ||
|
|
243
|
+
diagnostic.code === "semantic/undefined-reference" ||
|
|
244
|
+
diagnostic.code === "semantic/circular-template") {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
diagnostics.push({
|
|
248
|
+
...diagnostic,
|
|
249
|
+
uri,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
diagnostics.push(...collectCircularTemplateDiagnostics([...parsedDocuments.entries()].map(([uri, parsed]) => ({ uri, parsed }))));
|
|
254
|
+
return {
|
|
255
|
+
entryUri: options.entryUri,
|
|
256
|
+
visitedUris: [...visited],
|
|
257
|
+
symbolTable: mergedSymbolTable,
|
|
258
|
+
snapshots,
|
|
259
|
+
documents: Object.fromEntries([...documentMap.entries()].map(([uri, document]) => [uri, document.text])),
|
|
260
|
+
diagnostics: dedupeDiagnostics(diagnostics),
|
|
261
|
+
stats,
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
//# sourceMappingURL=cross-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-file.js","sourceRoot":"","sources":["../src/cross-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,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,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,CACzE,CACF,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC;QACzB,WAAW,EAAE,iBAAiB;QAC9B,SAAS;QACT,SAAS,EAAE,MAAM,CAAC,WAAW,CAC3B,CAAC,GAAG,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAC1E;QACD,WAAW,EAAE,iBAAiB,CAAC,WAAW,CAAC;QAC3C,KAAK;KACN,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { resolveCrossFileReferences } from "./cross-file.js";
|
|
2
|
+
export type { BirdDiagnostic, BirdDiagnosticSeverity, BirdRange, BirdSymbolKind, CoreSnapshot, CrossFileDocumentInput, CrossFileResolveOptions, CrossFileResolutionResult, CrossFileResolutionStats, SymbolDefinition, SymbolReference, SymbolTable, TypeCheckOptions, TypeValue, } from "./types.js";
|
|
3
|
+
export { checkTypes } from "./type-checker.js";
|
|
4
|
+
export { DEFAULT_DOCUMENT_URI, buildSymbolTableFromParsed, mergeSymbolTables, pushSymbolTableDiagnostics, } from "./symbol-table.js";
|
|
5
|
+
export { buildCoreSnapshotFromParsed } from "./snapshot.js";
|
|
6
|
+
export { DEFAULT_CROSS_FILE_MAX_DEPTH, DEFAULT_CROSS_FILE_MAX_FILES, resolveCrossFileReferences, } from "./cross-file.js";
|
|
7
|
+
/** Parses and builds semantic snapshot in one async call. */
|
|
8
|
+
export declare const buildCoreSnapshot: (text: string) => Promise<import("./types.js").CoreSnapshot>;
|
|
9
|
+
export type ResolveCrossFileReferences = typeof resolveCrossFileReferences;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAG7D,YAAY,EACV,cAAc,EACd,sBAAsB,EACtB,SAAS,EACT,cAAc,EACd,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,wBAAwB,EACxB,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC;AAEzB,6DAA6D;AAC7D,eAAO,MAAM,iBAAiB,GAAU,MAAM,MAAM,+CAGnD,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,OAAO,0BAA0B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parseBirdConfig } from "@birdcc/parser";
|
|
2
|
+
import { buildCoreSnapshotFromParsed } from "./snapshot.js";
|
|
3
|
+
export { checkTypes } from "./type-checker.js";
|
|
4
|
+
export { DEFAULT_DOCUMENT_URI, buildSymbolTableFromParsed, mergeSymbolTables, pushSymbolTableDiagnostics, } from "./symbol-table.js";
|
|
5
|
+
export { buildCoreSnapshotFromParsed } from "./snapshot.js";
|
|
6
|
+
export { DEFAULT_CROSS_FILE_MAX_DEPTH, DEFAULT_CROSS_FILE_MAX_FILES, resolveCrossFileReferences, } from "./cross-file.js";
|
|
7
|
+
/** Parses and builds semantic snapshot in one async call. */
|
|
8
|
+
export const buildCoreSnapshot = async (text) => {
|
|
9
|
+
const parsed = await parseBirdConfig(text);
|
|
10
|
+
return buildCoreSnapshotFromParsed(parsed);
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAmB5D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC;AAEzB,6DAA6D;AAC7D,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE;IACtD,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC;IAC3C,OAAO,2BAA2B,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC,CAAC"}
|
package/dist/prefix.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefix.d.ts","sourceRoot":"","sources":["../src/prefix.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM,KAAG,OAmEtD,CAAC"}
|