daml icon indicating copy to clipboard operation
daml copied to clipboard

`DA.Internal.Desugar` types show in IDE when hovering on certain parts of the source code

Open akrmn opened this issue 1 year ago • 3 comments

The problem here is that we use the location information in the DA-GHC AST for (at least) two purposes:

  • Providing error messages in LF conversion and typechecker.
  • Showing Daml Studio tooltips through daml-ghcide

These two conflict when it comes to the value bindings and class instances used for desugaring: we want them to have locations so the we can give helpful error messages, but we want them to not have locations so they don't show up in Daml Studio.

One possible approach would be to embed the location information into the type/class of the value bindings/class instances (so we can extract it in LF Conversion), while setting the SrcLoc of the binding/instance itself as UnhelpfulLoc (so they are ignored by daml-ghcide). For example, the class HasMethod, which currently looks like

class HasMethod i (m : Symbol) r | i m -> r

would now look like

data SrcLoc
    (startLine : Nat)
    (startCol : Nat)
    (endLine : Nat)
    (endCol : Nat)
  = SrcLoc {}

class HasMethod (loc : SrcLoc) i (m : Symbol) r | i m -> r loc

Alternatively, we could define SrcLoc as a class. That way, classes like HasMethod would stay the same, instead we would add SrcLoc constraints to the instances, e.g.

class SrcLoc
    (startLine : Nat)
    (startCol : Nat)
    (endLine : Nat)
    (endCol : Nat)

instance SrcLoc 20 5 21 30 => HasMethod MyInterface "myMethod" MyReturnType

akrmn avatar Aug 25 '22 11:08 akrmn

Two examples:

LeaksInterfaceView LeaksHasMethod

akrmn avatar Aug 30 '22 16:08 akrmn

I don’t think there is anything that directly corresponds to what you have here currently. We do have some precedence for doing slightly similar stuff here. The two things that come to mind are:

  1. Deemphasizing certain definitions in https://github.com/digital-asset/daml-ghcide/blob/d54267ac4ee420e31de7e387822a67df5ec58d99/src/Development/IDE/Spans/AtPoint.hs#L109. That is probably the closest to what you do.
  2. Filtering certain internal definitions in https://github.com/digital-asset/daml-ghcide/pull/11/files. Doesn’t quite match what you're doing but at least broadly the same category.

cocreature avatar Aug 31 '22 07:08 cocreature

Another example (thanks @basvangijzel-DA), this one pre-interfaces:

LeaksPartyConcat

This one is harder to spot because it only shows up when hovering on the comma.

akrmn avatar Aug 31 '22 11:08 akrmn