blob: d58af32bb4d3b56d2a1885f81275f2dbea832993 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
namespace MonoDevelop.FSharp
open MonoDevelop
open MonoDevelop.Ide.Editor
open MonoDevelop.Ide.Editor.Extension
open FSharp.Compiler
open FSharp.Compiler.SourceCodeServices
type FSharpNavigationTextEditorExtension() =
inherit AbstractNavigationExtension()
override x.RequestLinksAsync(offset, _length, token) =
// return all links for the line at offset
let editor = base.Editor
let documentContext = base.DocumentContext
async {
if documentContext :? FsiDocumentContext then return Seq.empty
else
match documentContext.ParsedDocument |> Option.tryCast<FSharpParsedDocument> with
| Some doc ->
match doc.TryGetAst () with
| None -> return Seq.empty
| Some _ast ->
let getOffset(pos: Range.pos) =
editor.LocationToOffset (DocumentLocation(pos.Line, pos.Column + 1))
let line = editor.OffsetToLineNumber offset
let segmentFromSymbol (symbol: FSharpSymbolUse) =
let range = symbol.RangeAlternate
let startOffset = getOffset range.Start
let endOffset = getOffset range.End
let text = editor.GetTextBetween(startOffset, endOffset)
let lastDot = text.LastIndexOf "."
let correctedOffset =
if lastDot <> -1 then
startOffset + lastDot + 1
else
startOffset
AbstractNavigationExtension.NavigationSegment(correctedOffset, endOffset - correctedOffset,
(fun () -> GLib.Timeout.Add (50u, fun () -> Refactoring.jumpToDeclaration(editor, documentContext, symbol)
false) |> ignore))
let filterSymbols (symbol: FSharpSymbolUse) =
symbol.RangeAlternate.StartLine = line
&& Refactoring.Operations.canJump symbol editor.FileName documentContext.Project.ParentSolution
return doc.AllSymbolsKeyed.Values
|> Seq.filter filterSymbols
|> Seq.map segmentFromSymbol
| None -> return Seq.empty
}
|> StartAsyncAsTask token
|