diff --git a/pkgs/_analyzer_macros/bin/server.dart b/pkgs/_analyzer_macros/bin/server.dart new file mode 100644 index 00000000..3fe39a11 --- /dev/null +++ b/pkgs/_analyzer_macros/bin/server.dart @@ -0,0 +1,33 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:_analyzer_macros/macro_implementation.dart'; +import 'package:analysis_server/starter.dart'; +import 'package:analyzer/src/summary2/macro_injected_impl.dart' as injected; +import 'package:macro_service/macro_service.dart'; + +/// Analysis server with `dart_model` implementation injected. +/// +/// Run with your IDE by compiling and placing in the SDK your IDE is using, +/// for example: +/// +/// dart compile kernel -DPACKAGE_CONFIG_PATH=$HOME/git/macros/.dart_tool/package_config.json bin/server.dart +/// cp bin/server.dill ~/opt/dart-sdk-be/bin/snapshots/analysis_server.dart.snapshot +/// +/// Then restart, VSCode: Ctrl+Shift+P, Restart Analysis Server. +/// +/// Only works for one project, the one specified in the command line with +/// `PACKAGE_CONFIG_PATH`. +void main(List args) async { + injected.macroImplementation = await AnalyzerMacroImplementation.start( + protocol: Protocol( + encoding: ProtocolEncoding.binary, version: ProtocolVersion.macros1), + // TODO(davidmorgan): this needs to come from the analyzer, not be + // hardcoded. + packageConfig: + Uri.file(const String.fromEnvironment('PACKAGE_CONFIG_PATH'))); + + var starter = ServerStarter(); + starter.start(args); +} diff --git a/pkgs/_analyzer_macros/pubspec.yaml b/pkgs/_analyzer_macros/pubspec.yaml index fcc4ddf2..eb63921a 100644 --- a/pkgs/_analyzer_macros/pubspec.yaml +++ b/pkgs/_analyzer_macros/pubspec.yaml @@ -8,6 +8,7 @@ environment: dependencies: _macro_host: any + analysis_server: any analyzer: any dart_model: any macro_service: any diff --git a/pubspec.yaml b/pubspec.yaml index 69104325..082aec3a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,11 +39,21 @@ dependency_overrides: url: https://github.com/dart-lang/sdk.git path: pkg/_macros ref: a8bee55e94979730890500026884afcf33e68f2f + analysis_server: + git: + url: https://github.com/dart-lang/sdk.git + path: pkg/analysis_server + ref: a8bee55e94979730890500026884afcf33e68f2f analyzer: git: url: https://github.com/dart-lang/sdk.git path: pkg/analyzer ref: a8bee55e94979730890500026884afcf33e68f2f + analyzer_plugin: + git: + url: https://github.com/dart-lang/sdk.git + path: pkg/analyzer_plugin + ref: a8bee55e94979730890500026884afcf33e68f2f analyzer_utilities: git: url: https://github.com/dart-lang/sdk.git @@ -109,6 +119,16 @@ dependency_overrides: url: https://github.com/dart-lang/sdk.git path: pkg/kernel ref: a8bee55e94979730890500026884afcf33e68f2f + analysis_server_plugin: + git: + url: https://github.com/dart-lang/sdk.git + path: pkg/analysis_server_plugin + ref: a8bee55e94979730890500026884afcf33e68f2f + language_server_protocol: + git: + url: https://github.com/dart-lang/sdk.git + path: third_party/pkg/language_server_protocol + ref: a8bee55e94979730890500026884afcf33e68f2f linter: git: url: https://github.com/dart-lang/sdk.git @@ -119,6 +139,11 @@ dependency_overrides: url: https://github.com/dart-lang/sdk.git path: pkg/mmap ref: a8bee55e94979730890500026884afcf33e68f2f + telemetry: + git: + url: https://github.com/dart-lang/sdk.git + path: pkg/telemetry + ref: a8bee55e94979730890500026884afcf33e68f2f vm: git: url: https://github.com/dart-lang/sdk.git