Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an analysis_server binary with dart_model implementation injected #120

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pkgs/_analyzer_macros/bin/server.dart
Original file line number Diff line number Diff line change
@@ -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<String> args) async {
injected.macroImplementation = await AnalyzerMacroImplementation.start(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious how we are going to handle enabling/disabling this in general?

If we are going to attempt to support old and new macros together, then the way we are injecting things right now won't really work, because it is a global setting, and you might have multiple projects open with different macro implementations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure I wrote a reply to this, not sure where it went...

My expectation is that we'll switch from one to the other without supporting both, and possibly with some downtime in between when we support neither.

It would be more work+complexity to support both for external users, e.g. we'd have to do something about package:macros being used in two different ways, or use two different packages.

For our own use for development I guess one or the other is enough, or we can add something more fine-grained if needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An atomic switch will probably be a bit tricky given all the tests which work with the existing API as well as the JSON macro (which lives in the SDK but we could move it out which might help).

It might still be the easiest answer though.

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);
}
1 change: 1 addition & 0 deletions pkgs/_analyzer_macros/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ environment:

dependencies:
_macro_host: any
analysis_server: any
analyzer: any
dart_model: any
macro_service: any
Expand Down
25 changes: 25 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down