Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FSharpParsedDocument.fs « MonoDevelop.FSharpBinding « fsharpbinding « external « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0643088b0994357de334181ea576377ae4f95157 (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
58
59
60
61
62
63
namespace MonoDevelop.FSharp

open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.SourceCodeServices
open MonoDevelop
open MonoDevelop.Core
open MonoDevelop.Ide
open MonoDevelop.Ide.Editor
open MonoDevelop.Ide.Tasks
open MonoDevelop.Ide.TypeSystem
open System.Collections.Generic
open System.IO

type FSharpParsedDocument(fileName, location: DocumentLocation option) =
    inherit DefaultParsedDocument(fileName,Flags = ParsedDocumentFlags.NonSerializable)
    let specialCommentTags = 
        CommentTag.SpecialCommentTags
        |> Seq.map(fun t -> t.Tag)
        |> Set.ofSeq

    member val Tokens : (FSharpTokenInfo list * string) list option = None with get,set
    member val AllSymbolsKeyed = Dictionary<Range.pos, FSharpSymbolUse>() :> IDictionary<_,_> with get, set
    member x.ParsedLocation = location

    member val UnusedCodeRanges : Range.range list option = None with get, set

    override x.GetTagCommentsAsync(cancellationToken) =
        let tokenListToComment (tokenList: FSharpTokenInfo list, lineText: string) =
            let comment = 
                tokenList
                |> List.filter(fun t -> t.CharClass = FSharpTokenCharKind.LineComment)
                |> List.fold(fun acc token -> acc + lineText.[token.LeftColumn..token.RightColumn]) ""
            comment.TrimStart('/', ' ')

        let computation =
            async {
                match x.Tokens with
                | Some tokens ->
                    let tokensByLine =
                        tokens 
                        |> List.mapi (fun line tokenList -> line+1, tokenListToComment tokenList)
                        |> List.choose(fun (line, s) ->
                                            specialCommentTags 
                                            |> Set.tryFind(fun tag -> s.StartsWith tag)
                                            |> Option.bind(fun t -> Some <| Tag(t, s, DocumentRegion(line, 1, line, 1))))

                    return ResizeArray(tokensByLine) :> IReadOnlyList<_>
                | None -> return ResizeArray() :> IReadOnlyList<_>
            }
        Async.StartAsTask(computation, cancellationToken = cancellationToken)

[<AutoOpen>]
module DocumentContextExt =
    type DocumentContext with
        member x.GetWorkingFolder() =
            if IdeApp.Workbench.ActiveDocument <> null && FileService.isInsideFSharpFile() then
                let doc = IdeApp.Workbench.ActiveDocument.FileName.ToString()
                if doc <> null then Path.GetDirectoryName(doc) |> Some else None
            else None

        member x.TryGetFSharpParsedDocument() =
            x.TryGetParsedDocument()
            |> Option.bind (function :? FSharpParsedDocument as fpd -> Some fpd | _ -> None)