-
Notifications
You must be signed in to change notification settings - Fork 847
[WIP] Fix brace matching for outer braces #3849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…the end of a brace
| // | ||
| // Ex: let x = ((12))^ | ||
| // | ||
| // The caret can be on the outside of the last paren, but this is actually 1 position |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't appear to be true at all
|
Maybe a test or two should be added to https://github.com/Microsoft/visualfsharp/blob/master/vsintegration/tests/unittests/BraceMatchingServiceTests.fs? |
| // | ||
| // The caret can be on the outside of the last paren, but this is actually 1 position | ||
| // further to the right than the end of the span that we get back. | ||
| range.Contains(caretPosition) || range.End = caretPosition + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be range.End = caretPosition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I originally thought, but it it results in the same behavior as #3794 (and the current implementation).
Changing to just range.Contains(caretPosition) fixes #3794 and also results the same behavior as the current implementation for #2092 (all cases except for let (| A9 |) and the caret being inside a brace pair result in highlighting).
Unfortunately, debugging this is a real mess. I think it has something to do with debugging CEs, but isPositionInRange is called twice as often as I would expect.
|
Actually @saul back to this comment: #2092 (comment) You fixed brace matching such that (given let x= ( 12 ^)Will match those braces. I don't think that's the correct thing to do. Given this: let x = ((12)^)It's not clear which brace should be highlighted. Roslyn throws out the outer pair and so the inner one is matched, but I'm not convinced that we should be giving them both pairs. Thoughts? |
|
I'm not entirely sure - does it really matter? I was just trying to fix the bug raised in #2092 which I agreed with. My change was to fix most of those issues, and to also fix the logic for auto-deindent (which I believe this PR breaks, looking at the tests) |
|
Not sure if it matters, but given that ambiguity I'm leaning towards not counting that case. What is a bit baffling is that all the test cases in let x = [ 1 .. 10 ]^And conversely, when I change it to |
|
@cartermp is this still valid? |
|
Yes. The current brace matching implementation doesn't work because of some weirdness with Roslyn calling us twice and passing different values. |
|
@cartermp There is a reason why it is passing two different values. http://source.roslyn.io/#Microsoft.CodeAnalysis.EditorFeatures/Implementation/BraceMatching/BraceHighlightingViewTaggerProvider.cs,77 This is intended behavior. To summarize, here is an example (C#): ()^()It will check the right side for a starting brace; if there is, it will match. (position) I also want to note that |
|
@TIHan if it's about reimplementing taggers I can help out here. Thanks to code lens I know too much about them. |
|
With regards to the API being internal - that's the case for, unfortunately, too many of the things we implement or override. The best thing is to help convince folks to make all the workspace APIs we deal with public so that we can get rid of the internalsvisibleto hack. |
|
Can the community help with convincing them? E.g. writing nice blog posts 😝? |
|
Not really, no. It's a big cost for a small team with a huge feature area to open them up right now. It affects more than just F#, though, so I'm hopeful we can get to it in 2018. |
|
Closing this, as there is likely to be more advanced logic required to fix this problem correctly. |


Fixes #3794
Not entirely sure if this is the right fix, but it certainly is a fix. It's really just the
range.Contains()call that fixes this, though.Needs test updates