-
Notifications
You must be signed in to change notification settings - Fork 847
Separate Project/Document diagnostics #1634
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
Merged
OmarTawfik
merged 2 commits into
dotnet:master
from
OmarTawfik:fix-1596-project-diagnostics
Oct 19, 2016
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
vsintegration/src/FSharp.Editor/ProjectDiagnosticAnalyzer.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| namespace Microsoft.VisualStudio.FSharp.Editor | ||
|
|
||
| open System | ||
| open System.Composition | ||
| open System.Collections.Immutable | ||
| open System.IO | ||
| open System.Threading | ||
| open System.Threading.Tasks | ||
|
|
||
| open Microsoft.CodeAnalysis | ||
| open Microsoft.CodeAnalysis.Diagnostics | ||
| open Microsoft.CodeAnalysis.Host.Mef | ||
| open Microsoft.CodeAnalysis.Text | ||
| open Microsoft.CodeAnalysis.SolutionCrawler | ||
|
|
||
| open Microsoft.FSharp.Compiler | ||
| open Microsoft.FSharp.Compiler.SourceCodeServices | ||
| open Microsoft.FSharp.Compiler.Range | ||
|
|
||
| open Microsoft.VisualStudio.FSharp.LanguageService | ||
|
|
||
| [<DiagnosticAnalyzer(FSharpCommonConstants.FSharpLanguageName)>] | ||
| type internal FSharpProjectDiagnosticAnalyzer() = | ||
| inherit ProjectDiagnosticAnalyzer() | ||
|
|
||
| static member GetDiagnostics(options: FSharpProjectOptions) = | ||
| let checkProjectResults = FSharpChecker.Instance.ParseAndCheckProject(options) |> Async.RunSynchronously | ||
| (checkProjectResults.Errors |> Seq.choose(fun (error) -> | ||
| if error.StartLineAlternate = 0 || error.EndLineAlternate = 0 then | ||
| Some(CommonRoslynHelpers.ConvertError(error, Location.None)) | ||
| else | ||
| // F# error line numbers are one-based. Errors that have a valid line number are reported by DocumentDiagnosticAnalyzer | ||
| None | ||
| )).ToImmutableArray() | ||
|
|
||
| override this.SupportedDiagnostics with get() = CommonRoslynHelpers.SupportedDiagnostics() | ||
|
|
||
| override this.AnalyzeProjectAsync(project: Project, cancellationToken: CancellationToken): Task<ImmutableArray<Diagnostic>> = | ||
| let computation = async { | ||
| match FSharpLanguageService.GetOptions(project.Id) with | ||
| | Some(options) -> | ||
| return FSharpProjectDiagnosticAnalyzer.GetDiagnostics(options) | ||
| | None -> return ImmutableArray<Diagnostic>.Empty | ||
| } | ||
|
|
||
| Async.StartAsTask(computation, TaskCreationOptions.None, cancellationToken) | ||
| .ContinueWith(CommonRoslynHelpers.GetCompletedTaskResult, cancellationToken) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
vsintegration/tests/unittests/ProjectDiagnosticAnalyzerTests.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| namespace Microsoft.VisualStudio.FSharp.Editor.Tests.Roslyn | ||
|
|
||
| open System | ||
| open System.IO | ||
| open System.Threading | ||
|
|
||
| open FSharp.Compiler.Service.Tests.Common | ||
|
|
||
| open NUnit.Framework | ||
|
|
||
| open Microsoft.CodeAnalysis | ||
| open Microsoft.CodeAnalysis.Classification | ||
| open Microsoft.CodeAnalysis.Editor | ||
| open Microsoft.CodeAnalysis.Text | ||
|
|
||
| open Microsoft.VisualStudio.FSharp.Editor | ||
| open Microsoft.VisualStudio.FSharp.LanguageService | ||
|
|
||
| open Microsoft.FSharp.Compiler.SourceCodeServices | ||
| open Microsoft.FSharp.Compiler.Range | ||
|
|
||
| [<TestFixture>] | ||
| type ProjectDiagnosticAnalyzerTests() = | ||
|
|
||
| let CreateProjectAndGetOptions(fileContents: string) = | ||
| let tempName = Path.GetTempFileName() | ||
| let fileName = Path.ChangeExtension(tempName, ".fs") | ||
| let projectName = Path.ChangeExtension(tempName, ".fsproj") | ||
| let dllName = Path.ChangeExtension(tempName, ".dll") | ||
| File.WriteAllText(fileName, fileContents) | ||
|
|
||
| let args = mkProjectCommandLineArgs (dllName, [fileName]) | ||
| checker.GetProjectOptionsFromCommandLineArgs (projectName, args) | ||
|
|
||
| [<Test>] | ||
| member public this.ProjectDiagnosticsDontReportJustProjectErrors_Bug1596() = | ||
| // https://github.com/Microsoft/visualfsharp/issues/1596 | ||
| let fileContents = """ | ||
| let x = 3 | ||
| printf "%d" x | ||
| """ | ||
| let options = CreateProjectAndGetOptions(fileContents) | ||
| let additionalOptions = {options with OtherOptions = Array.append options.OtherOptions [| "--times" |]} | ||
|
|
||
| let errors = FSharpProjectDiagnosticAnalyzer.GetDiagnostics(additionalOptions) | ||
| Assert.AreEqual(1, errors.Length, "Exactly one warning should have been reported") | ||
|
|
||
| let warning = errors.[0] | ||
| Assert.AreEqual(DiagnosticSeverity.Warning, warning.Severity, "Diagnostic severity should be a warning") | ||
| Assert.AreEqual("The command-line option 'times' is for test purposes only", warning.GetMessage()) | ||
|
|
||
| [<Test>] | ||
| member public this.ProjectDiagnosticsShouldNotReportDocumentErrors_Bug1596() = | ||
| // https://github.com/Microsoft/visualfsharp/issues/1596 | ||
| let fileContents = """ | ||
| let x = "string value that cannot be printed with %d" | ||
| printf "%d" x | ||
| """ | ||
| let options = CreateProjectAndGetOptions(fileContents) | ||
|
|
||
| let errors = FSharpProjectDiagnosticAnalyzer.GetDiagnostics(options) | ||
| Assert.AreEqual(0, errors.Length, "No semantic errors should have been reported") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does the user see the project diagnostics at all? Or only on build?
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.
@dsyme If you build the project, they will show up in output pane (from MSBuild) and error pane (from Roslyn service in this change). But they won't be highlighted on source code as the bug reported.