daml
daml copied to clipboard
`DA.Internal.Desugar` types show in IDE when hovering on certain parts of the source code
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
Two examples:
![LeaksInterfaceView](https://user-images.githubusercontent.com/6054733/187492573-3e2dcaef-d83f-4e20-a171-2150931932ef.png)
![LeaksHasMethod](https://user-images.githubusercontent.com/6054733/187492584-a5bf2c38-fc9e-4025-a47c-20f7b6b162d8.png)
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:
- 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.
- 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.
Another example (thanks @basvangijzel-DA), this one pre-interfaces:
This one is harder to spot because it only shows up when hovering on the comma.