Skip to content

Commit 17446f0

Browse files
committed
Update version to 0.2.3; add options to enable/disable LSP warnings and errors
1 parent 2e385f7 commit 17446f0

File tree

7 files changed

+59
-6
lines changed

7 files changed

+59
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,8 @@
9090

9191
## 0.2.2
9292

93-
* Enhance: LSP suggestion
93+
* Enhance: LSP suggestion
94+
95+
## 0.2.3
96+
97+
* Added Option to enable/disable LSP warning and error.

lib/LSP/lsp.dart

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22
import 'dart:convert';
33
import 'dart:io';
44
import 'package:flutter/material.dart';
5+
import 'package:flutter/rendering.dart';
56

67
import '../utils/utils.dart';
78
import 'package:web_socket_channel/web_socket_channel.dart';
@@ -24,6 +25,13 @@ sealed class LspConfig {
2425
/// The workspacePath is the root directory of the project or workspace.
2526
/// If you are using a single file, you can set it to the parent directory of the file.
2627
final String workspacePath;
28+
29+
/// Whether to disable warnings from the LSP server.
30+
final bool disableWarning;
31+
32+
/// Whether to disable errors from the LSP server.
33+
final bool disableError;
34+
2735
final StreamController<Map<String, dynamic>> _responseController =
2836
StreamController.broadcast();
2937
int _nextId = 1;
@@ -33,6 +41,8 @@ sealed class LspConfig {
3341
required this.filePath,
3442
required this.workspacePath,
3543
required this.languageId,
44+
this.disableWarning = false,
45+
this.disableError = false,
3646
});
3747

3848
void dispose();
@@ -178,8 +188,22 @@ sealed class LspConfig {
178188
method: 'textDocument/hover',
179189
params: _commonParams(line, character),
180190
);
181-
if (response['result'] == null || response['result'].isEmpty) return '';
182-
return response['result']?['contents']?['value'] ?? '';
191+
final contents = response['result']?['contents'];
192+
if (contents == null || contents.isEmpty) return '';
193+
if (contents is String) return contents;
194+
if (contents is Map && contents.containsKey('value')) {
195+
return contents['value'] ?? '';
196+
}
197+
if (contents is List && contents.isNotEmpty) {
198+
return contents
199+
.map((item) {
200+
if (item is String) return item;
201+
if (item is Map && item.containsKey('value')) return item['value'];
202+
return '';
203+
})
204+
.join('\n');
205+
}
206+
return '';
183207
}
184208

185209
Future<String> getDefinition(int line, int character) async {

lib/LSP/lsp_socket.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class LspSocketConfig extends LspConfig {
3434
required super.workspacePath,
3535
required super.languageId,
3636
required this.serverUrl,
37+
super.disableWarning,
38+
super.disableError,
3739
}) : _channel = WebSocketChannel.connect(Uri.parse(serverUrl));
3840

3941
/// This method is used to initialize the LSP server. and it's used internally by the [CodeCrafter] widget.

lib/LSP/lsp_stdio.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class LspStdioConfig extends LspConfig {
7979
required super.languageId,
8080
this.args,
8181
this.environment,
82+
super.disableWarning,
83+
super.disableError,
8284
});
8385

8486
static Future<LspStdioConfig> start({
@@ -88,6 +90,8 @@ class LspStdioConfig extends LspConfig {
8890
required String languageId,
8991
List<String>? args,
9092
Map<String, String>? environment,
93+
bool disableWarning = false,
94+
bool disableError = false,
9195
}) async {
9296
final config = LspStdioConfig._(
9397
executable: executable,
@@ -96,6 +100,8 @@ class LspStdioConfig extends LspConfig {
96100
workspacePath: workspacePath,
97101
args: args,
98102
environment: environment,
103+
disableWarning: disableWarning,
104+
disableError: disableError,
99105
);
100106
await config._startProcess();
101107
return config;

lib/code_crafter/code_area.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,17 @@ class _CodeCrafterState extends State<CodeCrafter> {
189189
for (final (item as Map<String, dynamic>) in diagnostics) {
190190
errors.add(
191191
LspErrors(
192-
severity: item['severity'],
192+
severity: (() {
193+
if (item['severity'] == 1 &&
194+
widget.lspConfig!.disableError) {
195+
return 0;
196+
}
197+
if (item['severity'] == 2 &&
198+
widget.lspConfig!.disableWarning) {
199+
return 0;
200+
}
201+
return item['severity'];
202+
})(),
193203
range: item['range'],
194204
message: item['message'],
195205
),
@@ -409,7 +419,13 @@ class _CodeCrafterState extends State<CodeCrafter> {
409419
@override
410420
void dispose() {
411421
_keyboardFocus.dispose();
422+
_suggestionFocus.dispose();
423+
_codeFocus.dispose();
424+
_hoverHorizontalScroll.dispose();
425+
_hoverVerticalSCroll.dispose();
412426
_debounceTimer?.cancel();
427+
widget.lspConfig?.closeDocument();
428+
widget.lspConfig?.dispose();
413429
super.dispose();
414430
}
415431

lib/code_crafter/code_crafter_controller.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ class CodeCrafterController extends TextEditingController {
420420
case 3:
421421
return Colors.blueAccent;
422422
default:
423-
return Colors.transparent;
423+
return editorTheme['root']?.backgroundColor ??
424+
Colors.black;
424425
}
425426
})(),
426427
).merge(Shared().textStyle);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_code_crafter
22
description: "Powerful code editor with AI code completion and LSP support"
3-
version: 0.2.2
3+
version: 0.2.3
44
homepage: https://github.com/heckmon/flutter_code_crafter
55

66
environment:

0 commit comments

Comments
 (0)