This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
/
FSharpParsedDocument.fs
69 lines (59 loc) · 2.94 KB
/
FSharpParsedDocument.fs
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
64
65
66
67
68
69
namespace MonoDevelop.FSharp
open FSharp.Compiler
open 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, parsedLine: string 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 val ParsedLocation = location with get, set
/// The text of the line where the caret is located at the point that the document was parsed
/// Used for intellisense cache.
member val ParsedLine = parsedLine with get, set
member val UnusedCodeRanges : Range.range list option = None with get, set
member val HasErrors = false with get, set
override x.GetTagCommentsAsync(cancellationToken) =
let tokenListToComment (tokenList: FSharpTokenInfo list, lineText: string) =
let comment =
tokenList
|> Array.ofList
|> Array.filter(fun token -> token.CharClass = FSharpTokenCharKind.LineComment)
|> Array.map(fun token -> lineText.[token.LeftColumn..token.RightColumn])
|> System.String.Concat
comment.TrimStart('/', ' ')
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<_>
}
|> StartAsyncAsTask 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)