Skip to content

Commit 95a163e

Browse files
committed
wip
1 parent 0a7ecef commit 95a163e

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/FSharpFileStructureExplorer.fs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Stages
22

3+
open System.Collections.Generic
4+
open JetBrains.DocumentModel
35
open JetBrains.ReSharper.Daemon.Stages
46
open JetBrains.ReSharper.Feature.Services.Daemon
7+
open JetBrains.ReSharper.Plugins.FSharp.ProjectModel
58
open JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Tree
69
open JetBrains.ReSharper.Plugins.FSharp.Psi.Tree
710
open JetBrains.ReSharper.Psi.Tree
@@ -21,23 +24,46 @@ type DisableByNowarnCodeInspectionSection(warningId, range) =
2124
type FSharpFileStructure(fsFile: IFSharpFile) =
2225
inherit FileStructureBase(fsFile)
2326

27+
let getCompilerIds (directive: IHashDirective) =
28+
directive.ArgsEnumerable
29+
|> Seq.collect (fun argToken ->
30+
let fsString = argToken.As<FSharpString>()
31+
if isNull fsString then []: IReadOnlyCollection<_> else
32+
33+
// todo: define common helper for extracting string token values
34+
let text = fsString.GetText()
35+
let text = text.Substring(1, text.Length - 2)
36+
37+
FSharpCompilerWarningProcessor.parseCompilerIds text)
38+
2439
do
40+
let inline makeNowarnRange (startRange: DocumentRange) offset = startRange.SetEndTo(&offset)
41+
let fileRange = fsFile.GetDocumentRange()
42+
let isFSharp10Supported = FSharpLanguageLevel.isFSharp100Supported fsFile
43+
let openedNowarns = Dictionary()
44+
2545
for moduleDecl in fsFile.ModuleDeclarationsEnumerable do
2646
for moduleMember in moduleDecl.MembersEnumerable do
27-
let nowarnDirective = moduleMember.As<INowarnDirective>()
28-
if isNull nowarnDirective then () else
29-
30-
for argToken in nowarnDirective.ArgsEnumerable do
31-
let fsString = argToken.As<FSharpString>()
32-
if isNull fsString then () else
33-
34-
// todo: define common helper for extracting string token values
35-
let text = fsString.GetText()
36-
let text = text.Substring(1, text.Length - 2)
47+
match moduleMember with
48+
| :? INowarnDirective as nowarnDirective ->
49+
let compilerIds = getCompilerIds nowarnDirective
50+
for id in compilerIds do openedNowarns.TryAdd(id, fileRange) |> ignore
3751

38-
let range = fsFile.GetDocumentRange()
39-
for id in FSharpCompilerWarningProcessor.parseCompilerIds text do
40-
base.WarningDisableRange.AddValue(id, DisableByNowarnCodeInspectionSection(id, range))
52+
| :? IWarnonDirective as warnonDirective when isFSharp10Supported ->
53+
let compilerIds = getCompilerIds warnonDirective
54+
for id in compilerIds do
55+
match openedNowarns.TryGetValue(id) with
56+
| true, nowarnRange ->
57+
openedNowarns.Remove(id) |> ignore
58+
let range = makeNowarnRange nowarnRange (warnonDirective.GetDocumentStartOffset())
59+
base.WarningDisableRange.AddValue(id, DisableByNowarnCodeInspectionSection(id, range))
60+
| _ -> ()
61+
62+
| _ -> ()
63+
64+
for KeyValue(id, nowarnRange) in openedNowarns do
65+
let range = makeNowarnRange nowarnRange fileRange.EndOffset
66+
base.WarningDisableRange.AddValue(id, DisableByNowarnCodeInspectionSection(id, range))
4167

4268
for comment in fsFile.Descendants<FSharpComment>() do base.ProcessComment(comment, comment.CommentText)
4369
base.CloseAllRanges(fsFile)

0 commit comments

Comments
 (0)