Skip to content

Commit 7599811

Browse files
author
Omar Tawfik
committed
Address PR comments
1 parent 25fe21c commit 7599811

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

vsintegration/src/FSharp.Editor/BraceMatchingService.fs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ open Microsoft.VisualStudio.Text.Tagging
2525
open Microsoft.FSharp.Compiler.Parser
2626
open Microsoft.FSharp.Compiler.SourceCodeServices
2727

28-
// TODO: add defines flags if available from project sites and files
28+
// FSROSLYNTODO: add defines flags if available from project sites and files
2929

3030
[<ExportBraceMatcher(FSharpCommonConstants.FSharpLanguageName)>]
3131
type internal FSharpBraceMatchingService() =
@@ -95,13 +95,16 @@ type internal FSharpBraceMatchingService() =
9595
member this.FindBracesAsync(document: Document, position: int, cancellationToken: CancellationToken): Task<Nullable<BraceMatchingResult>> =
9696
document.GetTextAsync(cancellationToken).ContinueWith(
9797
fun (sourceTextTask: Task<SourceText>) ->
98-
try match getBraceMatchingResult(sourceTextTask.Result, Some(document.Name), [], position, cancellationToken) with
99-
| None -> Nullable()
100-
| Some(braceMatchingResult) -> Nullable(braceMatchingResult)
101-
with ex ->
102-
Assert.Exception(ex)
103-
reraise()
104-
, TaskContinuationOptions.OnlyOnRanToCompletion)
98+
if sourceTextTask.Status = TaskStatus.RanToCompletion then
99+
try match getBraceMatchingResult(sourceTextTask.Result, Some(document.Name), [], position, cancellationToken) with
100+
| None -> Nullable()
101+
| Some(braceMatchingResult) -> Nullable(braceMatchingResult)
102+
with ex ->
103+
Assert.Exception(ex)
104+
reraise()
105+
else
106+
raise(sourceTextTask.Exception.GetBaseException())
107+
, cancellationToken)
105108

106109
// Helper function to proxy Roslyn types to tests
107110
static member FindMatchingBrace(sourceText: SourceText, fileName: Option<string>, defines: string list, position: int, cancellationToken: CancellationToken) : Option<int> =

vsintegration/src/FSharp.Editor/ColorizationService.fs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ open Microsoft.VisualStudio.Text.Tagging
2525

2626
open Microsoft.FSharp.Compiler.SourceCodeServices
2727

28-
// TODO: add types colorization if available from intellisense
29-
// TODO: add defines flags if available from project sites and files
28+
// FSROSLYNTODO: add types colorization if available from intellisense
29+
// FSROSLYNTODO: add defines flags if available from project sites and files
3030

3131
type private SourceLineData(lexStateAtEndOfLine: FSharpTokenizerLexState, hashCode: int, classifiedSpans: IReadOnlyList<ClassifiedSpan>) =
3232
member val LexStateAtEndOfLine = lexStateAtEndOfLine
@@ -97,15 +97,17 @@ type internal FSharpColorizationService() =
9797
member this.AddSyntacticClassificationsAsync(document: Document, textSpan: TextSpan, result: List<ClassifiedSpan>, cancellationToken: CancellationToken) =
9898
document.GetTextAsync(cancellationToken).ContinueWith(
9999
fun (sourceTextTask: Task<SourceText>) ->
100-
result.AddRange(FSharpColorizationService.GetColorizationData(sourceTextTask.Result, textSpan, None, [], cancellationToken))
101-
, TaskContinuationOptions.OnlyOnRanToCompletion)
100+
if sourceTextTask.Status = TaskStatus.RanToCompletion then
101+
result.AddRange(FSharpColorizationService.GetColorizationData(sourceTextTask.Result, textSpan, None, [], cancellationToken))
102+
, cancellationToken)
102103

103104
member this.AddSemanticClassificationsAsync(document: Document, textSpan: TextSpan, result: List<ClassifiedSpan>, cancellationToken: CancellationToken) =
104105
document.GetTextAsync(cancellationToken).ContinueWith(
105106
fun (sourceTextTask: Task<SourceText>) ->
106-
//TODO: Replace with types data when available from intellisense (behaving as AddSyntacticClassificationsAsync() for now)
107-
result.AddRange(FSharpColorizationService.GetColorizationData(sourceTextTask.Result, textSpan, None, [], cancellationToken))
108-
, TaskContinuationOptions.OnlyOnRanToCompletion)
107+
if sourceTextTask.Status = TaskStatus.RanToCompletion then
108+
//FSROSLYNTODO: Replace with types data when available from intellisense (behaving as AddSyntacticClassificationsAsync() for now)
109+
result.AddRange(FSharpColorizationService.GetColorizationData(sourceTextTask.Result, textSpan, None, [], cancellationToken))
110+
, cancellationToken)
109111

110112
member this.AdjustStaleClassification(text: SourceText, classifiedSpan: ClassifiedSpan) : ClassifiedSpan =
111113
let tokens = FSharpColorizationService.GetColorizationData(text, classifiedSpan.TextSpan, None, [], CancellationToken.None)

vsintegration/src/FSharp.Editor/IndentationService.fs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,20 @@ type internal FSharpIndentationService() =
4646
| _ -> spaces
4747
Some(loop 0 0)
4848

49+
// FSROSLYNTODO: post beta5, update implementation to use ISynchronousIndentationService instead to guarentee Indentation is UI-blocking
4950
interface IIndentationService with
5051
member this.GetDesiredIndentationAsync(document: Document, lineNumber: int, cancellationToken: CancellationToken): Task<Nullable<IndentationResult>> =
5152
document.GetTextAsync(cancellationToken).ContinueWith(
5253
fun (sourceTextTask: Task<SourceText>) ->
53-
let tabSize = document.Project.Solution.Workspace.Options.GetOption(FormattingOptions.TabSize, FSharpCommonConstants.FSharpLanguageName)
54-
try match FSharpIndentationService.GetDesiredIndentation(sourceTextTask.Result, lineNumber, tabSize) with
55-
| None -> Nullable<IndentationResult>()
56-
| Some(indentation) -> Nullable<IndentationResult>(IndentationResult(sourceTextTask.Result.Lines.[lineNumber].Start, indentation))
57-
with ex ->
58-
Assert.Exception(ex)
59-
reraise()
60-
, TaskContinuationOptions.OnlyOnRanToCompletion)
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)

0 commit comments

Comments
 (0)