@shapeshift-labs/frontier-lang-compiler 0.2.22 → 0.2.23
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/README.md +28 -0
- package/bench/smoke.mjs +40 -1
- package/dist/index.d.ts +59 -0
- package/dist/index.js +1218 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,6 +50,34 @@ console.log(imported.nativeSource.ast.rootId);
|
|
|
50
50
|
console.log(imported.patch.operations.length);
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
Import external code-intelligence payloads into Frontier semantic evidence when a project already has language tooling such as SCIP, LSIF, LSP, or SemanticDB:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import { importExternalSemanticIndex } from '@shapeshift-labs/frontier-lang-compiler';
|
|
57
|
+
|
|
58
|
+
const importedIndex = importExternalSemanticIndex({
|
|
59
|
+
format: 'scip',
|
|
60
|
+
language: 'typescript',
|
|
61
|
+
payload: {
|
|
62
|
+
metadata: { project_root: '/repo' },
|
|
63
|
+
documents: [{
|
|
64
|
+
relative_path: 'src/todo.ts',
|
|
65
|
+
occurrences: [{
|
|
66
|
+
symbol: 'scip-typescript npm todo 1.0.0 src/todo.ts/ addTodo().',
|
|
67
|
+
range: [0, 16, 23],
|
|
68
|
+
symbol_roles: 1
|
|
69
|
+
}]
|
|
70
|
+
}]
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
console.log(importedIndex.semanticIndex.symbols.length);
|
|
75
|
+
console.log(importedIndex.summary.sourceMapMappings);
|
|
76
|
+
console.log(importedIndex.readiness.readiness); // "ready-with-losses" or review-required
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
External semantic-index imports create Frontier `SemanticIndexRecord`, `SourceMapRecord`, evidence, losses, ownership facts, and a universal AST envelope. They are a bridge from existing language servers/indexers into semantic merge tooling; they do not claim full parser AST coverage, macro expansion, type checking, comments/trivia preservation, or lossless cross-language code generation by themselves.
|
|
80
|
+
|
|
53
81
|
Native imports include source maps, semantic merge candidates, and a loss summary for admission queues and dashboards. Informational losses produce `ready-with-losses`, warning losses produce `needs-review`, and error losses or failed import evidence produce `blocked`:
|
|
54
82
|
|
|
55
83
|
```js
|
package/bench/smoke.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
createProjectionTargetLossMatrix,
|
|
8
8
|
createNativeSourcePreservation,
|
|
9
9
|
createSemanticImportSidecar,
|
|
10
|
+
importExternalSemanticIndex,
|
|
10
11
|
importNativeSource,
|
|
11
12
|
projectNativeImportToSource,
|
|
12
13
|
runNativeImporterAdapter,
|
|
@@ -134,6 +135,40 @@ const nativeTargetAdapterDurationMs = performance.now() - nativeTargetAdapterSta
|
|
|
134
135
|
const nativeTargetAdapterBytes = nativeTargetAdapterCompiles.reduce((sum, result) => sum + result.output.length, 0);
|
|
135
136
|
const nativeTargetAdapterSourceMaps = nativeTargetAdapterCompiles.reduce((sum, result) => sum + result.sourceMaps.length, 0);
|
|
136
137
|
|
|
138
|
+
const externalSemanticStart = performance.now();
|
|
139
|
+
const externalSemanticImports = [];
|
|
140
|
+
for (let index = 0; index < 100; index += 1) {
|
|
141
|
+
externalSemanticImports.push(importExternalSemanticIndex({
|
|
142
|
+
format: index % 2 === 0 ? 'scip' : 'lsp',
|
|
143
|
+
language: index % 2 === 0 ? 'typescript' : 'python',
|
|
144
|
+
payload: index % 2 === 0
|
|
145
|
+
? {
|
|
146
|
+
metadata: { project_root: '/bench' },
|
|
147
|
+
documents: [{
|
|
148
|
+
relative_path: `src/external-${index}.ts`,
|
|
149
|
+
language: 'typescript',
|
|
150
|
+
occurrences: [{
|
|
151
|
+
symbol: `scip-typescript npm bench 1.0.0 src/external-${index}.ts/ external${index}().`,
|
|
152
|
+
range: [0, 16, 24],
|
|
153
|
+
symbol_roles: 1
|
|
154
|
+
}]
|
|
155
|
+
}]
|
|
156
|
+
}
|
|
157
|
+
: {
|
|
158
|
+
uri: `file:///bench/src/external-${index}.py`,
|
|
159
|
+
languageId: 'python',
|
|
160
|
+
documentSymbols: [{
|
|
161
|
+
name: `external_${index}`,
|
|
162
|
+
kind: 12,
|
|
163
|
+
range: { start: { line: 0, character: 0 }, end: { line: 1, character: 0 } }
|
|
164
|
+
}]
|
|
165
|
+
}
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
const externalSemanticDurationMs = performance.now() - externalSemanticStart;
|
|
169
|
+
const externalSemanticSymbols = externalSemanticImports.reduce((sum, imported) => sum + imported.semanticIndex.symbols.length, 0);
|
|
170
|
+
const externalSemanticMappings = externalSemanticImports.reduce((sum, imported) => sum + imported.summary.sourceMapMappings, 0);
|
|
171
|
+
|
|
137
172
|
console.log(JSON.stringify({
|
|
138
173
|
compiles: 250,
|
|
139
174
|
bytes,
|
|
@@ -172,5 +207,9 @@ console.log(JSON.stringify({
|
|
|
172
207
|
nativeTargetAdapterCompiles: nativeTargetAdapterCompiles.length,
|
|
173
208
|
nativeTargetAdapterBytes,
|
|
174
209
|
nativeTargetAdapterSourceMaps,
|
|
175
|
-
nativeTargetAdapterDurationMs: Number(nativeTargetAdapterDurationMs.toFixed(2))
|
|
210
|
+
nativeTargetAdapterDurationMs: Number(nativeTargetAdapterDurationMs.toFixed(2)),
|
|
211
|
+
externalSemanticImports: externalSemanticImports.length,
|
|
212
|
+
externalSemanticSymbols,
|
|
213
|
+
externalSemanticMappings,
|
|
214
|
+
externalSemanticDurationMs: Number(externalSemanticDurationMs.toFixed(2))
|
|
176
215
|
}));
|
package/dist/index.d.ts
CHANGED
|
@@ -1067,6 +1067,63 @@ export type NativeSourceImportResult = LanguageImportResult & {
|
|
|
1067
1067
|
readonly universalAst: FrontierUniversalAstEnvelope;
|
|
1068
1068
|
};
|
|
1069
1069
|
|
|
1070
|
+
export type ExternalSemanticIndexFormat =
|
|
1071
|
+
| 'frontier-semantic-index'
|
|
1072
|
+
| 'scip'
|
|
1073
|
+
| 'lsif'
|
|
1074
|
+
| 'lsp'
|
|
1075
|
+
| 'semanticdb'
|
|
1076
|
+
| string;
|
|
1077
|
+
|
|
1078
|
+
export interface ImportExternalSemanticIndexOptions {
|
|
1079
|
+
readonly format?: ExternalSemanticIndexFormat;
|
|
1080
|
+
readonly payload?: unknown;
|
|
1081
|
+
readonly semanticIndex?: SemanticIndexRecord;
|
|
1082
|
+
readonly id?: string;
|
|
1083
|
+
readonly semanticIndexId?: string;
|
|
1084
|
+
readonly universalAstId?: string;
|
|
1085
|
+
readonly documentId?: string;
|
|
1086
|
+
readonly documentName?: string;
|
|
1087
|
+
readonly sourceMapId?: string;
|
|
1088
|
+
readonly language?: FrontierSourceLanguage | string;
|
|
1089
|
+
readonly sourcePath?: string;
|
|
1090
|
+
readonly sourceHash?: string;
|
|
1091
|
+
readonly projectRoot?: string;
|
|
1092
|
+
readonly parser?: string;
|
|
1093
|
+
readonly evidence?: readonly EvidenceRecord[];
|
|
1094
|
+
readonly metadata?: Record<string, unknown>;
|
|
1095
|
+
readonly universalAstMetadata?: Record<string, unknown>;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
export interface ExternalSemanticIndexImportSummary {
|
|
1099
|
+
readonly documents: number;
|
|
1100
|
+
readonly symbols: number;
|
|
1101
|
+
readonly occurrences: number;
|
|
1102
|
+
readonly relations: number;
|
|
1103
|
+
readonly facts: number;
|
|
1104
|
+
readonly sourceMapMappings: number;
|
|
1105
|
+
readonly losses: number;
|
|
1106
|
+
readonly readiness: SemanticMergeReadiness;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
export interface ExternalSemanticIndexImportResult {
|
|
1110
|
+
readonly kind: 'frontier.lang.externalSemanticIndexImport';
|
|
1111
|
+
readonly version: 1;
|
|
1112
|
+
readonly id: string;
|
|
1113
|
+
readonly format: ExternalSemanticIndexFormat;
|
|
1114
|
+
readonly language?: FrontierSourceLanguage | string;
|
|
1115
|
+
readonly sourcePath?: string;
|
|
1116
|
+
readonly projectRoot?: string;
|
|
1117
|
+
readonly semanticIndex: SemanticIndexRecord;
|
|
1118
|
+
readonly universalAst: FrontierUniversalAstEnvelope;
|
|
1119
|
+
readonly sourceMaps: readonly SourceMapRecord[];
|
|
1120
|
+
readonly losses: readonly NativeAstLossRecord[];
|
|
1121
|
+
readonly evidence: readonly EvidenceRecord[];
|
|
1122
|
+
readonly readiness: NativeImportReadinessClassification;
|
|
1123
|
+
readonly summary: ExternalSemanticIndexImportSummary;
|
|
1124
|
+
readonly metadata: Record<string, unknown>;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1070
1127
|
export interface NativeImporterAdapterParseInput {
|
|
1071
1128
|
readonly sourceText: string;
|
|
1072
1129
|
readonly sourcePath?: string;
|
|
@@ -1474,6 +1531,7 @@ export declare const ProjectionTargetLossClasses: readonly ProjectionTargetLossC
|
|
|
1474
1531
|
export declare const NativeImportReadinessBySeverity: Readonly<Record<NativeImportLossSummary['highestSeverity'], SemanticMergeReadiness>>;
|
|
1475
1532
|
export declare const NativeImportFeatureEvidencePolicies: Readonly<Record<string, NativeImportFeatureEvidencePolicy>>;
|
|
1476
1533
|
export declare const NativeImportLanguageProfiles: readonly NativeImportLanguageProfile[];
|
|
1534
|
+
export declare const ExternalSemanticIndexFormats: readonly ExternalSemanticIndexFormat[];
|
|
1477
1535
|
export declare function normalizeCompileTarget(target?: string): FrontierCompileTarget;
|
|
1478
1536
|
export declare function compileFrontierSource(source: string, options?: FrontierCompileOptions): FrontierCompileResult;
|
|
1479
1537
|
export declare function compileFrontierDocument(document: FrontierLangDocument, options?: FrontierCompileOptions): FrontierCompileResult;
|
|
@@ -1500,6 +1558,7 @@ export declare function createTreeSitterNativeImporterAdapter(options?: TreeSitt
|
|
|
1500
1558
|
export declare function runNativeImporterAdapter(adapter: NativeImporterAdapter, input: RunNativeImporterAdapterOptions): Promise<NativeImporterAdapterImportResult>;
|
|
1501
1559
|
export declare function runNativeTargetProjectionAdapter(adapter: NativeTargetProjectionAdapter, input: NativeTargetProjectionAdapterInput): NativeTargetProjectionResult;
|
|
1502
1560
|
export declare function projectNativeImportToSource(importResult: NativeSourceImportResult | NativeProjectImportResult, options?: ProjectNativeImportToSourceOptions): NativeSourceProjectionResult;
|
|
1561
|
+
export declare function importExternalSemanticIndex(input: ImportExternalSemanticIndexOptions | SemanticIndexRecord): ExternalSemanticIndexImportResult;
|
|
1503
1562
|
export declare function importNativeSource(input: ImportNativeSourceOptions): NativeSourceImportResult;
|
|
1504
1563
|
export declare function diffNativeSources(input: DiffNativeSourcesOptions): NativeSourceChangeSet;
|
|
1505
1564
|
export declare function diffNativeSourceImports(input: DiffNativeSourceImportsOptions): NativeSourceChangeSet;
|