@kroy665/code-editor-engine 1.0.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/README.md +127 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/__tests__/editor.spec.d.ts +2 -0
- package/dist/__tests__/editor.spec.d.ts.map +1 -0
- package/dist/__tests__/editor.spec.js +141 -0
- package/dist/__tests__/editor.spec.js.map +1 -0
- package/dist/core/CodeEditor.d.ts +70 -0
- package/dist/core/CodeEditor.d.ts.map +1 -0
- package/dist/core/CodeEditor.js +392 -0
- package/dist/core/CodeEditor.js.map +1 -0
- package/dist/core/CommandSystem.d.ts +158 -0
- package/dist/core/CommandSystem.d.ts.map +1 -0
- package/dist/core/CommandSystem.js +358 -0
- package/dist/core/CommandSystem.js.map +1 -0
- package/dist/core/EventSystem.d.ts +87 -0
- package/dist/core/EventSystem.d.ts.map +1 -0
- package/dist/core/EventSystem.js +330 -0
- package/dist/core/EventSystem.js.map +1 -0
- package/dist/core/TextDocument.d.ts +110 -0
- package/dist/core/TextDocument.d.ts.map +1 -0
- package/dist/core/TextDocument.js +340 -0
- package/dist/core/TextDocument.js.map +1 -0
- package/dist/index.d.ts +178 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +302 -0
- package/dist/index.js.map +1 -0
- package/dist/language/Extensions.d.ts +280 -0
- package/dist/language/Extensions.d.ts.map +1 -0
- package/dist/language/Extensions.js +368 -0
- package/dist/language/Extensions.js.map +1 -0
- package/dist/language/Tokenizer.d.ts +108 -0
- package/dist/language/Tokenizer.d.ts.map +1 -0
- package/dist/language/Tokenizer.js +630 -0
- package/dist/language/Tokenizer.js.map +1 -0
- package/dist/types/core.d.ts +355 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +93 -0
- package/dist/types/core.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsyncEventEmitter = exports.PriorityEventEmitter = exports.TypedEventEmitter = exports.CompositeDisposable = exports.DisposableImpl = void 0;
|
|
4
|
+
exports.combineDisposables = combineDisposables;
|
|
5
|
+
exports.createDisposable = createDisposable;
|
|
6
|
+
/**
|
|
7
|
+
* Disposable implementation for cleanup
|
|
8
|
+
*/
|
|
9
|
+
class DisposableImpl {
|
|
10
|
+
constructor(cleanupFn) {
|
|
11
|
+
this.isDisposed = false;
|
|
12
|
+
this.cleanupFn = cleanupFn;
|
|
13
|
+
}
|
|
14
|
+
dispose() {
|
|
15
|
+
if (!this.isDisposed) {
|
|
16
|
+
this.isDisposed = true;
|
|
17
|
+
this.cleanupFn();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
get disposed() {
|
|
21
|
+
return this.isDisposed;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.DisposableImpl = DisposableImpl;
|
|
25
|
+
/**
|
|
26
|
+
* Composite disposable for managing multiple disposables
|
|
27
|
+
*/
|
|
28
|
+
class CompositeDisposable {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.disposables = [];
|
|
31
|
+
this.isDisposed = false;
|
|
32
|
+
}
|
|
33
|
+
add(disposable) {
|
|
34
|
+
if (this.isDisposed) {
|
|
35
|
+
disposable.dispose();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.disposables.push(disposable);
|
|
39
|
+
}
|
|
40
|
+
remove(disposable) {
|
|
41
|
+
const index = this.disposables.indexOf(disposable);
|
|
42
|
+
if (index >= 0) {
|
|
43
|
+
this.disposables.splice(index, 1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
dispose() {
|
|
47
|
+
if (!this.isDisposed) {
|
|
48
|
+
this.isDisposed = true;
|
|
49
|
+
for (const disposable of this.disposables) {
|
|
50
|
+
try {
|
|
51
|
+
disposable.dispose();
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('Error disposing resource:', error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
this.disposables.length = 0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
get disposed() {
|
|
61
|
+
return this.isDisposed;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.CompositeDisposable = CompositeDisposable;
|
|
65
|
+
/**
|
|
66
|
+
* Typed event emitter implementation with memory management
|
|
67
|
+
*/
|
|
68
|
+
class TypedEventEmitter {
|
|
69
|
+
constructor() {
|
|
70
|
+
this.listeners = new Map();
|
|
71
|
+
this.onceListeners = new Map();
|
|
72
|
+
this.isDisposed = false;
|
|
73
|
+
}
|
|
74
|
+
on(event, listener) {
|
|
75
|
+
if (this.isDisposed) {
|
|
76
|
+
throw new Error('EventEmitter has been disposed');
|
|
77
|
+
}
|
|
78
|
+
if (!this.listeners.has(event)) {
|
|
79
|
+
this.listeners.set(event, new Set());
|
|
80
|
+
}
|
|
81
|
+
this.listeners.get(event).add(listener);
|
|
82
|
+
return new DisposableImpl(() => {
|
|
83
|
+
this.off(event, listener);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
off(event, listener) {
|
|
87
|
+
const listeners = this.listeners.get(event);
|
|
88
|
+
if (listeners) {
|
|
89
|
+
listeners.delete(listener);
|
|
90
|
+
if (listeners.size === 0) {
|
|
91
|
+
this.listeners.delete(event);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const onceListeners = this.onceListeners.get(event);
|
|
95
|
+
if (onceListeners) {
|
|
96
|
+
onceListeners.delete(listener);
|
|
97
|
+
if (onceListeners.size === 0) {
|
|
98
|
+
this.onceListeners.delete(event);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
once(event, listener) {
|
|
103
|
+
if (this.isDisposed) {
|
|
104
|
+
throw new Error('EventEmitter has been disposed');
|
|
105
|
+
}
|
|
106
|
+
if (!this.onceListeners.has(event)) {
|
|
107
|
+
this.onceListeners.set(event, new Set());
|
|
108
|
+
}
|
|
109
|
+
this.onceListeners.get(event).add(listener);
|
|
110
|
+
return new DisposableImpl(() => {
|
|
111
|
+
this.off(event, listener);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
emit(event, data) {
|
|
115
|
+
if (this.isDisposed) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// Emit to regular listeners
|
|
119
|
+
const listeners = this.listeners.get(event);
|
|
120
|
+
if (listeners) {
|
|
121
|
+
for (const listener of [...listeners]) {
|
|
122
|
+
// Copy to prevent modification during iteration
|
|
123
|
+
try {
|
|
124
|
+
listener(data);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error(`Error in event listener for ${String(event)}:`, error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Emit to once listeners and remove them
|
|
132
|
+
const onceListeners = this.onceListeners.get(event);
|
|
133
|
+
if (onceListeners) {
|
|
134
|
+
for (const listener of [...onceListeners]) {
|
|
135
|
+
try {
|
|
136
|
+
listener(data);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
console.error(`Error in once event listener for ${String(event)}:`, error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
this.onceListeners.delete(event);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get the number of listeners for an event
|
|
147
|
+
*/
|
|
148
|
+
listenerCount(event) {
|
|
149
|
+
const regularCount = this.listeners.get(event)?.size || 0;
|
|
150
|
+
const onceCount = this.onceListeners.get(event)?.size || 0;
|
|
151
|
+
return regularCount + onceCount;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get all events that have listeners
|
|
155
|
+
*/
|
|
156
|
+
eventNames() {
|
|
157
|
+
const events = new Set();
|
|
158
|
+
for (const event of this.listeners.keys()) {
|
|
159
|
+
events.add(event);
|
|
160
|
+
}
|
|
161
|
+
for (const event of this.onceListeners.keys()) {
|
|
162
|
+
events.add(event);
|
|
163
|
+
}
|
|
164
|
+
return Array.from(events);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Remove all listeners for all events
|
|
168
|
+
*/
|
|
169
|
+
removeAllListeners() {
|
|
170
|
+
this.listeners.clear();
|
|
171
|
+
this.onceListeners.clear();
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Remove all listeners for a specific event
|
|
175
|
+
*/
|
|
176
|
+
removeAllListenersForEvent(event) {
|
|
177
|
+
this.listeners.delete(event);
|
|
178
|
+
this.onceListeners.delete(event);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Dispose the event emitter and clean up all listeners
|
|
182
|
+
*/
|
|
183
|
+
dispose() {
|
|
184
|
+
if (!this.isDisposed) {
|
|
185
|
+
this.isDisposed = true;
|
|
186
|
+
this.removeAllListeners();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
get disposed() {
|
|
190
|
+
return this.isDisposed;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.TypedEventEmitter = TypedEventEmitter;
|
|
194
|
+
/**
|
|
195
|
+
* Event emitter that supports priorities
|
|
196
|
+
*/
|
|
197
|
+
class PriorityEventEmitter extends TypedEventEmitter {
|
|
198
|
+
constructor() {
|
|
199
|
+
super(...arguments);
|
|
200
|
+
this.priorityListeners = new Map();
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Add a listener with priority (higher numbers = higher priority)
|
|
204
|
+
*/
|
|
205
|
+
onWithPriority(event, listener, priority = 0) {
|
|
206
|
+
if (!this.priorityListeners.has(event)) {
|
|
207
|
+
this.priorityListeners.set(event, new Map());
|
|
208
|
+
}
|
|
209
|
+
const eventPriorities = this.priorityListeners.get(event);
|
|
210
|
+
if (!eventPriorities.has(priority)) {
|
|
211
|
+
eventPriorities.set(priority, new Set());
|
|
212
|
+
}
|
|
213
|
+
eventPriorities.get(priority).add(listener);
|
|
214
|
+
return new DisposableImpl(() => {
|
|
215
|
+
this.offWithPriority(event, listener, priority);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
offWithPriority(event, listener, priority) {
|
|
219
|
+
const eventPriorities = this.priorityListeners.get(event);
|
|
220
|
+
if (!eventPriorities)
|
|
221
|
+
return;
|
|
222
|
+
const prioritySet = eventPriorities.get(priority);
|
|
223
|
+
if (!prioritySet)
|
|
224
|
+
return;
|
|
225
|
+
prioritySet.delete(listener);
|
|
226
|
+
if (prioritySet.size === 0) {
|
|
227
|
+
eventPriorities.delete(priority);
|
|
228
|
+
if (eventPriorities.size === 0) {
|
|
229
|
+
this.priorityListeners.delete(event);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
emit(event, data) {
|
|
234
|
+
if (this.disposed) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
// Emit to priority listeners first (highest priority first)
|
|
238
|
+
const eventPriorities = this.priorityListeners.get(event);
|
|
239
|
+
if (eventPriorities) {
|
|
240
|
+
const sortedPriorities = Array.from(eventPriorities.keys()).sort((a, b) => b - a);
|
|
241
|
+
for (const priority of sortedPriorities) {
|
|
242
|
+
const listeners = eventPriorities.get(priority);
|
|
243
|
+
for (const listener of [...listeners]) {
|
|
244
|
+
try {
|
|
245
|
+
listener(data);
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
console.error(`Error in priority event listener for ${String(event)} (priority ${priority}):`, error);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// Then emit to regular listeners
|
|
254
|
+
super.emit(event, data);
|
|
255
|
+
}
|
|
256
|
+
removeAllListeners() {
|
|
257
|
+
super.removeAllListeners();
|
|
258
|
+
this.priorityListeners.clear();
|
|
259
|
+
}
|
|
260
|
+
removeAllListenersForEvent(event) {
|
|
261
|
+
super.removeAllListenersForEvent(event);
|
|
262
|
+
this.priorityListeners.delete(event);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
exports.PriorityEventEmitter = PriorityEventEmitter;
|
|
266
|
+
/**
|
|
267
|
+
* Async event emitter for handling asynchronous event listeners
|
|
268
|
+
*/
|
|
269
|
+
class AsyncEventEmitter extends TypedEventEmitter {
|
|
270
|
+
/**
|
|
271
|
+
* Emit event and wait for all listeners to complete
|
|
272
|
+
*/
|
|
273
|
+
async emitAsync(event, data) {
|
|
274
|
+
if (this.disposed) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const promises = [];
|
|
278
|
+
// Handle regular listeners
|
|
279
|
+
const listeners = this.listeners.get(event);
|
|
280
|
+
if (listeners) {
|
|
281
|
+
for (const listener of [...listeners]) {
|
|
282
|
+
try {
|
|
283
|
+
const result = listener(data);
|
|
284
|
+
if (result && typeof result.then === 'function') {
|
|
285
|
+
promises.push(result);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
console.error(`Error in async event listener for ${String(event)}:`, error);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
// Handle once listeners
|
|
294
|
+
const onceListeners = this.onceListeners.get(event);
|
|
295
|
+
if (onceListeners) {
|
|
296
|
+
for (const listener of [...onceListeners]) {
|
|
297
|
+
try {
|
|
298
|
+
const result = listener(data);
|
|
299
|
+
if (result && typeof result.then === 'function') {
|
|
300
|
+
promises.push(result);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
console.error(`Error in async once event listener for ${String(event)}:`, error);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
this.onceListeners.delete(event);
|
|
308
|
+
}
|
|
309
|
+
// Wait for all async listeners to complete
|
|
310
|
+
await Promise.allSettled(promises);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
exports.AsyncEventEmitter = AsyncEventEmitter;
|
|
314
|
+
/**
|
|
315
|
+
* Utility function to create a disposable from multiple disposables
|
|
316
|
+
*/
|
|
317
|
+
function combineDisposables(...disposables) {
|
|
318
|
+
const composite = new CompositeDisposable();
|
|
319
|
+
for (const disposable of disposables) {
|
|
320
|
+
composite.add(disposable);
|
|
321
|
+
}
|
|
322
|
+
return composite;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Utility function to create a disposable from a cleanup function
|
|
326
|
+
*/
|
|
327
|
+
function createDisposable(cleanupFn) {
|
|
328
|
+
return new DisposableImpl(cleanupFn);
|
|
329
|
+
}
|
|
330
|
+
//# sourceMappingURL=EventSystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventSystem.js","sourceRoot":"","sources":["../../src/core/EventSystem.ts"],"names":[],"mappings":";;;AAyWA,gDAMC;AAKD,4CAEC;AApXD;;GAEG;AACH,MAAa,cAAc;IAIvB,YAAY,SAAqB;QAHzB,eAAU,GAAG,KAAK,CAAC;QAIvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED,OAAO;QACH,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACnB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,SAAS,EAAE,CAAC;QACrB,CAAC;IACL,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACJ;AAlBD,wCAkBC;AAED;;GAEG;AACH,MAAa,mBAAmB;IAAhC;QACY,gBAAW,GAAiB,EAAE,CAAC;QAC/B,eAAU,GAAG,KAAK,CAAC;IAkC/B,CAAC;IAhCG,GAAG,CAAC,UAAsB;QACtB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,UAAU,CAAC,OAAO,EAAE,CAAC;YACrB,OAAO;QACX,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,UAAsB;QACzB,MAAM,KAAK,GAAG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C;oBACrC,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;wBAC9C,QAAQ,CAAC,IAAI,CAAC,MAAuB,CAAC,CAAC;oBAC3C,CAAC;gBACL,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,OAAO,CAAC,KAAK,CACT,0CAA0C,MAAM,CAAC,KAAK,CAAC,GAAG,EAC1D,KAAK,CACR,CAAC;gBACN,CAAC;YACL,CAAC;YACD,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC;QAED,2CAA2C;QAC3C,MAAM,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;CACJ;AAhDD,8CAgDC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,GAAG,WAAyB;IAC3D,MAAM,SAAS,GAAG,IAAI,mBAAmB,EAAE,CAAC;IAC5C,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACnC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,SAAqB;IAClD,OAAO,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Position, Range, TextDocument } from '../types/core';
|
|
2
|
+
/**
|
|
3
|
+
* Efficient line-based text representation using a rope-like structure
|
|
4
|
+
* Optimized for typical code editing operations
|
|
5
|
+
*/
|
|
6
|
+
export declare class LineBuffer {
|
|
7
|
+
private lines;
|
|
8
|
+
private _version;
|
|
9
|
+
private _lineEndings;
|
|
10
|
+
constructor(content?: string, lineEnding?: string);
|
|
11
|
+
get version(): number;
|
|
12
|
+
get lineCount(): number;
|
|
13
|
+
get lineEndings(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Get the full text content
|
|
16
|
+
*/
|
|
17
|
+
getText(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Get text within a specific range
|
|
20
|
+
*/
|
|
21
|
+
getTextRange(range: Range): string;
|
|
22
|
+
/**
|
|
23
|
+
* Get content of a specific line
|
|
24
|
+
*/
|
|
25
|
+
getLineContent(line: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Get line length including line ending
|
|
28
|
+
*/
|
|
29
|
+
getLineLength(line: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Set the entire text content
|
|
32
|
+
*/
|
|
33
|
+
setText(content: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Insert text at a specific position
|
|
36
|
+
*/
|
|
37
|
+
insertText(position: Position, text: string): Range;
|
|
38
|
+
/**
|
|
39
|
+
* Delete text in a specific range
|
|
40
|
+
*/
|
|
41
|
+
deleteText(range: Range): string;
|
|
42
|
+
/**
|
|
43
|
+
* Replace text in a specific range
|
|
44
|
+
*/
|
|
45
|
+
replaceText(range: Range, text: string): Range;
|
|
46
|
+
/**
|
|
47
|
+
* Validate and clamp position to document bounds
|
|
48
|
+
*/
|
|
49
|
+
validatePosition(position: Position): Position;
|
|
50
|
+
/**
|
|
51
|
+
* Validate and clamp range to document bounds
|
|
52
|
+
*/
|
|
53
|
+
validateRange(range: Range): Range;
|
|
54
|
+
/**
|
|
55
|
+
* Get word range at position
|
|
56
|
+
*/
|
|
57
|
+
getWordRangeAtPosition(position: Position, wordPattern?: RegExp): Range | null;
|
|
58
|
+
/**
|
|
59
|
+
* Convert offset to position
|
|
60
|
+
*/
|
|
61
|
+
offsetToPosition(offset: number): Position;
|
|
62
|
+
/**
|
|
63
|
+
* Convert position to offset
|
|
64
|
+
*/
|
|
65
|
+
positionToOffset(position: Position): number;
|
|
66
|
+
/**
|
|
67
|
+
* Find next occurrence of text
|
|
68
|
+
*/
|
|
69
|
+
findNext(searchText: string, startPosition: Position, options?: {
|
|
70
|
+
caseSensitive?: boolean;
|
|
71
|
+
wholeWord?: boolean;
|
|
72
|
+
regex?: boolean;
|
|
73
|
+
}): Range | null;
|
|
74
|
+
/**
|
|
75
|
+
* Find all occurrences of text
|
|
76
|
+
*/
|
|
77
|
+
findAll(searchText: string, options?: {
|
|
78
|
+
caseSensitive?: boolean;
|
|
79
|
+
wholeWord?: boolean;
|
|
80
|
+
regex?: boolean;
|
|
81
|
+
}): Range[];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Implementation of TextDocument interface
|
|
85
|
+
*/
|
|
86
|
+
export declare class TextDocumentImpl implements TextDocument {
|
|
87
|
+
readonly uri: string;
|
|
88
|
+
readonly languageId: string;
|
|
89
|
+
readonly version: number;
|
|
90
|
+
private buffer;
|
|
91
|
+
constructor(uri: string, languageId: string, version: number, content: string);
|
|
92
|
+
get lineCount(): number;
|
|
93
|
+
getText(range?: Range): string;
|
|
94
|
+
getLineContent(line: number): string;
|
|
95
|
+
getWordRangeAtPosition(position: Position): Range | null;
|
|
96
|
+
validateRange(range: Range): Range;
|
|
97
|
+
validatePosition(position: Position): Position;
|
|
98
|
+
/**
|
|
99
|
+
* Internal method to get the line buffer for editing operations
|
|
100
|
+
*/
|
|
101
|
+
getBuffer(): LineBuffer;
|
|
102
|
+
/**
|
|
103
|
+
* Create a new version of this document with changes applied
|
|
104
|
+
*/
|
|
105
|
+
applyChanges(changes: Array<{
|
|
106
|
+
range: Range;
|
|
107
|
+
text: string;
|
|
108
|
+
}>): TextDocumentImpl;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=TextDocument.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextDocument.d.ts","sourceRoot":"","sources":["../../src/core/TextDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE9D;;;GAGG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,QAAQ,CAAK;IAC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