diff --git a/lib/provider/code.g.dart b/lib/provider/code.g.dart index 3183e52..7aac36f 100644 --- a/lib/provider/code.g.dart +++ b/lib/provider/code.g.dart @@ -122,4 +122,5 @@ class SourceFileProvider ); } } -// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member diff --git a/lib/provider/datastore.g.dart b/lib/provider/datastore.g.dart index b8ed50c..f60b323 100644 --- a/lib/provider/datastore.g.dart +++ b/lib/provider/datastore.g.dart @@ -20,4 +20,5 @@ final datastoreProvider = FutureProvider.internal( ); typedef DatastoreRef = FutureProviderRef; -// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member diff --git a/lib/provider/file.g.dart b/lib/provider/file.g.dart index 7e51198..c113aed 100644 --- a/lib/provider/file.g.dart +++ b/lib/provider/file.g.dart @@ -109,4 +109,5 @@ class FileServiceProvider extends Provider { return _SystemHash.finish(hash); } } -// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member diff --git a/lib/provider/lsp.dart b/lib/provider/lsp.dart index a2f89c5..7376851 100644 --- a/lib/provider/lsp.dart +++ b/lib/provider/lsp.dart @@ -1,22 +1,97 @@ import 'package:package_info_plus/package_info_plus.dart'; +import 'package:path/path.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; +import '../logger.dart'; +import '../models/log_level.dart'; +import '../models/lsp/error.dart'; +import '../models/lsp/params/capabilities.dart'; +import '../models/lsp/params/clientInfo.dart'; +import '../models/lsp/params/initializationOptions.dart'; +import '../models/lsp/params/initialize.dart'; +import '../models/lsp/params/workspaceFolder.dart'; import '../services/lsp/lang/dart.dart'; +import '../utils.dart'; import '../wrapper/process.dart'; +import 'notifications.dart'; part 'lsp.g.dart'; @Riverpod(keepAlive: true) -Future dartLSP(DartLSPRef ref) async { - PackageInfo packageInfo = await PackageInfo.fromPlatform(); +class DartLSP extends _$DartLSP { + Future startDartLSP() async { + PackageInfo packageInfo = await PackageInfo.fromPlatform(); - DartLSPService service = await DartLSPService.start( - processWrapper: ActualProcessWrapper(), - clientId: packageInfo.packageName, - clientVersion: packageInfo.version, - logFilePath: '${packageInfo.packageName}-dart-sdk-lsp.log'); + DartLSPService service = await DartLSPService.start( + processWrapper: ActualProcessWrapper(), + clientId: packageInfo.packageName, + clientVersion: packageInfo.version, + logFilePath: '${packageInfo.packageName}-dart-sdk-lsp.log'); - ref.onDispose(service.stop); + ref.onDispose(service.stop); - return service; + return service; + } + + @override + Future build() async { + return startDartLSP(); + } + + void initializeLSP(String directoryPath) async { + if (!state.hasValue) { + await startDartLSP(); + } + + DartLSPService lspDart = state.requireValue; + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + + int lspParentProcessId = await lspDart.getParentProcessId(); + + final directoryUri = Uri.parse(directoryPath); + WorkspaceFolder workspaceFolder = WorkspaceFolder( + uri: directoryUri, + name: basename(directoryPath), + ); + + Initialize initialize = Initialize( + processId: lspParentProcessId, + rootUri: directoryUri.toString(), + capabilities: clientCapabilities, + initializationOptions: const InitializationOptions(), + trace: "verbose", + workspaceFolder: [workspaceFolder], + clientInfo: ClientInfo( + name: packageInfo.packageName, version: packageInfo.version), + locale: getCurrentLocale(), + ); + + try { + Map initialized = await lspDart.initialize(initialize); + logger.i("LSP:initialize: >>>"); + + if (initialized['capabilities'] != null && + initialized['serverInfo'] != null) { + lspDart.initialized(); + logger.i("LSP:initialized: <<< "); + + ref.watch(inAppNotificationStateProvider.notifier).fireInNotification( + 'Dart LSP server initialized!', + logLevel: LogLevel.info, + ); + } + } catch (err) { + if (err is LSPError) { + if (err.code == -32002) { + // Todo: Call change directory path + } else { + ref.watch(inAppNotificationStateProvider.notifier).fireInNotification( + 'Failed to initialize Dart LSP server', + logLevel: LogLevel.fatal, + ); + } + } + logger.e(err); + } + } } diff --git a/lib/provider/lsp.g.dart b/lib/provider/lsp.g.dart index 17cb9a1..dceb4ba 100644 --- a/lib/provider/lsp.g.dart +++ b/lib/provider/lsp.g.dart @@ -6,12 +6,12 @@ part of 'lsp.dart'; // RiverpodGenerator // ************************************************************************** -String _$dartLSPHash() => r'828e95e43a9296182919bc1050000ccc5a92ff85'; +String _$dartLSPHash() => r'50ba5a1a6536be51825353465a5118d998159e0e'; -/// See also [dartLSP]. -@ProviderFor(dartLSP) -final dartLSPProvider = FutureProvider.internal( - dartLSP, +/// See also [DartLSP]. +@ProviderFor(DartLSP) +final dartLSPProvider = AsyncNotifierProvider.internal( + DartLSP.new, name: r'dartLSPProvider', debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') ? null : _$dartLSPHash, @@ -19,5 +19,6 @@ final dartLSPProvider = FutureProvider.internal( allTransitiveDependencies: null, ); -typedef DartLSPRef = FutureProviderRef; -// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions +typedef _$DartLSP = AsyncNotifier; +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member diff --git a/lib/provider/notifications.g.dart b/lib/provider/notifications.g.dart index d55aec8..d293207 100644 --- a/lib/provider/notifications.g.dart +++ b/lib/provider/notifications.g.dart @@ -7,7 +7,7 @@ part of 'notifications.dart'; // ************************************************************************** String _$inAppNotificationStateHash() => - r'c5107f5e96d2ab76db10fd51f8ea4e0c14738fa7'; + r'f81ee8f515dc66a41b5a7aecac90c0d65802106d'; /// See also [InAppNotificationState]. @ProviderFor(InAppNotificationState) @@ -23,4 +23,5 @@ final inAppNotificationStateProvider = ); typedef _$InAppNotificationState = Notifier; -// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member diff --git a/lib/provider/project.dart b/lib/provider/project.dart index 9e55a12..ab79e5b 100644 --- a/lib/provider/project.dart +++ b/lib/provider/project.dart @@ -1,20 +1,9 @@ import 'dart:io'; -import 'package:package_info_plus/package_info_plus.dart'; import 'package:path/path.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; -import '../logger.dart'; import '../models/ignored.dart'; -import '../models/log_level.dart'; -import '../models/lsp/error.dart'; -import '../models/lsp/params/capabilities.dart'; -import '../models/lsp/params/clientInfo.dart'; -import '../models/lsp/params/initializationOptions.dart'; -import '../models/lsp/params/initialize.dart'; -import '../models/lsp/params/workspaceFolder.dart'; -import '../utils.dart'; import 'lsp.dart'; -import 'notifications.dart'; part 'project.g.dart'; @@ -26,66 +15,13 @@ class ProjectDirectoryPath extends _$ProjectDirectoryPath { } void changeDirectoryPath(String? directoryPath) { - initializeLSP(directoryPath!); + // Reading the dartLSPProvider.future will start the LSP service if it hasn't been started yet + // Reading dartLSPProvider as its used inside functions triggered by user interactions (User select workspace) + ref.read(dartLSPProvider.future).then((dartLSPService) => + ref.read(dartLSPProvider.notifier).initializeLSP(directoryPath!)); state = directoryPath; } - - void initializeLSP(String directoryPath) async { - ref.read(dartLSPProvider).whenData((lspDart) async { - PackageInfo packageInfo = await PackageInfo.fromPlatform(); - - int lspParentProcessId = await lspDart.getParentProcessId(); - - final directoryUri = Uri.parse(directoryPath); - WorkspaceFolder workspaceFolder = WorkspaceFolder( - uri: directoryUri, - name: basename(directoryPath), - ); - - Initialize initialize = Initialize( - processId: lspParentProcessId, - rootUri: directoryUri.toString(), - capabilities: clientCapabilities, - initializationOptions: const InitializationOptions(), - trace: "verbose", - workspaceFolder: [workspaceFolder], - clientInfo: ClientInfo( - name: packageInfo.packageName, version: packageInfo.version), - locale: getCurrentLocale(), - ); - - try { - Map initialized = await lspDart.initialize(initialize); - logger.i("LSP:initialize: >>>"); - - if (initialized['capabilities'] != null && - initialized['serverInfo'] != null) { - lspDart.initialized(); - logger.i("LSP:initialized: <<< "); - - ref.watch(inAppNotificationStateProvider.notifier).fireInNotification( - 'Dart LSP server initialized!', - logLevel: LogLevel.info, - ); - } - } catch (err) { - if (err is LSPError) { - if (err.code == -32002) { - // Todo: Call change directory path - } else { - ref - .watch(inAppNotificationStateProvider.notifier) - .fireInNotification( - 'Failed to initialize Dart LSP server', - logLevel: LogLevel.fatal, - ); - } - } - logger.e(err); - } - }); - } } @Riverpod(keepAlive: true) diff --git a/lib/provider/project.g.dart b/lib/provider/project.g.dart index b47feec..4315987 100644 --- a/lib/provider/project.g.dart +++ b/lib/provider/project.g.dart @@ -7,7 +7,7 @@ part of 'project.dart'; // ************************************************************************** String _$projectDirectoryPathHash() => - r'c479f90c95530de067c737caf2592a289794503f'; + r'0b2c542f304be176577b22ef334f4aa0957764c3'; /// See also [ProjectDirectoryPath]. @ProviderFor(ProjectDirectoryPath) @@ -55,4 +55,5 @@ final projectExpandedNodesProvider = ); typedef _$ProjectExpandedNodes = Notifier>; -// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member diff --git a/lib/provider/repository.g.dart b/lib/provider/repository.g.dart index cec2ca5..460bb82 100644 --- a/lib/provider/repository.g.dart +++ b/lib/provider/repository.g.dart @@ -21,4 +21,5 @@ final codeBufferRepoProvider = FutureProvider.internal( ); typedef CodeBufferRepoRef = FutureProviderRef; -// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member diff --git a/lib/provider/theme.g.dart b/lib/provider/theme.g.dart index 1ea9398..3779891 100644 --- a/lib/provider/theme.g.dart +++ b/lib/provider/theme.g.dart @@ -39,4 +39,5 @@ final coreCodeThemeStateProvider = ); typedef _$CoreCodeThemeState = Notifier; -// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member diff --git a/lib/provider/tools.g.dart b/lib/provider/tools.g.dart index 9948ff8..7303264 100644 --- a/lib/provider/tools.g.dart +++ b/lib/provider/tools.g.dart @@ -38,4 +38,5 @@ final toolWindowWeightProvider = ); typedef _$ToolWindowWeight = AutoDisposeNotifier; -// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member diff --git a/lib/router/router.g.dart b/lib/router/router.g.dart index d8806ac..a7503f1 100644 --- a/lib/router/router.g.dart +++ b/lib/router/router.g.dart @@ -20,4 +20,5 @@ final routerProvider = AutoDisposeProvider.internal( ); typedef RouterRef = AutoDisposeProviderRef; -// ignore_for_file: unnecessary_raw_strings, subtype_of_sealed_class, invalid_use_of_internal_member, do_not_use_environment, prefer_const_constructors, public_member_api_docs, avoid_private_typedef_functions +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member