@shapeshift-labs/frontier-lang-compiler 0.2.82 → 0.2.84
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.
|
@@ -123,6 +123,20 @@ export interface SemanticEditScript {
|
|
|
123
123
|
export interface SemanticEditProjectionEdit {
|
|
124
124
|
readonly operationId?: string;
|
|
125
125
|
readonly status: 'applied' | 'already-applied';
|
|
126
|
+
readonly kind?: string;
|
|
127
|
+
readonly changeKind?: string;
|
|
128
|
+
readonly anchorKey?: string;
|
|
129
|
+
readonly conflictKey?: string;
|
|
130
|
+
readonly regionId?: string;
|
|
131
|
+
readonly regionKind?: string;
|
|
132
|
+
readonly sourcePath?: string;
|
|
133
|
+
readonly symbolId?: string;
|
|
134
|
+
readonly symbolName?: string;
|
|
135
|
+
readonly symbolKind?: string;
|
|
136
|
+
readonly semanticKey?: string;
|
|
137
|
+
readonly semanticIdentityHash?: string;
|
|
138
|
+
readonly sourceIdentityHash?: string;
|
|
139
|
+
readonly editContentHash?: string;
|
|
126
140
|
readonly headStart: number;
|
|
127
141
|
readonly headEnd: number;
|
|
128
142
|
readonly workerStart?: number;
|
|
@@ -54,7 +54,7 @@ export function projectSemanticEditScriptToSource(input = {}) {
|
|
|
54
54
|
|
|
55
55
|
function sourceEditForOperation(operation, workerSourceText, headSourceText) {
|
|
56
56
|
if (operation.status === 'already-applied') {
|
|
57
|
-
return { ok: true, value: { operationId: operation.id, start: 0, end: 0, replacement: '', current: '', alreadyApplied: true } };
|
|
57
|
+
return { ok: true, value: { ...semanticEditIdentity(operation), operationId: operation.id, start: 0, end: 0, replacement: '', current: '', alreadyApplied: true } };
|
|
58
58
|
}
|
|
59
59
|
if (operation.status !== 'portable') return { ok: false, reasonCodes: [`operation-not-portable:${operation.id}`] };
|
|
60
60
|
const workerOffsets = spanOffsets(workerSourceText, operation.spans?.worker);
|
|
@@ -77,6 +77,7 @@ function sourceEditForOperation(operation, workerSourceText, headSourceText) {
|
|
|
77
77
|
ok: true,
|
|
78
78
|
value: {
|
|
79
79
|
operationId: operation.id,
|
|
80
|
+
...semanticEditIdentity(operation),
|
|
80
81
|
start: headOffsets.start,
|
|
81
82
|
end: headOffsets.end,
|
|
82
83
|
workerStart: workerOffsets.start,
|
|
@@ -88,21 +89,90 @@ function sourceEditForOperation(operation, workerSourceText, headSourceText) {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
function projectionEditRecord(edit) {
|
|
92
|
+
const deletedTextHash = hashSemanticValue(edit.current);
|
|
93
|
+
const replacementTextHash = hashSemanticValue(edit.replacement);
|
|
94
|
+
const semanticKey = semanticEditKey(edit);
|
|
95
|
+
const semanticIdentityHash = hashSemanticValue(semanticIdentityRecord(edit, semanticKey));
|
|
96
|
+
const sourceIdentityHash = hashSemanticValue(sourceIdentityRecord(edit));
|
|
91
97
|
return compactRecord({
|
|
92
98
|
operationId: edit.operationId,
|
|
93
99
|
status: edit.alreadyApplied ? 'already-applied' : 'applied',
|
|
100
|
+
kind: edit.kind,
|
|
101
|
+
changeKind: edit.changeKind,
|
|
102
|
+
anchorKey: edit.anchorKey,
|
|
103
|
+
conflictKey: edit.conflictKey,
|
|
104
|
+
regionId: edit.regionId,
|
|
105
|
+
regionKind: edit.regionKind,
|
|
106
|
+
sourcePath: edit.sourcePath,
|
|
107
|
+
symbolId: edit.symbolId,
|
|
108
|
+
symbolName: edit.symbolName,
|
|
109
|
+
symbolKind: edit.symbolKind,
|
|
110
|
+
semanticKey,
|
|
111
|
+
semanticIdentityHash,
|
|
112
|
+
sourceIdentityHash,
|
|
113
|
+
editContentHash: hashSemanticValue(compactRecord({
|
|
114
|
+
semanticIdentityHash,
|
|
115
|
+
deletedTextHash,
|
|
116
|
+
replacementTextHash,
|
|
117
|
+
status: edit.alreadyApplied ? 'already-applied' : 'applied'
|
|
118
|
+
})),
|
|
94
119
|
headStart: edit.start,
|
|
95
120
|
headEnd: edit.end,
|
|
96
121
|
workerStart: edit.workerStart,
|
|
97
122
|
workerEnd: edit.workerEnd,
|
|
98
123
|
deletedBytes: edit.current.length,
|
|
99
124
|
replacementBytes: edit.replacement.length,
|
|
100
|
-
deletedTextHash
|
|
101
|
-
replacementTextHash
|
|
125
|
+
deletedTextHash,
|
|
126
|
+
replacementTextHash,
|
|
102
127
|
replacementText: edit.replacement
|
|
103
128
|
});
|
|
104
129
|
}
|
|
105
130
|
|
|
131
|
+
function semanticEditKey(edit) {
|
|
132
|
+
const scope = edit.symbolName
|
|
133
|
+
? `${edit.symbolKind ?? 'symbol'}:${edit.symbolName}`
|
|
134
|
+
: edit.anchorKey ?? edit.regionId ?? edit.operationId;
|
|
135
|
+
return ['semantic-edit', edit.kind ?? 'region', edit.changeKind ?? 'change', scope].filter(Boolean).join(':');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function semanticIdentityRecord(edit, semanticKey) {
|
|
139
|
+
return compactRecord({
|
|
140
|
+
semanticKey,
|
|
141
|
+
kind: edit.kind,
|
|
142
|
+
changeKind: edit.changeKind,
|
|
143
|
+
regionKind: edit.regionKind,
|
|
144
|
+
symbolName: edit.symbolName,
|
|
145
|
+
symbolKind: edit.symbolKind
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function sourceIdentityRecord(edit) {
|
|
150
|
+
return compactRecord({
|
|
151
|
+
anchorKey: edit.anchorKey,
|
|
152
|
+
conflictKey: edit.conflictKey,
|
|
153
|
+
regionId: edit.regionId,
|
|
154
|
+
sourcePath: edit.sourcePath,
|
|
155
|
+
symbolId: edit.symbolId,
|
|
156
|
+
semanticKey: semanticEditKey(edit)
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function semanticEditIdentity(operation) {
|
|
161
|
+
const anchor = operation.anchor ?? {};
|
|
162
|
+
return compactRecord({
|
|
163
|
+
kind: operation.kind,
|
|
164
|
+
changeKind: operation.changeKind,
|
|
165
|
+
anchorKey: anchor.key,
|
|
166
|
+
conflictKey: anchor.conflictKey,
|
|
167
|
+
regionId: anchor.regionId,
|
|
168
|
+
regionKind: anchor.regionKind,
|
|
169
|
+
sourcePath: anchor.sourcePath,
|
|
170
|
+
symbolId: anchor.symbolId,
|
|
171
|
+
symbolName: anchor.symbolName,
|
|
172
|
+
symbolKind: anchor.symbolKind
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
106
176
|
function applySourceEdits(sourceText, edits) {
|
|
107
177
|
return edits.filter((edit) => !edit.alreadyApplied)
|
|
108
178
|
.sort((left, right) => right.start - left.start)
|
package/package.json
CHANGED