Commit 5186901
Fix
The Copilot PR reviewer noticed that when two references share the same
range but have different non-null `Kind`s, `CompareTo` fell through to
`return -1` for both `a.CompareTo(b)` and `b.CompareTo(a)`. That violates
the `IComparable` antisymmetry contract and can yield unstable ordering in
`Array.Sort`.
We now order differing non-null kinds deterministically with
`string.CompareOrdinal` over their string representations (stable LSP
values like `comment` and `region`), so the two directions always have
opposite signs. The null-vs-kind cases are unchanged: a reference without
a kind still sorts after one that has a kind.
Added a test asserting the comparison is antisymmetric for differing kinds.
Drafted by Copilot (Claude Opus 4.8).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>FoldingReference.CompareTo antisymmetry for differing kinds1 parent a3f21b4 commit 5186901
2 files changed
Lines changed: 29 additions & 14 deletions
File tree
- src/PowerShellEditorServices/Services/TextDocument
- test/PowerShellEditorServices.Test/Language
Lines changed: 12 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
77 | 75 | | |
78 | 76 | | |
79 | 77 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
70 | 87 | | |
71 | 88 | | |
0 commit comments