Skip to content

Commit e209336

Browse files
author
Omar Tawfik
committed
Address PR comments
1 parent e7813d0 commit e209336

File tree

6 files changed

+25
-37
lines changed

6 files changed

+25
-37
lines changed

vsintegration/src/FSharp.Editor/BraceMatchingService.fs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,5 @@ type internal FSharpBraceMatchingService() =
3535
CommonRoslynHelpers.FSharpRangeToTextSpan(sourceText, right)))
3636
}
3737

38-
Async.StartAsTask(computation, TaskCreationOptions.None, cancellationToken).ContinueWith(fun(task: Task<Nullable<BraceMatchingResult>>) ->
39-
if task.Status = TaskStatus.RanToCompletion then
40-
task.Result
41-
else
42-
Assert.Exception(task.Exception.GetBaseException())
43-
raise(task.Exception.GetBaseException())
44-
, cancellationToken)
38+
Async.StartAsTask(computation, TaskCreationOptions.None, cancellationToken)
39+
.ContinueWith(CommonRoslynHelpers.GetCompletedTaskResult, cancellationToken)

vsintegration/src/FSharp.Editor/BreakpointResolutionService.fs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,8 @@ type internal FSharpBreakpointResolutionService() =
5353
| Some(range) -> BreakpointResolutionResult.CreateSpanResult(document, CommonRoslynHelpers.FSharpRangeToTextSpan(sourceText, range))
5454
}
5555

56-
Async.StartAsTask(computation, TaskCreationOptions.None, cancellationToken).ContinueWith(fun(task: Task<BreakpointResolutionResult>) ->
57-
if task.Status = TaskStatus.RanToCompletion then
58-
task.Result
59-
else
60-
Assert.Exception(task.Exception.GetBaseException())
61-
raise(task.Exception.GetBaseException())
62-
, cancellationToken)
56+
Async.StartAsTask(computation, TaskCreationOptions.None, cancellationToken)
57+
.ContinueWith(CommonRoslynHelpers.GetCompletedTaskResult, cancellationToken)
6358

6459
// FSROSLYNTODO: enable placing breakpoints by when user suplies fully-qualified function names
6560
member this.ResolveBreakpointsAsync(_, _, _): Task<IEnumerable<BreakpointResolutionResult>> =

vsintegration/src/FSharp.Editor/IndentationService.fs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,11 @@ type internal FSharpIndentationService() =
4949
// FSROSLYNTODO: post beta5, update implementation to use ISynchronousIndentationService instead to guarentee Indentation is UI-blocking
5050
interface IIndentationService with
5151
member this.GetDesiredIndentationAsync(document: Document, lineNumber: int, cancellationToken: CancellationToken): Task<Nullable<IndentationResult>> =
52-
document.GetTextAsync(cancellationToken).ContinueWith(
53-
fun (sourceTextTask: Task<SourceText>) ->
54-
if sourceTextTask.Status = TaskStatus.RanToCompletion then
55-
// FSROSLYNTODO: post beta5, update to use document.Options.GetOption() instead
56-
let tabSize = document.Project.Solution.Workspace.Options.GetOption(FormattingOptions.TabSize, FSharpCommonConstants.FSharpLanguageName)
57-
try match FSharpIndentationService.GetDesiredIndentation(sourceTextTask.Result, lineNumber, tabSize) with
58-
| None -> Nullable<IndentationResult>()
59-
| Some(indentation) -> Nullable<IndentationResult>(IndentationResult(sourceTextTask.Result.Lines.[lineNumber].Start, indentation))
60-
with ex ->
61-
Assert.Exception(ex)
62-
reraise()
63-
else
64-
raise(sourceTextTask.Exception.GetBaseException())
65-
, cancellationToken)
52+
document.GetTextAsync(cancellationToken).ContinueWith(fun (sourceTextTask: Task<SourceText>) ->
53+
let sourceText = CommonRoslynHelpers.GetCompletedTaskResult(sourceTextTask)
54+
// FSROSLYNTODO: post beta5, update to use document.Options.GetOption() instead
55+
let tabSize = document.Project.Solution.Workspace.Options.GetOption(FormattingOptions.TabSize, FSharpCommonConstants.FSharpLanguageName)
56+
match FSharpIndentationService.GetDesiredIndentation(sourceText, lineNumber, tabSize) with
57+
| None -> Nullable<IndentationResult>()
58+
| Some(indentation) -> Nullable<IndentationResult>(IndentationResult(sourceText.Lines.[lineNumber].Start, indentation))
59+
, cancellationToken)

vsintegration/src/FSharp.Editor/LanguageDebugInfoService.fs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,8 @@ type internal FSharpLanguageDebugInfoService() =
7474
| None -> Unchecked.defaultof<DebugDataTipInfo>
7575
| Some(textSpan) -> new DebugDataTipInfo(textSpan, sourceText.GetSubText(textSpan).ToString())
7676
}
77-
78-
Async.StartAsTask(computation, TaskCreationOptions.None, cancellationToken).ContinueWith(fun(task: Task<DebugDataTipInfo>) ->
79-
if task.Status = TaskStatus.RanToCompletion then
80-
task.Result
81-
else
82-
Assert.Exception(task.Exception.GetBaseException())
83-
raise(task.Exception.GetBaseException())
84-
, cancellationToken)
77+
78+
Async.StartAsTask(computation, TaskCreationOptions.None, cancellationToken)
79+
.ContinueWith(CommonRoslynHelpers.GetCompletedTaskResult, cancellationToken)
80+
8581

vsintegration/src/FSharp.LanguageService/CommonRoslynHelpers.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Microsoft.VisualStudio.FSharp.LanguageService
44

55
open System
6+
open System.Threading.Tasks
67
open Microsoft.CodeAnalysis
78
open Microsoft.CodeAnalysis.Text
89
open Microsoft.FSharp.Compiler.SourceCodeServices
@@ -35,3 +36,10 @@ module internal CommonRoslynHelpers =
3536
let startPosition = sourceText.Lines.[range.StartLine - 1].Start + range.StartColumn
3637
let endPosition = sourceText.Lines.[range.EndLine - 1].Start + range.EndColumn
3738
TextSpan(startPosition, endPosition - startPosition)
39+
40+
let GetCompletedTaskResult(task: Task<'TResult>) =
41+
if task.Status = TaskStatus.RanToCompletion then
42+
task.Result
43+
else
44+
Assert.Exception(task.Exception.GetBaseException())
45+
raise(task.Exception.GetBaseException())

vsintegration/src/FSharp.LanguageService/FSharp.LanguageService.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
<EmbeddedResource Include="VSPackage.resx" />
5252
<EmbeddedResource Include="FSLangSvcStrings.resx" />
5353
<Compile Include="AssemblyInfo.fs" />
54+
<Compile Include="Error.fs" />
5455
<Compile Include="CommonConstants.fs" />
5556
<Compile Include="CommonRoslynHelpers.fs" />
56-
<Compile Include="Error.fs" />
5757
<Compile Include="Quickparse.fs" />
5858
<Compile Include="Vs.fs" />
5959
<Compile Include="Colorize.fs" />

0 commit comments

Comments
 (0)