Skip to content

Commit 7385222

Browse files
committed
feat: Update version to 9.8.0, enhance CHANGELOG and README, fix LSP initialization bug, and improve document handling
1 parent 4a59108 commit 7385222

8 files changed

Lines changed: 73 additions & 34 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,7 @@ This release establishes **CodeForge** as a powerful, production-ready code edit
378378
- FEATURE: Empty `Mode` as default highlight grammar instead of dart grammar as requested in [#59](https://github.com/heckmon/code_forge/discussions/59)
379379

380380
## 9.7.0
381-
- Enhanced large text handling.
381+
- Enhanced large text handling.
382+
383+
## 9.8.0
384+
- - FIX: LSP initialization bug.

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,24 @@
3333
<img src="https://raw.githubusercontent.com/heckmon/code_forge/refs/heads/main/gifs/code_forge_100k.gif" alt="CodeForge Demo" width="800"/><sub><br>large code support (tested with 100k+ lines) and LSP based intelligent lazy highlighting</sub>
3434
</p>
3535

36+
### Feature demos: [CodeForge Features Showcase](https://heckmon.github.io/code_forge_demo/)
37+
3638
> [!NOTE]
3739
>
3840
> code_forge does **not** support Flutter web, as it relies on `dart:io` for core functionality. Use [code_forge_web](https://pub.dev/packages/code_forge_web) for web support.
3941
4042

41-
### What's new in 9.7.0
42-
- Enhanced large text handling.
43+
## Upcoming feature (v10.0.0):
44+
**Currently I'm working on the migration of code_forge backend from dart to rust, while keeping the front end flutter APIs untouched.
45+
This will make the code_forge lightning fast like the [zed editor](https://zed.dev/).**
46+
47+
48+
### What's new in 9.8.0
49+
- FIX: LSP initialization bug.
50+
51+
4352

4453
## Why CodeForge?
45-
**Feature demos:** [CodeForge Features Showcase](https://heckmon.github.io/code_forge_demo/)
4654

4755
**CodeForge** is a next-generation code editor widget designed for developers who demand more. Whether you're building an IDE, a code snippet viewer, or an educational coding platform, CodeForge delivers:
4856

@@ -114,7 +122,7 @@ Add CodeForge to your `pubspec.yaml`:
114122

115123
```yaml
116124
dependencies:
117-
code_forge: ^9.6.0
125+
code_forge: ^9.8.0
118126
```
119127
120128
Then run:

lib/LSP/lsp.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ sealed class LspConfig {
7272
}) {
7373
_initOptions.addAll({
7474
"highlight": {'enabled': true},
75+
...initializationOptions,
7576
});
7677
}
7778

@@ -155,7 +156,7 @@ sealed class LspConfig {
155156
textDocumentCapabilities['completion'] = {
156157
'completionItem': {
157158
'resolveSupport': {
158-
'properties': ['documentaion', 'detail', 'additionalTextEdits'],
159+
'properties': ['documentation', 'detail', 'additionalTextEdits'],
159160
},
160161
'snippetSupport': false,
161162
},

lib/LSP/lsp_socket.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ class LspSocketConfig extends LspConfig {
9191
final request = {'jsonrpc': '2.0', 'id': id, "result": result};
9292

9393
_channel.sink.add(jsonEncode(request));
94-
95-
return await _responseController.stream.firstWhere(
96-
(response) => response['id'] == id,
97-
orElse: () => throw TimeoutException('No response for request $id'),
98-
);
94+
return request;
9995
}
10096

10197
@override

lib/LSP/lsp_stdio.dart

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class LspStdioConfig extends LspConfig {
118118
executable,
119119
args ?? [],
120120
environment: environment,
121+
workingDirectory: workspacePath,
121122
);
122123
_process.stdout.listen(_handleStdoutData);
123124
_process.stderr.listen((data) => debugPrint(utf8.decode(data)));
@@ -154,12 +155,11 @@ class LspStdioConfig extends LspConfig {
154155
}
155156

156157
int _findHeaderEnd() {
157-
final endSequence = [13, 10, 13, 10];
158-
for (var i = 0; i <= _buffer.length - endSequence.length; i++) {
159-
if (List.generate(
160-
endSequence.length,
161-
(j) => _buffer[i + j],
162-
).every((byte) => endSequence.contains(byte))) {
158+
for (var i = 0; i <= _buffer.length - 4; i++) {
159+
if (_buffer[i] == 13 &&
160+
_buffer[i + 1] == 10 &&
161+
_buffer[i + 2] == 13 &&
162+
_buffer[i + 3] == 10) {
163163
return i;
164164
}
165165
}
@@ -205,11 +205,7 @@ class LspStdioConfig extends LspConfig {
205205
) async {
206206
final request = {'jsonrpc': '2.0', 'id': id, 'result': result};
207207
await _sendLspMessage(request);
208-
209-
return await _responseController.stream.firstWhere(
210-
(response) => response['id'] == id,
211-
orElse: () => throw TimeoutException('No response for request $id'),
212-
);
208+
return request;
213209
}
214210

215211
Future<void> _sendLspMessage(Map<String, dynamic> message) async {

lib/code_forge/code_area.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7942,15 +7942,24 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
79427942
_paragraphCache[lineIndex] = para;
79437943
}
79447944

7945-
final lineStartChar = (lineIndex == startLine) ? startChar : 0;
7946-
final lineEndChar = (lineIndex == endLine)
7947-
? endChar.clamp(0, lineText.length)
7948-
: lineText.length;
7945+
final lineStartChar = ((lineIndex == startLine) ? startChar : 0).clamp(
7946+
0,
7947+
lineText.length,
7948+
);
7949+
int lineEndChar = ((lineIndex == endLine) ? endChar : lineText.length)
7950+
.clamp(0, lineText.length);
79497951

7950-
if (lineStartChar >= lineEndChar || lineStartChar >= lineText.length) {
7952+
if (lineStartChar >= lineText.length) {
79517953
continue;
79527954
}
79537955

7956+
if (lineStartChar >= lineEndChar) {
7957+
lineEndChar = (lineStartChar + 1).clamp(0, lineText.length);
7958+
if (lineStartChar >= lineEndChar) {
7959+
continue;
7960+
}
7961+
}
7962+
79547963
final boxKey = '$lineIndex-$lineStartChar-$lineEndChar';
79557964
final boxes = _diagnosticPathCache.containsKey(boxKey)
79567965
? _diagnosticPathCache[boxKey] as List<ui.TextBox>

lib/code_forge/controller.dart

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,9 @@ class CodeForgeController implements DeltaTextInputClient {
8787
if (!lspConfig!.isInitialized) {
8888
await lspConfig!.initialize();
8989
}
90-
await Future.delayed(const Duration(milliseconds: 300));
91-
await lspConfig!.openDocument(openedFile!);
92-
_lspReady = true;
93-
await _fetchSemanticTokensFull();
94-
await fetchDocumentColors();
95-
await fetchLSPFoldRanges();
90+
if (openedFile != null) {
91+
await _openDocumentInLsp();
92+
}
9693
} catch (e) {
9794
debugPrint('Error initializing LSP: $e');
9895
} finally {
@@ -260,6 +257,25 @@ class CodeForgeController implements DeltaTextInputClient {
260257
}
261258
}
262259

260+
Future<void> _openDocumentInLsp({String? previousFile}) async {
261+
if (lspConfig == null || !lspConfig!.isInitialized || openedFile == null) {
262+
return;
263+
}
264+
265+
try {
266+
if (previousFile != null && previousFile != openedFile) {
267+
await lspConfig!.closeDocument(previousFile);
268+
}
269+
await lspConfig!.openDocument(openedFile!);
270+
_lspReady = true;
271+
await _fetchSemanticTokensFull();
272+
await fetchDocumentColors();
273+
await fetchLSPFoldRanges();
274+
} catch (e) {
275+
debugPrint('Error opening LSP document: $e');
276+
}
277+
}
278+
263279
Future<void> _highlightListener() async {
264280
if (text != _previousValue && _lspReady) {
265281
final currentText = text;
@@ -364,10 +380,20 @@ class CodeForgeController implements DeltaTextInputClient {
364380

365381
/// Open a file using the controller API instead of passing `filePath` parameter to [CodeForge]
366382
set openedFile(String? file) {
383+
final previousFile = _openedFile;
367384
_openedFile = file;
368385
if (openedFile != null) {
369386
text = File(_openedFile!).readAsStringSync();
370387
}
388+
389+
if (previousFile != openedFile &&
390+
lspConfig != null &&
391+
lspConfig!.isInitialized &&
392+
openedFile != null) {
393+
(() async {
394+
await _openDocumentInLsp(previousFile: previousFile);
395+
})();
396+
}
371397
}
372398

373399
/// Returns the errors, warnings and info available in the editor as a [List<LspErrors>].

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: code_forge
22
description: "A sophisticated code editor package with AI completion, LSP support, syntax highlighting, and advanced editing capabilities."
3-
version: 9.7.0
3+
version: 9.8.0
44
homepage: https://github.com/heckmon/code_forge
55

66
environment:

0 commit comments

Comments
 (0)