Dart-Code / Dart-Code

Dart and Flutter support for VS Code
https://dartcode.org/
MIT License
1.46k stars 295 forks source link

Augmented code from macros not showing up in VSCode #5110

Closed wolfenrain closed 2 weeks ago

wolfenrain commented 2 weeks ago

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 commented 2 weeks ago

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

felangel commented 2 weeks ago

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 commented 2 weeks ago

You're hitting https://github.com/dart-lang/sdk/issues/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 https://github.com/dart-lang/sdk/commit/73bdc86dd50e11cedb3bf976c597a02ad209bdb4 then you'll be able to import a file that exports them.