haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

Mark recursive references in let bindings

Open roberth opened this issue 2 years ago • 9 comments

Is your feature request related to a problem? Please describe.

I just spent an hour debugging a hanging test, doubting my production code instead of checking the test code :facepalm:. If the recursive reference were highlighted, I would have found the mistake while writing the code.

For context, here's how it looked:

 do
-  let attr = r & findJust "hello attribute" \case EvaluateEvent.Attribute a | AttributeEvent.expressionPath attr == ["hello"] -> Just a; _ -> Nothing
+  let attr = r & findJust "hello attribute" \case EvaluateEvent.Attribute a | AttributeEvent.expressionPath a == ["hello"] -> Just a; _ -> Nothing
   evaluate attr -- debug hang

Describe the solution you'd like

Highlight recursive references with let exprs and let statements. I expect such a highlight to help with code understanding as well.

  let a = f a
            ^---- highlight this in IDE

Recursive references usually aren't mistakes, so the highlight should use a neutral style. Maybe underline it?

Ideally, the analysis also finds more indirect examples:

  let a = b
      b = g a
            ^---- highlight this in IDE

I suppose mutually recursive functions would also be highlighted by such an analysis. I don't know if this is desirable.

Describe alternatives you've considered

  • Build a cabin in the woods and earn with AirBnB.

  • Add non-recursive let to the language and change habits to use that instead. Keep making mistakes in library code that refuses to use it for compatibility reasons.

Additional context

roberth avatar May 11 '22 10:05 roberth

This is a cool idea. I'm not sure how we'd do it, though. Semantic highlighting, maybe? But we'd need a special token modifier, and I don't think it's easy to get that to work :thinking:

michaelpj avatar May 11 '22 21:05 michaelpj

We can use hie to get the recursive relation. Semantic highlighting looks very suitable, but needs some extra work indeed to adapt recursive definition. Maybe we can do it after we have the support of semantic highlighting.

July541 avatar May 16 '22 16:05 July541

How about diagnostic with information severity? https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnosticSeverity

July541 avatar May 16 '22 16:05 July541

I guess it could be a diagnostic. It feels noisy to put this information in there: it's going to clutter up people's diagnostic lists, and it's only something you care about occasionally, so that feels kind of bad?

michaelpj avatar May 16 '22 17:05 michaelpj

Yes, information severity is noisy indeed. Maybe we can use hint severity? it won't show in people's diagnostic lists, and it is a hint for users in a way.

July541 avatar May 17 '22 08:05 July541

@sloorush one to think about when we're thinking about semantic highlighting.

michaelpj avatar May 30 '22 14:05 michaelpj

cc @soulomoon , although I don't think there's a good token modifier for this, sadly.

michaelpj avatar Jan 16 '24 17:01 michaelpj

For the direct recursive case, it should be easy For the mutual recursive case, we might need to do a dependency graph. But there is a good chance such an analyze tool already exists, we can cache and use the analyzation?

soulomoon avatar Jan 16 '24 18:01 soulomoon

It's also not clear that there is any appropriate type or modifier to use here.

michaelpj avatar May 01 '24 12:05 michaelpj