Skip to content

Add ToString() as an alias to ''.'' (dot inode) for getting a folder path #3

Closed

Description

@JordanMarr

I am now able to create my generated type, SlnRoot, and I am able to dot into it and correctly browse all of the directories and files on it.

However, when I try to bind one of the string values of a file or folder, I get this error on my type:

image

Activity

  1. MangelMaxime commented on Apr 22, 2024

    @MangelMaxime
    Contributor

    The error you are seing is because ``SlqHydra.Queryy`` is an interface.

    So here you are trying to assigned an interface to a variable which is not possible. If you want the folder path you need to use SlnRoot.``SqlHydra.Query``.``.`` .

    I am using . because this is the standard inode to represent the current on Unix system which makes sure there are no conflicts with an existing file name.

    However, when debugging this issue I found out that VS does not provide completion for double backtick properties. Which is probably why you didn't see the problem with the type being an interface.

  2. JordanMarr commented on Apr 22, 2024

    @JordanMarr
    ContributorAuthor

    Ok, I see that now on your readme page.

    It looks like a workaround is to create a new type when necessary:

    image

    Just thinking out loud - would it be possible to add or override a ToString method on the generated folder interfaces to return the path?
    It would be intuitive, and would also allow this:

    type SlnRoot = RelativeFileSystem<"..">
    type Server = SlnRoot.``CEI.BimHub.WebApi``
    printfn $"Server path: {Server}"
  3. MangelMaxime commented on Apr 23, 2024

    @MangelMaxime
    Contributor

    It looks like a workaround is to create a new type when necessary:

    Indeed, this works because then VS intellisense doesn't deal with the double back tick.

    Just thinking out loud - would it be possible to add or override a ToString method on the generated folder interfaces to return the path?

    I guess it could be possible yes. I used ``.`` because it is the standard inode for referring to the current repository. At first I was thinking about FullName but there was a risk of conflict with an existing file on the disk. The ToString() method avoid that conflict from happening because a file/folder reference is represented using a property and not method.

    I will look into it.

  4. MangelMaxime commented on Apr 23, 2024

    @MangelMaxime
    Contributor

    @JordanMarr I am able to generate the ToString() method but it does not allow for syntax like printfn $"Server path: {Server}"

    See #4 for an experimentation about adding ToString()

    This is because type CurrentDirectoryDot = RelativeFileSystem<"."> is not an instantiated type but a type definition.

    From what I understand it is equivalent to something like that:

    type CurrentDirectoryDot =
            static member ``.`` : string = "/home/joe/tests/"
            static member ToString() = "/home/joe/tests/"

    Note

    I am not sure how the inner directories are represented

    If we want to allow something like printfn $"Server path: {Server}", I will need to switch the TP to use instantiated types.

    Usage would become something like that:

    let CurrentDirectoryDot = RelativeFileSystem<".">()

    I suppose should be possible to do, but I am not sure if there are any consequences or not. The way the TP works right now, is by provided all the strings using Literal field so I think it generate no types in the output.

    Would having ToString() has a static method for now works or do you think it is not enough and we should go directly with trying to use instantiated types?

    Having ToString() has a static method means that you are always expected to explicitly call it:

    CurrentDirectoryDot.ToString()

    We could also call it GetFullName() to stay consistent with .NET API naming:

    let myDir = DirectoryInfo("...")
    myDir.FullName
  5. changed the title [-]Generated type "not defined"[/-] [+]Add `ToString()` as an alias to ` ``.`` ` for getting an folder path[/+] on Apr 23, 2024
  6. changed the title [-]Add `ToString()` as an alias to ` ``.`` ` for getting an folder path[/-] [+]Add `ToString()` as an alias to ` ''.'' ` (dot inode) for getting an folder path[/+] on Apr 23, 2024
  7. changed the title [-]Add `ToString()` as an alias to ` ''.'' ` (dot inode) for getting an folder path[/-] [+]Add `ToString()` as an alias to ` ''.'' ` (dot inode) for getting a folder path[/+] on Apr 23, 2024
  8. JordanMarr commented on Apr 23, 2024

    @JordanMarr
    ContributorAuthor

    Interesting!
    While it would be cool to be able to use in string interpolation, redesigning the type provider sounds like a lot of work. On the other hand, having a ToString() static method would probably be pretty easy and I think would be worth doing.

  9. JordanMarr commented on Apr 23, 2024

    @JordanMarr
    ContributorAuthor

    I was also experimenting with this approach, just for fun, but I ran into a block:

    image

    But having a .ToString() method would be better.

  10. MangelMaxime commented on Apr 23, 2024

    @MangelMaxime
    Contributor

    Ok, for now I will add .ToString() or something equivalent as a static member.

    This is the fastest way to have something out, and because EasyBuild.FileSystemProvider is aimed at being used inside of build script I think it will be good enough for now (and probably a long time 🙈).

    Regarding the SRTP syntax, I am not 100% sure that the TP generate is a static member ``. `` But I suspect this is something like that.

    What the TP generates is a ProvidedField.Literal however what it means in create F# types I am not sure 😅. Perhaps it generates a static member val.

    Working on TP is kind of fun but this is a real blackbox to me, I just put code that seems to makes sense and test out the output in the test folder. I don't know if there is a way to look into the generate DLL to get the generated F# type. But I am going side ways here.

    Will add the . ToString() stuff later this evening or tomorrow.

  11. JordanMarr commented on Apr 23, 2024

    @JordanMarr
    ContributorAuthor

    This is a really cool type provider library. Thank you for making it!
    I've already updated one of my project's builds to use it.

  12. MangelMaxime commented on Apr 23, 2024

    @MangelMaxime
    Contributor

    I am glad you are liking it.

    For me this is already a game changer not having to deal with string and relative path anymore.

    This is the first stone of a new project aiming to make it easier to maintain any projects. For example, in this repository I am already auto generating the changelog based on the Git history and this is just SO nice to press a button and to have nothing special to do to make a release. The version is auto computed if I don't override it and the changelog file is auto generated too.

    I am working on making it a tool so it can be used on any project.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions