@boperators/plugin-ts-language-server 0.1.4 → 0.2.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/dist/SourceMap.js +4 -96
- package/dist/index.js +5 -2
- package/package.json +6 -3
package/dist/SourceMap.js
CHANGED
|
@@ -4,12 +4,12 @@ exports.SourceMap = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* Bidirectional position mapping between original and transformed source text.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Wraps pre-computed edit records and provides O(edits) position and span
|
|
8
|
+
* mapping in both directions, for use by the language service proxy.
|
|
9
9
|
*/
|
|
10
10
|
class SourceMap {
|
|
11
|
-
constructor(
|
|
12
|
-
this.edits =
|
|
11
|
+
constructor(edits) {
|
|
12
|
+
this.edits = edits;
|
|
13
13
|
}
|
|
14
14
|
/** Returns true if no edits were detected (original === transformed). */
|
|
15
15
|
get isEmpty() {
|
|
@@ -20,14 +20,11 @@ class SourceMap {
|
|
|
20
20
|
let delta = 0;
|
|
21
21
|
for (const edit of this.edits) {
|
|
22
22
|
if (pos < edit.origStart) {
|
|
23
|
-
// Before this edit — just apply accumulated delta
|
|
24
23
|
break;
|
|
25
24
|
}
|
|
26
25
|
if (pos < edit.origEnd) {
|
|
27
|
-
// Inside an edited region — map to start of the transformed replacement
|
|
28
26
|
return edit.transStart;
|
|
29
27
|
}
|
|
30
|
-
// Past this edit — accumulate the delta
|
|
31
28
|
delta = edit.transEnd - edit.origEnd;
|
|
32
29
|
}
|
|
33
30
|
return pos + delta;
|
|
@@ -40,7 +37,6 @@ class SourceMap {
|
|
|
40
37
|
break;
|
|
41
38
|
}
|
|
42
39
|
if (pos < edit.transEnd) {
|
|
43
|
-
// Inside a transformed region — map to start of the original span
|
|
44
40
|
return edit.origStart;
|
|
45
41
|
}
|
|
46
42
|
delta = edit.origEnd - edit.transEnd;
|
|
@@ -78,91 +74,3 @@ class SourceMap {
|
|
|
78
74
|
}
|
|
79
75
|
}
|
|
80
76
|
exports.SourceMap = SourceMap;
|
|
81
|
-
/**
|
|
82
|
-
* Compute edit records by scanning both texts for mismatches.
|
|
83
|
-
*
|
|
84
|
-
* Uses character-level comparison with anchor-based convergence:
|
|
85
|
-
* identical characters are skipped, mismatches start an edit region,
|
|
86
|
-
* and convergence is found by searching for a matching anchor substring
|
|
87
|
-
* in the remaining text.
|
|
88
|
-
*/
|
|
89
|
-
function computeEdits(original, transformed) {
|
|
90
|
-
if (original === transformed)
|
|
91
|
-
return [];
|
|
92
|
-
const edits = [];
|
|
93
|
-
let i = 0; // index in original
|
|
94
|
-
let j = 0; // index in transformed
|
|
95
|
-
while (i < original.length && j < transformed.length) {
|
|
96
|
-
// Skip matching characters
|
|
97
|
-
if (original[i] === transformed[j]) {
|
|
98
|
-
i++;
|
|
99
|
-
j++;
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
// Mismatch — start of an edit
|
|
103
|
-
const origEditStart = i;
|
|
104
|
-
const transEditStart = j;
|
|
105
|
-
// Find where the texts converge again.
|
|
106
|
-
// Search for an anchor: a substring from `original` that also
|
|
107
|
-
// appears at the corresponding position in `transformed`.
|
|
108
|
-
const ANCHOR_LEN = 8;
|
|
109
|
-
let found = false;
|
|
110
|
-
// Scan ahead in original from the mismatch point
|
|
111
|
-
for (let oi = origEditStart + 1; oi <= original.length - ANCHOR_LEN; oi++) {
|
|
112
|
-
const anchor = original.substring(oi, oi + ANCHOR_LEN);
|
|
113
|
-
const transPos = transformed.indexOf(anchor, transEditStart);
|
|
114
|
-
if (transPos >= 0) {
|
|
115
|
-
// Verify the anchor actually converges by checking a few more chars
|
|
116
|
-
let valid = true;
|
|
117
|
-
const verifyLen = Math.min(ANCHOR_LEN * 2, original.length - oi, transformed.length - transPos);
|
|
118
|
-
for (let k = ANCHOR_LEN; k < verifyLen; k++) {
|
|
119
|
-
if (original[oi + k] !== transformed[transPos + k]) {
|
|
120
|
-
valid = false;
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (valid) {
|
|
125
|
-
edits.push({
|
|
126
|
-
origStart: origEditStart,
|
|
127
|
-
origEnd: oi,
|
|
128
|
-
transStart: transEditStart,
|
|
129
|
-
transEnd: transPos,
|
|
130
|
-
});
|
|
131
|
-
i = oi;
|
|
132
|
-
j = transPos;
|
|
133
|
-
found = true;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (!found) {
|
|
139
|
-
// No convergence — remaining text is all part of the edit.
|
|
140
|
-
// Use common suffix to tighten the bounds.
|
|
141
|
-
let suffixLen = 0;
|
|
142
|
-
while (suffixLen < original.length - origEditStart &&
|
|
143
|
-
suffixLen < transformed.length - transEditStart &&
|
|
144
|
-
original[original.length - 1 - suffixLen] ===
|
|
145
|
-
transformed[transformed.length - 1 - suffixLen]) {
|
|
146
|
-
suffixLen++;
|
|
147
|
-
}
|
|
148
|
-
edits.push({
|
|
149
|
-
origStart: origEditStart,
|
|
150
|
-
origEnd: original.length - suffixLen,
|
|
151
|
-
transStart: transEditStart,
|
|
152
|
-
transEnd: transformed.length - suffixLen,
|
|
153
|
-
});
|
|
154
|
-
i = original.length;
|
|
155
|
-
j = transformed.length;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
// Handle remaining text at the end
|
|
159
|
-
if (i < original.length || j < transformed.length) {
|
|
160
|
-
edits.push({
|
|
161
|
-
origStart: i,
|
|
162
|
-
origEnd: original.length,
|
|
163
|
-
transStart: j,
|
|
164
|
-
transEnd: transformed.length,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
return edits;
|
|
168
|
-
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const boperators_1 = require("boperators");
|
|
3
|
+
const SourceMap_1 = require("./SourceMap");
|
|
3
4
|
// ----- Overload edit scanner -----
|
|
4
5
|
/**
|
|
5
6
|
* Before transformation, find all expressions (binary, prefix unary, postfix unary)
|
|
@@ -306,6 +307,7 @@ function createProxy(ts, ls, cache, project) {
|
|
|
306
307
|
// Copy all methods from the underlying language service
|
|
307
308
|
const proxy = Object.create(null);
|
|
308
309
|
for (const key of Object.keys(ls)) {
|
|
310
|
+
// biome-ignore lint/suspicious/noExplicitAny: <TODO: fix this>
|
|
309
311
|
proxy[key] = ls[key];
|
|
310
312
|
}
|
|
311
313
|
// --- Diagnostics: remap output spans + suppress overload errors ---
|
|
@@ -570,6 +572,7 @@ function createProxy(ts, ls, cache, project) {
|
|
|
570
572
|
const transformedPos = sourceMap
|
|
571
573
|
? sourceMap.originalToTransformed(position)
|
|
572
574
|
: position;
|
|
575
|
+
// biome-ignore lint/complexity/noBannedTypes: <TODO: fix this>
|
|
573
576
|
const result = ls.findRenameLocations(fileName, transformedPos, findInStrings, findInComments, preferences);
|
|
574
577
|
if (!result)
|
|
575
578
|
return result;
|
|
@@ -669,7 +672,7 @@ module.exports = function init(modules) {
|
|
|
669
672
|
cache.set(fileName, {
|
|
670
673
|
version,
|
|
671
674
|
text: result.text,
|
|
672
|
-
sourceMap: result.
|
|
675
|
+
sourceMap: new SourceMap_1.SourceMap(result.edits),
|
|
673
676
|
overloadEdits,
|
|
674
677
|
});
|
|
675
678
|
return ts.ScriptSnapshot.fromString(result.text);
|
|
@@ -679,7 +682,7 @@ module.exports = function init(modules) {
|
|
|
679
682
|
cache.set(fileName, {
|
|
680
683
|
version,
|
|
681
684
|
text: source,
|
|
682
|
-
sourceMap: new
|
|
685
|
+
sourceMap: new SourceMap_1.SourceMap([]),
|
|
683
686
|
overloadEdits: [],
|
|
684
687
|
});
|
|
685
688
|
return snap;
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boperators/plugin-ts-language-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "TypeScript Language Server plugin for boperators - IDE support with source mapping.",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/DiefBell/boperators",
|
|
8
|
+
"url": "git+https://github.com/DiefBell/boperators.git",
|
|
9
9
|
"directory": "plugins/ts-language-server"
|
|
10
10
|
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/DiefBell/boperators/issues"
|
|
13
|
+
},
|
|
11
14
|
"homepage": "https://github.com/DiefBell/boperators/tree/main/plugins/ts-language-server",
|
|
12
15
|
"type": "commonjs",
|
|
13
16
|
"main": "./dist/index.js",
|
|
@@ -33,7 +36,7 @@
|
|
|
33
36
|
"dist"
|
|
34
37
|
],
|
|
35
38
|
"peerDependencies": {
|
|
36
|
-
"boperators": "0.
|
|
39
|
+
"boperators": "0.2.0",
|
|
37
40
|
"typescript": ">=5.0.0 <5.10.0"
|
|
38
41
|
},
|
|
39
42
|
"devDependencies": {
|