dotnet / dotnet/fsharp

RemoveUnusedBinding offers to remove unused parameters but doesn't remove them

Open
#11,741 4 comments 0 reactions 0 assignees View on GitHub
AI-thinks-windows-only Area-LangService-CodeFixes Bug good first issue
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

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

I think [this reported issue/feature gap](https://github.com/fsharp/FsAutoComplete/issues/811) in FSAC is reproducible in the VS tooling as well.

For the code:

```fsharp
let inc i =
2
```

with `--warnon:1182` enabled, there will be a diagnostic issued for the parameter `i`, but the [current codefix](https://github.com/dotnet/fsharp/blob/48e06db01c48fc01e382d7db5304ffb79725eef4/vsintegration/src/FSharp.Editor/CodeFix/RemoveUnusedBinding.fs) will not handle this scenario.

**Describe the solution you'd like**

I think a [small change](https://github.com/fsharp/FsAutoComplete/pull/812/files#diff-6e83d7b88f34d7f59884a533720e78dc4ecc5bc41f566309881b238e567abe3eR19-R66) to the [TryRangeOfBindingWithHeadPatternWithPos](https://github.com/dotnet/fsharp/blob/3a3fac2080e9b99eb30a97bd789ad456075a1aaf/vsintegration/src/FSharp.Editor/Common/FSharpCodeAnalysisExtensions.fs#L9) member could be made very similarly to what I've done in [this PR](https://github.com/fsharp/FsAutoComplete/pull/812), and the range that is derived from this member could be tagged as coming from a pattern or a binding.

Then, later in the codefix that result would be inspected to [walk the text in slightly different ways for patterns and bindings](https://github.com/fsharp/FsAutoComplete/pull/812/files#diff-6e83d7b88f34d7f59884a533720e78dc4ecc5bc41f566309881b238e567abe3eR78-R107), so that both kinds of triggering entities for this diagnostic could be handled.

**Describe alternatives you've considered**

Not doing this work, so that only nested bindings are removable.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.