Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ type internal FSharpColorizationService
let! options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! sourceText = document.GetTextAsync(cancellationToken)
let! _, checkResults = checkerProvider.Checker.ParseAndCheckDocument(document, options, sourceText)

for (range, tokenColorKind) in checkResults.GetExtraColorizationsAlternate() do
// it's crucial to not return duplicated or overlapping `ClassifiedSpan`s because Find Usages service crashes.
let colorizationData = checkResults.GetExtraColorizationsAlternate() |> Array.distinctBy fst
for (range, tokenColorKind) in colorizationData do
let span = CommonHelpers.fixupSpan(sourceText, CommonRoslynHelpers.FSharpRangeToTextSpan(sourceText, range))
if textSpan.Contains(span.Start) || textSpan.Contains(span.End - 1) || span.Contains(textSpan) then
result.Add(ClassifiedSpan(span, CommonHelpers.compilerTokenToRoslynToken(tokenColorKind)))
Expand Down
40 changes: 21 additions & 19 deletions vsintegration/src/FSharp.Editor/Navigation/FindReferencesService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ open Microsoft.CodeAnalysis.Editor.Host
open Microsoft.CodeAnalysis.Navigation
open Microsoft.CodeAnalysis.FindSymbols
open Microsoft.CodeAnalysis.FindReferences
open Microsoft.CodeAnalysis.Completion

open Microsoft.VisualStudio.FSharp.LanguageService

Expand Down Expand Up @@ -62,31 +63,32 @@ type internal FSharpFindReferencesService
let! symbol = CommonHelpers.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Fuzzy)
let! symbolUse = checkFileResults.GetSymbolUseAtLocation(lineNumber, symbol.RightColumn, textLine, [symbol.Text])
let! declaration = checkFileResults.GetDeclarationLocationAlternate (lineNumber, symbol.RightColumn, textLine, [symbol.Text], false) |> liftAsync
let tags = GlyphTags.GetTags(CommonRoslynHelpers.GetGlyphForSymbol symbolUse.Symbol)

let declarationRange =
match declaration with
| FSharpFindDeclResult.DeclFound range -> Some range
| _ -> None

let! declarationSpans =
match declarationRange with
| Some range -> rangeToDocumentSpans(document.Project.Solution, range, context.CancellationToken) |> liftAsync
| None -> async.Return None

let definitionItems =
match declarationSpans with
| [] ->
[ DefinitionItem.CreateNonNavigableItem(
ImmutableArray<string>.Empty,
[TaggedText(TextTags.Text, symbolUse.Symbol.FullName)].ToImmutableArray(),
[TaggedText(TextTags.Assembly, symbolUse.Symbol.Assembly.SimpleName)].ToImmutableArray()) ]
| _ ->
declarationSpans
|> List.map (fun span ->
DefinitionItem.Create(
ImmutableArray<string>.Empty,
[TaggedText(TextTags.Text, symbolUse.Symbol.FullName)].ToImmutableArray(),
span))
let! definitionItems =
async {
let! declarationSpans =
match declarationRange with
| Some range -> rangeToDocumentSpans(document.Project.Solution, range, context.CancellationToken)
| None -> async.Return []
return
match declarationSpans with
| [] ->
[ DefinitionItem.CreateNonNavigableItem(
tags,
ImmutableArray.Create(TaggedText(TextTags.Text, symbol.Text)),
ImmutableArray.Create(TaggedText(TextTags.Assembly, symbolUse.Symbol.Assembly.SimpleName))) ]
| _ ->
declarationSpans
|> List.map (fun span ->
DefinitionItem.Create(tags, ImmutableArray.Create(TaggedText(TextTags.Text, symbol.Text)), span))
} |> liftAsync

for definitionItem in definitionItems do
do! context.OnDefinitionFoundAsync(definitionItem) |> Async.AwaitTask |> liftAsync
Expand Down