Commit a3f21b4
Drop unused
We had silenced CA1067 (types implementing `IEquatable<T>` without overriding
`object.Equals`/`GetHashCode`) instead of fixing it. Promote it to `error` and
resolve the offenders at the root.
The four wrapper structs in `EditorFileRanges.cs` — `OmnisharpLspPosition`,
`OmnisharpLspRange`, `BufferFilePosition`, and `BufferFileRange` — are
`internal`, only ever surfaced through their interfaces
(`ILspFilePosition`/`IFileRange`/etc.), and never compared anywhere. Their
`IEquatable<T>` (added reflexively in #1183) was dead code, and the parallel
public classes (`FilePosition`/`LspFilePosition`/...) never implemented it. So
rather than completing the contract with `Equals(object)`/`GetHashCode`/
operators, I dropped `IEquatable<T>` and the typed `Equals` entirely — less
code, and CA1067 no longer applies to them. OmniSharp can't reach them either:
they're `internal` (unnameable for any generic equality), `InternalsVisibleTo`
lists only first-party assemblies, and the `ToOmnisharp*` conversions hand back
OmniSharp's own types, so an instance never flows back into the library.
`FoldingReference` is the one type that genuinely participates in comparison
(`Array.Sort` via `SafeAdd`, and xUnit `Assert.Equal` in the folding tests), so
it keeps `IEquatable`/`IComparable` and gets the real fix:
- `Equals(FoldingReference other)` was `=> CompareTo(other) == 0`, and
`CompareTo` dereferences its argument, so `Equals(null)` and `CompareTo(null)`
threw a `NullReferenceException` instead of returning `false`/`1`. Both are
now null-safe.
- Added `Equals(object)` and a netstandard2.0-compatible `GetHashCode` (manual
XOR, since `System.HashCode` is unavailable on that target).
Added focused tests covering the `FoldingReference` null-safety, value equality,
and hash-code consistency.
Drafted by Copilot (Claude Opus 4.8).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>IEquatable from range wrappers and fix FoldingReference
1 parent 40cf5e1 commit a3f21b4
4 files changed
Lines changed: 89 additions & 22 deletions
File tree
- src/PowerShellEditorServices
- Extensions
- Services/TextDocument
- test/PowerShellEditorServices.Test/Language
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
Lines changed: 4 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
277 | | - | |
| 277 | + | |
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
| |||
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | | - | |
287 | | - | |
288 | 286 | | |
289 | 287 | | |
290 | | - | |
| 288 | + | |
291 | 289 | | |
292 | 290 | | |
293 | 291 | | |
| |||
296 | 294 | | |
297 | 295 | | |
298 | 296 | | |
299 | | - | |
300 | | - | |
301 | 297 | | |
302 | 298 | | |
303 | | - | |
| 299 | + | |
304 | 300 | | |
305 | 301 | | |
306 | 302 | | |
| |||
309 | 305 | | |
310 | 306 | | |
311 | 307 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | 308 | | |
319 | 309 | | |
320 | | - | |
| 310 | + | |
321 | 311 | | |
322 | 312 | | |
323 | 313 | | |
| |||
326 | 316 | | |
327 | 317 | | |
328 | 318 | | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | 319 | | |
336 | 320 | | |
337 | 321 | | |
| |||
Lines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| |||
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
76 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
77 | 89 | | |
78 | 90 | | |
79 | 91 | | |
| |||
Lines changed: 71 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
0 commit comments