-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.