Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite6c2a38

Browse files
vasily-kirichenkobrettfo
authored andcommitted
Make matched brace highlighting work exactly as in C# editor (#5049)
* make matched brace highlighting work exactly as in C# editor* fix tests* Add optional param for formatting* revert matching braces logic in FSharpEditorFormattingService* add missing test attributes* Revert "revert matching braces logic in FSharpEditorFormattingService"This reverts commit 5ddaba3a5433967bdb7ff67e77bfd312717b198e.
1 parent86661b6 commite6c2a38

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

‎vsintegration/src/FSharp.Editor/Formatting/BraceMatchingService.fs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespaceMicrosoft.VisualStudio.FSharp.Editor
44

5-
openSystem
65
openSystem.ComponentModel.Composition
76
openMicrosoft.CodeAnalysis.Editor
87
openMicrosoft.FSharp.Compiler.SourceCodeServices
8+
openSystem.Runtime.InteropServices
99

1010
[<ExportBraceMatcher(FSharpConstants.FSharpLanguageName)>]
1111
typeinternalFSharpBraceMatchingService
@@ -14,19 +14,21 @@ type internal FSharpBraceMatchingService
1414
checkerProvider: FSharpCheckerProvider,
1515
projectInfoManager: FSharpProjectOptionsManager
1616
)=
17-
1817

1918
static letdefaultUserOpName="BraceMatching"
2019

21-
static memberGetBraceMatchingResult(checker:FSharpChecker,sourceText,fileName,parsingOptions:FSharpParsingOptions,position:int,userOpName:string)=
20+
static memberGetBraceMatchingResult(checker:FSharpChecker,sourceText,fileName,parsingOptions:FSharpParsingOptions,position:int,userOpName:string,[<Optional; DefaultParameterValue(false)>]forFormatting:bool)=
2221
async{
2322
let!matchedBraces= checker.MatchBraces(fileName, sourceText.ToString(), parsingOptions, userOpName)
2423
letisPositionInRange range=
2524
match RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, range)with
2625
| None->false
27-
| Some range->
28-
letlength= position- range.Start
29-
length>=0&& length<= range.Length
26+
| Some span->
27+
if forFormattingthen
28+
letlength= position- span.Start
29+
length>=0&& length<= span.Length
30+
else
31+
span.Contains position
3032
return matchedBraces|> Array.tryFind(fun(left,right)-> isPositionInRange left|| isPositionInRange right)
3133
}
3234

‎vsintegration/src/FSharp.Editor/Formatting/EditorFormattingService.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type internal FSharpEditorFormattingService
5050
x.Tag<> FSharpTokenTag.LINE_COMMENT)
5151

5252
let!(left,right)=
53-
FSharpBraceMatchingService.GetBraceMatchingResult(checker, sourceText, filePath, parsingOptions, position,"FormattingService")
53+
FSharpBraceMatchingService.GetBraceMatchingResult(checker, sourceText, filePath, parsingOptions, position,"FormattingService", forFormatting=true)
5454

5555
if right.StartColumn= firstMeaningfulToken.LeftColumnthen
5656
// Replace the indentation on this line with the indentation of the left bracket

‎vsintegration/tests/UnitTests/BraceMatchingServiceTests.fs‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,23 @@ let main argv =
161161
0 // return an integer exit code"""
162162
this.VerifyBraceMatch(code,"(printfn",")endBrace")
163163

164-
[<TestCase("let a1 = [ 0 .. 100 ]",[|9;10;20;21|])>]
165-
[<TestCase("let a2 = [| 0 .. 100 |]",[|9;10;11;21;22;23|])>]
166-
[<TestCase("let a3 = <@ 0 @>",[|9;10;11;14;15;16|])>]
167-
[<TestCase("let a4 = <@@ 0 @@>",[|9;10;11;12;15;15;16;17|])>]
168-
[<TestCase("let a6 = ( () )",[|9;10;16;17|])>]
169-
[<TestCase("[<ReflectedDefinition>]\nlet a7 = 70",[|0;1;2;21;22;23|])>]
170-
[<TestCase("let a8 = seq { yield() }",[|13;14;23;24|])>]
171-
memberthis.BraceMatchingBothSides_Bug2092(fileContents:string,matchingPositions:int[])=
172-
// https://github.com/Microsoft/visualfsharp/issues/2092
164+
[<TestCase("let a1 = [ 0 .. 100 ]",[|9;20|])>]
165+
[<TestCase("let a2 = [| 0 .. 100 |]",[|9;10;22|])>]
166+
[<TestCase("let a3 = <@ 0 @>",[|9;10;15|])>]
167+
[<TestCase("let a4 = <@@ 0 @@>",[|9;10;11;15;16|])>]
168+
[<TestCase("let a6 = ( () )",[|9;16|])>]
169+
[<TestCase("[<ReflectedDefinition>]\nlet a7 = 70",[|0;1;22|])>]
170+
[<TestCase("let a8 = seq { yield() }",[|13;23|])>]
171+
memberthis.DoNotMatchOnInnerSide(fileContents:string,matchingPositions:int[])=
173172
letsourceText= SourceText.From(fileContents)
174-
175173
letparsingOptions,_= checker.GetParsingOptionsFromProjectOptions projectOptions
176-
matchingPositions
177-
|> Array.iter(fun position->
174+
175+
for positionin matchingPositionsdo
178176
match FSharpBraceMatchingService.GetBraceMatchingResult(checker, sourceText, fileName, parsingOptions, position,"UnitTest")|> Async.RunSynchronouslywith
179177
| Some_->()
180178
| None->
181179
match positionwith
182180
|0->""
183181
|_-> fileContents.[position-1]|> sprintf" (previous character '%c')"
184-
|> sprintf"Didn't find a matching brace at position '%d', character '%c'%s" position fileContents.[position]
182+
|> sprintf"Didn't find a matching brace at position '%d'%s" position
185183
|> Assert.Fail
186-
)

‎vsintegration/tests/UnitTests/IndentationServiceTests.fs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ while true do
170170
|> Array.map(fun(lineNumber,expectedIndentation)->
171171
( Some(expectedIndentation), lineNumber, autoIndentTemplate))
172172

173+
[<Test>]
173174
memberthis.TestIndentation()=
174175
for(expectedIndentation, lineNumber, template)in testCasesdo
175176
letsourceText= SourceText.From(template)
@@ -179,7 +180,8 @@ while true do
179180
match expectedIndentationwith
180181
| None-> Assert.IsTrue(actualIndentation.IsNone,"No indentation was expected at line {0}", lineNumber)
181182
| Some indentation-> Assert.AreEqual(expectedIndentation.Value, actualIndentation.Value,"Indentation on line {0} doesn't match", lineNumber)
182-
183+
184+
[<Test>]
183185
memberthis.TestAutoIndentation()=
184186
for(expectedIndentation, lineNumber, template)in autoIndentTestCasesdo
185187

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp