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

Getting value from Literal/Const #44

Closed
TheAngryByrd opened this issue May 28, 2020 · 6 comments
Closed

Getting value from Literal/Const #44

TheAngryByrd opened this issue May 28, 2020 · 6 comments
Labels
enhancement New feature or request probably-not

Comments

@TheAngryByrd
Copy link
Contributor

Let's say I have the following code in my Types.fs file.

module A = 
    let [<Literal>] MyConst = "Hello"
    type MyAttribute(thing : string) =
        inherit System.Attribute()
        let _thing = thing
    type Thing = {
        [<MyAttribute(MyConst)>]
        Foo : string
    }

When looking at the AST of this code, the attributes for the field Foo:

{ Attributes =
   [{ TypeName =
                LongIdentWithDots
                  ([MyAttribute],
                   [])
      ArgExpr =
               Paren
                 (Ident MyConst,
                  tmp.fsx (8,25--8,26) IsSynthetic=false,
                  Some
                    tmp.fsx (8,33--8,34) IsSynthetic=false,
                  tmp.fsx (8,25--8,34) IsSynthetic=false)
      Target = None
      AppliesToGetterAndSetter =
                                false
      Range =
             tmp.fsx (8,14--8,25) IsSynthetic=false }]
   Range =
          tmp.fsx (8,12--8,36) IsSynthetic=false }

I get told that the data in the Attribute is MyConst. Do you know if there is a way I'd be able to get the value from that?

@Zaid-Ajaj
Copy link

This is how I do it in the Npgsql analyzer

@TheAngryByrd
Copy link
Contributor Author

Thanks I'll give that a shot!

@TheAngryByrd
Copy link
Contributor Author

TheAngryByrd commented May 28, 2020

Oh looks like I don't have access to the symbols only the ParsedInput.

Maybe Myriad should adopt the same structure from the Analyzers.SDK?

@7sharp9
Copy link
Collaborator

7sharp9 commented May 29, 2020

I would rather not have to type check the file and extract symbols thats the super slow part of the compiler, probably better to create some form of backtrack or binding dictionary.

@Krzysztof-Cieslak
Copy link
Contributor

I don't even think the problem is that it's the slow part of the compiler, which wouldn't be an as big issue given Myriad is run as part of build process - but huge issue is that we would need to parse project files to perform type checking. Which as you all know is not the best part of the F# community tooling ecosystem ;]

@7sharp9 7sharp9 added enhancement New feature or request help wanted Extra attention is needed labels Jul 28, 2020
@7sharp9 7sharp9 added probably-not and removed help wanted Extra attention is needed labels May 19, 2022
@7sharp9
Copy link
Collaborator

7sharp9 commented May 19, 2022

I don't think I'll get to this, up for grabs if anyone ever wants to do it, not me though.

@7sharp9 7sharp9 closed this as completed May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request probably-not
Projects
None yet
Development

No branches or pull requests

4 participants