Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Using shim for document highlights service
  • Loading branch information
TIHan committed May 8, 2019
commit 5924f70747b8b5937150c2ef3408fe36c3ce4189
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.DocumentHighlighting
open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.DocumentHighlighting

open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.Range
Expand All @@ -20,8 +21,7 @@ type internal FSharpHighlightSpan =
TextSpan: TextSpan }
override this.ToString() = sprintf "%+A" this

[<Shared>]
[<ExportLanguageService(typeof<IDocumentHighlightsService>, FSharpConstants.FSharpLanguageName)>]
[<Export(typeof<IFSharpDocumentHighlightsService>)>]
type internal FSharpDocumentHighlightsService [<ImportingConstructor>] (checkerProvider: FSharpCheckerProvider, projectInfoManager: FSharpProjectOptionsManager) =

static let userOpName = "DocumentHighlights"
Expand Down Expand Up @@ -72,8 +72,8 @@ type internal FSharpDocumentHighlightsService [<ImportingConstructor>] (checkerP
|> fixInvalidSymbolSpans sourceText symbol.Ident.idText
}

interface IDocumentHighlightsService with
member __.GetDocumentHighlightsAsync(document, position, _documentsToSearch, cancellationToken) : Task<ImmutableArray<DocumentHighlights>> =
interface IFSharpDocumentHighlightsService with
member __.GetDocumentHighlightsAsync(document, position, _documentsToSearch, cancellationToken) : Task<ImmutableArray<FSharpDocumentHighlights>> =
asyncMaybe {
let! parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document, cancellationToken)
let! sourceText = document.GetTextAsync(cancellationToken)
Expand All @@ -85,11 +85,11 @@ type internal FSharpDocumentHighlightsService [<ImportingConstructor>] (checkerP
let highlightSpans =
spans
|> Array.map (fun span ->
let kind = if span.IsDefinition then HighlightSpanKind.Definition else HighlightSpanKind.Reference
HighlightSpan(span.TextSpan, kind))
let kind = if span.IsDefinition then FSharpHighlightSpanKind.Definition else FSharpHighlightSpanKind.Reference
FSharpHighlightSpan(span.TextSpan, kind))
|> Seq.toImmutableArray

return ImmutableArray.Create(DocumentHighlights(document, highlightSpans))
return ImmutableArray.Create(FSharpDocumentHighlights(document, highlightSpans))
}
|> Async.map (Option.defaultValue ImmutableArray<DocumentHighlights>.Empty)
|> Async.map (Option.defaultValue ImmutableArray<FSharpDocumentHighlights>.Empty)
|> RoslynHelpers.StartAsyncAsTask(cancellationToken)