Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Make it possible to query a type literal/class reference #156

Closed
eEQK opened this issue Dec 14, 2024 · 1 comment
Closed

Make it possible to query a type literal/class reference #156

eEQK opened this issue Dec 14, 2024 · 1 comment

Comments

@eEQK
Copy link
Contributor

eEQK commented Dec 14, 2024

TL;DR do we want a ClassReference.uri field? or maybe ClassReference.name to be a QualifiedName?


I'm currently building a macro that will take in a specification as an argument and generate a client/server based on this specification

the way it's going to be used will be something along the lines of:

@Client(BaseService)
class BaseClient {}

which generates the following:

{
  "type": "ConstructorInvocation",
  "value": {
    "type": { ... },
    "constructor": { ... },
    "arguments": [
      {
        "type": "PositionalArgument",
        "value": {
          "expression": {
            "type": "TypeLiteral",
            "value": {
              "typeAnnotation": {
                "type": "NamedTypeAnnotation",
                "value": {
                  "reference": {
                    "type": "ClassReference",
                    "value": {
                      "name": "BaseService"
                    }
                  },
                  "typeArguments": []
                }
              }
            }
          }
        }
      }
    ]
  }
}

As you can see, having a name only is not enough to query BaseService since at that moment BaseService is not loaded/resolved (builder.model.node['types'])

"types": {
    "named": {
      "dart:core#Object": { ... },
      "dart:core#Null": { ... },
      "dart:async#Future": { ... },
      "package:bar/test.dart#BaseClient": { ... }
  }

I do actually have a local fix for that, that adds uri to ClassReference (I'm not sure but I feel like it makes the most sense to put that information there):

                  "reference": {
                    "type": "ClassReference",
                    "value": {
                      "name": "BaseService",
                      "uri": "package:bar/test.dart"
                    }
                  },

and I'd love to submit a PR, but I'm not sure if that's how the model should look like? another approach would be to make name a qualified name, like so:

                  "reference": {
                    "type": "ClassReference",
                    "value": {
                      "name": "package:bar/test.dart#BaseService"
                    }
                  },

So my question is, do we want a uri field, name to become a QualifiedName or maybe something else?

Thanks in advance!

@davidmorgan
Copy link
Contributor

Thanks for filing.

I think we're not ready to get into this level of detail here yet, there are bigger questions about the macro metadata model that we need to figure out first.

@davidmorgan davidmorgan closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants