From e37e906ae219fa7176a6bbc83cc71333558af453 Mon Sep 17 00:00:00 2001 From: David Morgan Date: Fri, 25 Oct 2024 16:52:41 +0200 Subject: [PATCH 1/3] Add an `analysis_server` binary with `dart_model` implementation injected. --- pkgs/_analyzer_macros/bin/server.dart | 35 +++++++++++++++++++++++++++ pkgs/_analyzer_macros/pubspec.yaml | 1 + pubspec.yaml | 25 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 pkgs/_analyzer_macros/bin/server.dart diff --git a/pkgs/_analyzer_macros/bin/server.dart b/pkgs/_analyzer_macros/bin/server.dart new file mode 100644 index 00000000..b4b13f94 --- /dev/null +++ b/pkgs/_analyzer_macros/bin/server.dart @@ -0,0 +1,35 @@ +// 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 'dart:io'; + +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 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 path, see `packageConfig` path hardcoded below. +void main(List args) async { + final home = Platform.environment['HOME']!; + 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('$home/git/macros/.dart_tool/package_config.json')); + + var starter = ServerStarter(); + starter.start(args); +} diff --git a/pkgs/_analyzer_macros/pubspec.yaml b/pkgs/_analyzer_macros/pubspec.yaml index fcc4ddf2..409afb03 100644 --- a/pkgs/_analyzer_macros/pubspec.yaml +++ b/pkgs/_analyzer_macros/pubspec.yaml @@ -9,6 +9,7 @@ environment: dependencies: _macro_host: any analyzer: any + analysis_server: any dart_model: any macro_service: any macros: 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 From e4706b9f08ee56d92cbd4755ecc513c38184af4c Mon Sep 17 00:00:00 2001 From: David Morgan Date: Mon, 28 Oct 2024 16:46:46 +0100 Subject: [PATCH 2/3] Address review comments, sort deps. --- goldens/foo/lib/json_codable_test.dart | 2 +- pkgs/_analyzer_macros/bin/server.dart | 10 ++++------ pkgs/_analyzer_macros/pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/goldens/foo/lib/json_codable_test.dart b/goldens/foo/lib/json_codable_test.dart index 9675ccae..84a54e90 100644 --- a/goldens/foo/lib/json_codable_test.dart +++ b/goldens/foo/lib/json_codable_test.dart @@ -223,7 +223,7 @@ class A { final double doubleField; - final num numField; + final num numFieldXfzAbcdefgabc; final List listOfSerializableField; diff --git a/pkgs/_analyzer_macros/bin/server.dart b/pkgs/_analyzer_macros/bin/server.dart index b4b13f94..3fe39a11 100644 --- a/pkgs/_analyzer_macros/bin/server.dart +++ b/pkgs/_analyzer_macros/bin/server.dart @@ -2,8 +2,6 @@ // 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 'dart:io'; - import 'package:_analyzer_macros/macro_implementation.dart'; import 'package:analysis_server/starter.dart'; import 'package:analyzer/src/summary2/macro_injected_impl.dart' as injected; @@ -14,21 +12,21 @@ import 'package:macro_service/macro_service.dart'; /// Run with your IDE by compiling and placing in the SDK your IDE is using, /// for example: /// -/// dart compile kernel bin/server.dart +/// 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 path, see `packageConfig` path hardcoded below. +/// Only works for one project, the one specified in the command line with +/// `PACKAGE_CONFIG_PATH`. void main(List args) async { - final home = Platform.environment['HOME']!; 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('$home/git/macros/.dart_tool/package_config.json')); + 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 409afb03..eb63921a 100644 --- a/pkgs/_analyzer_macros/pubspec.yaml +++ b/pkgs/_analyzer_macros/pubspec.yaml @@ -8,8 +8,8 @@ environment: dependencies: _macro_host: any - analyzer: any analysis_server: any + analyzer: any dart_model: any macro_service: any macros: any From 65a189f852e37338f0962cf7b0ed3e580fe009a1 Mon Sep 17 00:00:00 2001 From: David Morgan Date: Mon, 28 Oct 2024 17:09:26 +0100 Subject: [PATCH 3/3] Revert unwanted change. --- goldens/foo/lib/json_codable_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/goldens/foo/lib/json_codable_test.dart b/goldens/foo/lib/json_codable_test.dart index 84a54e90..9675ccae 100644 --- a/goldens/foo/lib/json_codable_test.dart +++ b/goldens/foo/lib/json_codable_test.dart @@ -223,7 +223,7 @@ class A { final double doubleField; - final num numFieldXfzAbcdefgabc; + final num numField; final List listOfSerializableField;