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

Augmented code from macros not showing up in VSCode #5110

Closed
wolfenrain opened this issue May 16, 2024 · 3 comments
Closed

Augmented code from macros not showing up in VSCode #5110

wolfenrain opened this issue May 16, 2024 · 3 comments

Comments

@wolfenrain
Copy link

Describe the bug

I have been playing around with Dart's experimental support for macros and I have followed the steps described here but I have not been able to get the augmented code to show up.

To Reproduce

  1. Follow the steps described in the documentation: https://dart.dev/language/macros#set-up-the-experiment
  2. Clone https://github.com/felangel/struct for a simple reproducible example
  3. Run dart pub get
  4. Open the example/main.dart

Expected behavior

I expected the augmented code to work and show up correctly.

Screenshots
This screenshot shows that the copyWith does not exist, even tho the macro adds it and I can run that code with dart run --enable-experiment=macros example/main.dart

image

Please complete the following information:

You can run the Dart: Collect Diagnostic Information command from the VS Code command palette (F1) to easily capture this information or provide it manually.

**!! ⚠️ PLEASE REVIEW THIS REPORT FOR SENSITIVE INFORMATION BEFORE SHARING ⚠️ !!**

<details>

<summary><strong>Workspace Environment</strong></summary>

```text
Dart Code extension: 3.88.1
Flutter extension: 3.88.0 (not activated)

App: Visual Studio Code
App Host: desktop
Version: mac 1.89.1

Workspace type: Dart (LSP)

Dart (3.5.0-160.0.dev): /Users/wolfen/development/flutter/bin/cache/dart-sdk
Flutter (undefined): /Users/wolfen/development/flutter (No device)

Output from 'dart info'

/Users/wolfen/development/flutter/bin/cache/dart-sdk/bin/dart info

If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

General info

  • Dart 3.5.0-160.0.dev (dev) (Wed May 15 17:06:58 2024 -0700) on "macos_arm64"
  • on macos / Version 14.4.1 (Build 23E224)
  • locale is en-NL

Project info

  • sdk constraint: '^3.5.0-152.0.dev'
  • dependencies: collection, equatable, macros
  • dev_dependencies:

Process info

Memory CPU Elapsed time Command line
351 MB 0.0% 02:30:27 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.88.1
132 MB 0.0% 03:20 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.88.1
27 MB 0.0% 02:30:27 dart tooling-daemon --machine
39 MB 0.0% 03:20 dart tooling-daemon --machine
```
@wolfenrain
Copy link
Author

/cc @kevmoo as he asked me to open an issue and CC him on it 😏

@felangel
Copy link

fwiw I'm also seeing the same thing. I was able to see things work correctly once or twice (e.g I could see the "go to augmentation" shortcut in vscode and the analyzer wasn't complaining) but lately I'm also experiencing the same issues as @wolfenrain using the exact same Dart version.

@DanTup
Copy link
Member

DanTup commented May 16, 2024

You're hitting dart-lang/sdk#55746 which has just been fixed. Currently the analysis server isn't running macros if they're imported from a file that exports them.

If you add src/ into your import in example/main.dart to import the file containing the macro directly then things will work:

import 'package:struct_annotation/src/struct_annotation.dart';
//                                ^^^^

Once you're on an SDK that includes dart-lang/sdk@73bdc86 then you'll be able to import a file that exports them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants