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

Bug: type info broken #112

Closed
rvion opened this issue Jul 19, 2016 · 8 comments
Closed

Bug: type info broken #112

rvion opened this issue Jul 19, 2016 · 8 comments

Comments

@rvion
Copy link

rvion commented Jul 19, 2016

context:

  • on one of my purescript projects, I decided to always use structural subtyping unless I needed type unions or class instances. But, quickly, it became annoying:
    • type at the bottom of the autocompletion popup for my functions started to take the whole space available on screen and is were so long that it became impossible for me to understand them at a glance (arrows were lost in the middle of too much noise).
    • type on hover tooltip was also too long and move outside of the screen

so, I decided to fix those 2 issues and implement

  • some type parsing
  • some type formatting (lines , colors, etc)
  • some recursive record folding (from deepest record, until the whole expression is small enough, etc.)

🍏 I got a prototype working fine (on top, the new version, at the bottom, the old version):
image

🔶 except for one expression 😠

image

I thought my code was buggy, so I added some html escaping, but nothing worked.

🔴 Then, I saw that the original type tooltip was buggy too on raw atom-ide-purescript:
Indeed, if you look at the beginning of the expression, you can see that brackets don't close properly:
image

so I checked pulp psci
🔴 🔴 and then I got this.

> import GM.Scene
> :t instance_create
forall a m.
  (MonadState { elems :: Array                                 m) => { x :: Number
                           (Maybe                                    , y :: Number
                              { obj :: { x :: Number                 , vx :: Number
                                       , y :: Number                 , vy :: Number
                                       , vx :: Number                , mask :: { x :: Number
                                       , vy :: Number                          , y :: Number
                                       , mask :: { x :: Number                 , w :: Number
                                                 , y :: Number                 , h :: Number
                                                 , w :: Number                 }
                                                 , h :: Number       , obj :: a
                                                 }                   }
                                       , obj :: a                    -> m Unit
                                       }
                              , uid :: Int
                              }
                           )
              , next_uid :: Int
              }

So I guess the bug is a bit more serious than just atom-ide-purescript

/cc
@kritzcreek
@nwolverson

here is the buggy function

-- dumb scene manager instance creation with O(N^2) brodaphase
instance_create  :: forall a m. (MonadState (Scene a) m) => Stuff a -> m Unit
instance_create o = do
  modify \(f :: Scene a) -> f {
     elems = snoc f.elems (Just {obj: o, uid: f.next_uid}),
     next_uid = f.next_uid + 1
  }
```purescript

here is the result of my externs.json file from output folder

```json
{
  "EDValue": {
    "edValueName": {
      "Ident": "instance_create"
    },
    "edValueType": {
      "tag": "ForAll",
      "contents": [
        "m",
        {
          "tag": "ForAll",
          "contents": [
            "a",
            {
              "tag": "ConstrainedType",
              "contents": [
                [
                  {
                    "constraintClass": [
                      [
                        "Control",
                        "Monad",
                        "State",
                        "Class"
                      ],
                      "MonadState"
                    ],
                    "constraintArgs": [
                      {
                        "tag": "TypeApp",
                        "contents": [
                          {
                            "tag": "TypeConstructor",
                            "contents": [
                              [
                                "Prim"
                              ],
                              "Record"
                            ]
                          },
                          {
                            "tag": "RCons",
                            "contents": [
                              "elems",
                              {
                                "tag": "TypeApp",
                                "contents": [
                                  {
                                    "tag": "TypeConstructor",
                                    "contents": [
                                      [
                                        "Prim"
                                      ],
                                      "Array"
                                    ]
                                  },
                                  {
                                    "tag": "TypeApp",
                                    "contents": [
                                      {
                                        "tag": "TypeConstructor",
                                        "contents": [
                                          [
                                            "Data",
                                            "Maybe"
                                          ],
                                          "Maybe"
                                        ]
                                      },
                                      {
                                        "tag": "TypeApp",
                                        "contents": [
                                          {
                                            "tag": "TypeConstructor",
                                            "contents": [
                                              [
                                                "Prim"
                                              ],
                                              "Record"
                                            ]
                                          },
                                          {
                                            "tag": "RCons",
                                            "contents": [
                                              "obj",
                                              {
                                                "tag": "TypeApp",
                                                "contents": [
                                                  {
                                                    "tag": "TypeConstructor",
                                                    "contents": [
                                                      [
                                                        "Prim"
                                                      ],
                                                      "Record"
                                                    ]
                                                  },
                                                  {
                                                    "tag": "RCons",
                                                    "contents": [
                                                      "x",
                                                      {
                                                        "tag": "TypeConstructor",
                                                        "contents": [
                                                          [
                                                            "Prim"
                                                          ],
                                                          "Number"
                                                        ]
                                                      },
                                                      {
                                                        "tag": "RCons",
                                                        "contents": [
                                                          "y",
                                                          {
                                                            "tag": "TypeConstructor",
                                                            "contents": [
                                                              [
                                                                "Prim"
                                                              ],
                                                              "Number"
                                                            ]
                                                          },
                                                          {
                                                            "tag": "RCons",
                                                            "contents": [
                                                              "vx",
                                                              {
                                                                "tag": "TypeConstructor",
                                                                "contents": [
                                                                  [
                                                                    "Prim"
                                                                  ],
                                                                  "Number"
                                                                ]
                                                              },
                                                              {
                                                                "tag": "RCons",
                                                                "contents": [
                                                                  "vy",
                                                                  {
                                                                    "tag": "TypeConstructor",
                                                                    "contents": [
                                                                      [
                                                                        "Prim"
                                                                      ],
                                                                      "Number"
                                                                    ]
                                                                  },
                                                                  {
                                                                    "tag": "RCons",
                                                                    "contents": [
                                                                      "mask",
                                                                      {
                                                                        "tag": "TypeApp",
                                                                        "contents": [
                                                                          {
                                                                            "tag": "TypeConstructor",
                                                                            "contents": [
                                                                              [
                                                                                "Prim"
                                                                              ],
                                                                              "Record"
                                                                            ]
                                                                          },
                                                                          {
                                                                            "tag": "RCons",
                                                                            "contents": [
                                                                              "x",
                                                                              {
                                                                                "tag": "TypeConstructor",
                                                                                "contents": [
                                                                                  [
                                                                                    "Prim"
                                                                                  ],
                                                                                  "Number"
                                                                                ]
                                                                              },
                                                                              {
                                                                                "tag": "RCons",
                                                                                "contents": [
                                                                                  "y",
                                                                                  {
                                                                                    "tag": "TypeConstructor",
                                                                                    "contents": [
                                                                                      [
                                                                                        "Prim"
                                                                                      ],
                                                                                      "Number"
                                                                                    ]
                                                                                  },
                                                                                  {
                                                                                    "tag": "RCons",
                                                                                    "contents": [
                                                                                      "w",
                                                                                      {
                                                                                        "tag": "TypeConstructor",
                                                                                        "contents": [
                                                                                          [
                                                                                            "Prim"
                                                                                          ],
                                                                                          "Number"
                                                                                        ]
                                                                                      },
                                                                                      {
                                                                                        "tag": "RCons",
                                                                                        "contents": [
                                                                                          "h",
                                                                                          {
                                                                                            "tag": "TypeConstructor",
                                                                                            "contents": [
                                                                                              [
                                                                                                "Prim"
                                                                                              ],
                                                                                              "Number"
                                                                                            ]
                                                                                          },
                                                                                          {
                                                                                            "tag": "REmpty",
                                                                                            "contents": []
                                                                                          }
                                                                                        ]
                                                                                      }
                                                                                    ]
                                                                                  }
                                                                                ]
                                                                              }
                                                                            ]
                                                                          }
                                                                        ]
                                                                      },
                                                                      {
                                                                        "tag": "RCons",
                                                                        "contents": [
                                                                          "obj",
                                                                          {
                                                                            "tag": "TypeVar",
                                                                            "contents": "a"
                                                                          },
                                                                          {
                                                                            "tag": "REmpty",
                                                                            "contents": []
                                                                          }
                                                                        ]
                                                                      }
                                                                    ]
                                                                  }
                                                                ]
                                                              }
                                                            ]
                                                          }
                                                        ]
                                                      }
                                                    ]
                                                  }
                                                ]
                                              },
                                              {
                                                "tag": "RCons",
                                                "contents": [
                                                  "uid",
                                                  {
                                                    "tag": "TypeConstructor",
                                                    "contents": [
                                                      [
                                                        "Prim"
                                                      ],
                                                      "Int"
                                                    ]
                                                  },
                                                  {
                                                    "tag": "REmpty",
                                                    "contents": []
                                                  }
                                                ]
                                              }
                                            ]
                                          }
                                        ]
                                      }
                                    ]
                                  }
                                ]
                              },
                              {
                                "tag": "RCons",
                                "contents": [
                                  "next_uid",
                                  {
                                    "tag": "TypeConstructor",
                                    "contents": [
                                      [
                                        "Prim"
                                      ],
                                      "Int"
                                    ]
                                  },
                                  {
                                    "tag": "REmpty",
                                    "contents": []
                                  }
                                ]
                              }
                            ]
                          }
                        ]
                      },
                      {
                        "tag": "TypeVar",
                        "contents": "m"
                      }
                    ],
                    "constraintData": null
                  }
                ],
                {
                  "tag": "TypeApp",
                  "contents": [
                    {
                      "tag": "TypeApp",
                      "contents": [
                        {
                          "tag": "TypeConstructor",
                          "contents": [
                            [
                              "Prim"
                            ],
                            "Function"
                          ]
                        },
                        {
                          "tag": "TypeApp",
                          "contents": [
                            {
                              "tag": "TypeConstructor",
                              "contents": [
                                [
                                  "Prim"
                                ],
                                "Record"
                              ]
                            },
                            {
                              "tag": "RCons",
                              "contents": [
                                "x",
                                {
                                  "tag": "TypeConstructor",
                                  "contents": [
                                    [
                                      "Prim"
                                    ],
                                    "Number"
                                  ]
                                },
                                {
                                  "tag": "RCons",
                                  "contents": [
                                    "y",
                                    {
                                      "tag": "TypeConstructor",
                                      "contents": [
                                        [
                                          "Prim"
                                        ],
                                        "Number"
                                      ]
                                    },
                                    {
                                      "tag": "RCons",
                                      "contents": [
                                        "vx",
                                        {
                                          "tag": "TypeConstructor",
                                          "contents": [
                                            [
                                              "Prim"
                                            ],
                                            "Number"
                                          ]
                                        },
                                        {
                                          "tag": "RCons",
                                          "contents": [
                                            "vy",
                                            {
                                              "tag": "TypeConstructor",
                                              "contents": [
                                                [
                                                  "Prim"
                                                ],
                                                "Number"
                                              ]
                                            },
                                            {
                                              "tag": "RCons",
                                              "contents": [
                                                "mask",
                                                {
                                                  "tag": "TypeApp",
                                                  "contents": [
                                                    {
                                                      "tag": "TypeConstructor",
                                                      "contents": [
                                                        [
                                                          "Prim"
                                                        ],
                                                        "Record"
                                                      ]
                                                    },
                                                    {
                                                      "tag": "RCons",
                                                      "contents": [
                                                        "x",
                                                        {
                                                          "tag": "TypeConstructor",
                                                          "contents": [
                                                            [
                                                              "Prim"
                                                            ],
                                                            "Number"
                                                          ]
                                                        },
                                                        {
                                                          "tag": "RCons",
                                                          "contents": [
                                                            "y",
                                                            {
                                                              "tag": "TypeConstructor",
                                                              "contents": [
                                                                [
                                                                  "Prim"
                                                                ],
                                                                "Number"
                                                              ]
                                                            },
                                                            {
                                                              "tag": "RCons",
                                                              "contents": [
                                                                "w",
                                                                {
                                                                  "tag": "TypeConstructor",
                                                                  "contents": [
                                                                    [
                                                                      "Prim"
                                                                    ],
                                                                    "Number"
                                                                  ]
                                                                },
                                                                {
                                                                  "tag": "RCons",
                                                                  "contents": [
                                                                    "h",
                                                                    {
                                                                      "tag": "TypeConstructor",
                                                                      "contents": [
                                                                        [
                                                                          "Prim"
                                                                        ],
                                                                        "Number"
                                                                      ]
                                                                    },
                                                                    {
                                                                      "tag": "REmpty",
                                                                      "contents": []
                                                                    }
                                                                  ]
                                                                }
                                                              ]
                                                            }
                                                          ]
                                                        }
                                                      ]
                                                    }
                                                  ]
                                                },
                                                {
                                                  "tag": "RCons",
                                                  "contents": [
                                                    "obj",
                                                    {
                                                      "tag": "TypeVar",
                                                      "contents": "a"
                                                    },
                                                    {
                                                      "tag": "REmpty",
                                                      "contents": []
                                                    }
                                                  ]
                                                }
                                              ]
                                            }
                                          ]
                                        }
                                      ]
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "tag": "TypeApp",
                      "contents": [
                        {
                          "tag": "TypeVar",
                          "contents": "m"
                        },
                        {
                          "tag": "TypeConstructor",
                          "contents": [
                            [
                              "Data",
                              "Unit"
                            ],
                            "Unit"
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            48
          ]
        },
        49
      ]
    }
  }
}
@nwolverson
Copy link
Owner

This probably derives from the compiler's use of boxes to format types. If the type is incorrectly printed in psci you should open a compiler issue if there isn't one already. I'm not sure it's technically incorrect, it's just vertically formatted, but I really find this formatting unhelpful and hard to read.

To be honest it's probably not ideal that the types passed to the editor plugin are formatted with boxes, unless we want to preserve that formatting.

To improve tooltips, I think the first thing that would help is type aliases being preserved in the compiler (known issue), then a separate Atom package that provides for better formatted tooltips (current one I use just takes in text). I'd use the standard Atom syntax highlighting for PureScript within the tooltip if we can.

@rvion
Copy link
Author

rvion commented Jul 19, 2016

If the type is incorrectly printed in psci you should open a compiler issue if there isn't one already.

👍 I have to leave within a minute. I'll open an issue if nobody did it when I get back or tomorrow.

it's just vertically formatted, but I really find this formatting unhelpful and hard to read.

me too

To be honest it's probably not ideal that the types passed to the editor plugin are formatted with boxes, unless we want to preserve that formatting.

👍

To improve tooltips, I think the first thing that would help is type aliases being preserved in the compiler (known issue)

big 👍

then a separate Atom package that provides for better formatted tooltips (current one I use just takes in text). I'd use the standard Atom syntax highlighting for PureScript within the tooltip if we can.

I saw that. My fork was mostly temporary. I'll clean the code and open a PR if you consider merging it as an temporary optional type formatting option, but I know that it's more a hack than anything (this being said, it saves me time already)

@rvion
Copy link
Author

rvion commented Jul 19, 2016

btw, it also break the quickfix feature when one try to automatically add type signature

@kritzcreek
Copy link
Contributor

I didn't know about the side by side thing... The reason the tooltip is messed up, is that I use the compiler's pretty printer and then join all the lines removing trailing whitespace. That of course doesn't work with side by side things

@nwolverson
Copy link
Owner

Per discussion on the linked issue that's not intentional. But your comment that you join all the lines indicates that "we should preserve the pretty printed output" doesn't have as much weight as I thought. I thought the whitespace was being dropped on the editor side.

@kritzcreek
Copy link
Contributor

I originally decided to do so, becasuse I wanted to show the type in emacs's message buffer which is annoying if it gets bigger then 3 lines. But I also think the same goes for the type popups here, adding a bunch of whitespace makes them very intrusive.

@rvion
Copy link
Author

rvion commented Dec 30, 2016

I think that this one is fixed

@rvion rvion closed this as completed Dec 30, 2016
@nwolverson
Copy link
Owner

@rvion thanks

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