-
Notifications
You must be signed in to change notification settings - Fork 844
Unused declarations analyzer #2358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unused declarations analyzer #2358
Conversation
vasily-kirichenko
commented
Feb 2, 2017

|
Code fix that works on the compiler's FS1182 should work when VS fixes F# code fixes. |
|
Good stuff. |
|
It does not work as expected for two reasons:
@dsyme Am I right on these points? To fix the first one we need something like |
|
And the third point
|
| Diagnostic.Create( | ||
| Descriptor, | ||
| CommonRoslynHelpers.RangeToLocation(symbolUse.RangeAlternate, sourceText, document.FilePath))) | ||
| ).ToImmutableArray() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen this is quite a few places - is there nowhere we can have something like:
module ImmutableArray =
let ofSeq (x : 'a seq) = x.ToImmutableArray ()That way we can do:
unusedSymbolUses
|> Seq.map (* ... *)
|> ImmutableArray.ofSeqJust a thought
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good suggestion. Or we could provide an implicit conversion from seq<'a>... ;)
There is already an implicit background project check happening (that's the IncrementalBuilder). It currently raises events when finished. So you could listen for the ProjectChecked event and then call ParseAndCheckProject and GetBackgroundCheckResultsForFileInProject, which should in that case return more or less immediately (if nothing goes dirty in between the calls). Or we could change the ProjectChecked event to return the relevant FSharpCheckProjectResults.
Yes, the background IncrementalBuilder reads via FileSystem. Using dirty buffers for (intellisense and errors too) will be interesting - it will change the feel of the tooling but is clearly the "right" thing. Why does the analysis need full project results? In the screen shot you're only doing locals. Do you grey out private class/method/function declarations too? But in that case wouldn't you need the whole solution graph to properly treat internals w.r.t. InternalsVisibleTo? |
The problem is that we cannot tell Roslyn "hey, we have fresh data for you". It calls us itself when a file changed. Or you suggest to do something like: let compilationToken = StartBackgroundCompilation(options)
let! eargs = Async.AwaitEvent ProjectChecked
if eargs.CompilationToken = compilationToken then ...
else <wait again>? |
Yes.
Yes, but I ignore |
We should finally implement #1866 (comment) |
Yes that's approximately right. However it's dodgy, e.g. the event is not guaranteed to be raised. The background builder just builds one project (and its dependencies), selected somewhat implicitly (see Suggest:
The advantage of all this is that it gives me more confidence that we won't be putting any extra strain on the reactor thread - it's just doing what we're doing already, we just happen to be listening in for the completion of checking a project. |
|
@dsyme good plan. Unfortunately, RC3 crashes in 5-30 seconds after start both at home and at work. So I'm gonna wait until RTM is released to continue working on VFT. |
|
Reset windows, installed RC3. Everything works OK so far :) |
|
@vasily-kirichenko Thanks Kevin |
# Conflicts: # vsintegration/src/FSharp.Editor/FSharp.Editor.resx # vsintegration/src/FSharp.Editor/srFSharp.Editor.fs
|
@KevinRansom It requires #1866 to be done (checking project wide against dirty buffers). |
|
@KevinRansom I agree it requires #1866 to be done |
|
@KevinRansom I'll defer to @vasily-kirichenko - he implemented this for VFPT. For VFT it woud also apply to error lists, intellisense and quick info - we'd need to trial it extensively |
|
@vasily-kirichenko , is this ready or do you want to do more work? Kevin |
|
It still requires #1866 to be implemented first. |
|
I will simplify it to analyze private for document symbols 'coz no change project wide analysis will every be implemented. |
# Conflicts: # vsintegration/src/FSharp.Editor/FSharp.Editor.resx
|
@vasily-kirichenko is this ready to merge? Thanks Kevin |
UnusedDeclarationsAnalyzer analyze semantic, not syntax
|
@vasily-kirichenko please let me know when this is ready to merge? |
|
@KevinRansom it has false positives (it detects as unused |
|
@vasily-kirichenko sounds good, change it from wip, whan it's ready for review. And thanks for this. Kevin |
KevinRansom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this work
* add UnusedDeclarationsAnalyzer * fix compilation * make UnusedDeclarationsAnalyzer work on private symbols only * fix compilation UnusedDeclarationsAnalyzer analyze semantic, not syntax * finish UnusedDeclarationsAnalyzer * do not mark as unused symbols prefixed with underscore * fix FSharp.Editor.Pervasive.isScript * UnusedDeclarationsAnalyzer consider all declaration in scripts as private to file
