haskell / haskell/haskell-language-server

Mark recursive references in let bindings

Open
#2,902 9 comments 5 reactions 0 assignees View on GitHub
component: semantic-tokens level: easy type: enhancement
Dominant language
Haskell
Stars
3k
Forks
455
Avg merge
2d 19h
Merged PRs (30d)
11

Description

**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:

```diff
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**

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.