Skip to content

Commit

Permalink
Merge pull request #10490 from dotnet/merges/main-to-feature/tasks
Browse files Browse the repository at this point in the history
Merge main to feature/tasks
  • Loading branch information
KevinRansom authored Nov 18, 2020
2 parents 4815d10 + a4f9bcf commit 1d7b23b
Show file tree
Hide file tree
Showing 26 changed files with 209 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/fsharp/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,7 @@ let warningOn err level specificWarnOn =
// Some specific warnings are never on by default, i.e. unused variable warnings
match n with
| 1182 -> false // chkUnusedValue - off by default
| 3218 -> false // ArgumentsInSigAndImplMismatch - off by default
| 3180 -> false // abImplicitHeapAllocation - off by default
| 3390 -> false // xmlDocBadlyFormed - off by default
| _ -> level >= GetWarningLevel err

let SplitRelatedDiagnostics(err: PhasedDiagnostic) : PhasedDiagnostic * PhasedDiagnostic list =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ type FSharpDependencyManager (outputDir:string option) =
sprintf """ #r "nuget:FSharp.Data";; // %s 'FSharp.Data' %s""" (SR.loadNugetPackage()) (SR.highestVersion())
|]

member this.ResolveDependencies(scriptExt: string, packageManagerTextLines: (string * string) seq, targetFramework: string, runtimeIdentifier: string) : obj =
member this.ResolveDependencies(scriptExt: string, packageManagerTextLines: (string * string) seq, targetFrameworkMoniker: string, runtimeIdentifier: string) : obj =
let poundRprefix =
match scriptExt with
| ".csx" -> "#r \""
| _ -> "#r @\""

let generateAndBuildProjectArtifacts =
let resolutionResult = prepareDependencyResolutionFiles (scriptExt, packageManagerTextLines, targetFramework, runtimeIdentifier)
let resolutionResult = prepareDependencyResolutionFiles (scriptExt, packageManagerTextLines, targetFrameworkMoniker, runtimeIdentifier)
match resolutionResult.resolutionsFile with
| Some file ->
let resolutions = getResolutionsFromFile file
Expand Down
18 changes: 18 additions & 0 deletions src/fsharp/service/ServiceUntypedParse.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ type FSharpParseFileResults(errors: FSharpErrorInfo[], input: ParsedInput option

member scope.ParseTree = input

member scope.TryRangeOfRefCellDereferenceContainingPos expressionPos =
match input with
| Some input ->
let res =
AstTraversal.Traverse(expressionPos, input, { new AstTraversal.AstVisitorBase<_>() with
member _.VisitExpr(_, _, defaultTraverse, expr) =
match expr with
| SynExpr.App(_, false, SynExpr.Ident funcIdent, expr, _) ->
if funcIdent.idText = "op_Dereference" && rangeContainsPos expr.Range expressionPos then
Some funcIdent.idRange
else
None
| _ -> defaultTraverse expr
})
res
| None ->
None

member scope.FindNoteworthyParamInfoLocations pos =
match input with
| Some input -> FSharpNoteworthyParamInfoLocations.Find(pos, input)
Expand Down
7 changes: 7 additions & 0 deletions src/fsharp/service/ServiceUntypedParse.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ type public FSharpParseFileResults =
/// The syntax tree resulting from the parse
member ParseTree : ParsedInput option

/// <summary>
/// Given the position of an expression, attempts to find the range of the
/// '!' in a derefence operation of that expression, like:
/// '!expr', '!(expr)', etc.
/// </summary>
member TryRangeOfRefCellDereferenceContainingPos: expressionPos: pos -> Option<range>

/// Notable parse info for ParameterInfo at a given location
member FindNoteworthyParamInfoLocations : pos:pos -> FSharpNoteworthyParamInfoLocations option

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22753,6 +22753,7 @@ FSharp.Compiler.SourceCodeServices.FSharpParseFileResults: Boolean get_ParseHadE
FSharp.Compiler.SourceCodeServices.FSharpParseFileResults: FSharp.Compiler.SourceCodeServices.FSharpErrorInfo[] Errors
FSharp.Compiler.SourceCodeServices.FSharpParseFileResults: FSharp.Compiler.SourceCodeServices.FSharpErrorInfo[] get_Errors()
FSharp.Compiler.SourceCodeServices.FSharpParseFileResults: FSharp.Compiler.SourceCodeServices.FSharpNavigationItems GetNavigationItems()
FSharp.Compiler.SourceCodeServices.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Range+range] TryRangeOfRefCellDereferenceContainingPos(pos)
FSharp.Compiler.SourceCodeServices.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Range+range] ValidateBreakpointLocation(pos)
FSharp.Compiler.SourceCodeServices.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.SourceCodeServices.FSharpNoteworthyParamInfoLocations] FindNoteworthyParamInfoLocations(pos)
FSharp.Compiler.SourceCodeServices.FSharpParseFileResults: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.SyntaxTree+ParsedInput] ParseTree
Expand Down
53 changes: 53 additions & 0 deletions tests/service/ServiceUntypedParseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,56 @@ type T =
new (x:int) = ()
"""
getTypeMemberRange source |> shouldEqual [ (3, 4), (3, 20) ]


[<Test>]
let ``TryRangeOfRefCellDereferenceContainingPos - simple``() =
let source = """
let x = false
let y = !x
"""
let parseFileResults, _ = getParseAndCheckResults source
let res = parseFileResults.TryRangeOfRefCellDereferenceContainingPos (mkPos 3 9)
match res with
| Some res ->
res
|> tups
|> fst
|> shouldEqual (3, 8)
| None ->
Assert.Fail("No deref operator found in source.")

[<Test>]
let ``TryRangeOfRefCellDereferenceContainingPos - parens``() =
let source = """
let x = false
let y = !(x)
"""
let parseFileResults, _ = getParseAndCheckResults source
let res = parseFileResults.TryRangeOfRefCellDereferenceContainingPos (mkPos 3 10)
match res with
| Some res ->
res
|> tups
|> fst
|> shouldEqual (3, 8)
| None ->
Assert.Fail("No deref operator found in source.")


[<Test>]
let ``TryRangeOfRefCellDereferenceContainingPos - binary expr``() =
let source = """
let x = false
let y = !(x = false)
"""
let parseFileResults, _ = getParseAndCheckResults source
let res = parseFileResults.TryRangeOfRefCellDereferenceContainingPos (mkPos 3 10)
match res with
| Some res ->
res
|> tups
|> fst
|> shouldEqual (3, 8)
| None ->
Assert.Fail("No deref operator found in source.")
3 changes: 2 additions & 1 deletion tests/service/data/TestTP/ProvidedTypes.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ type ProvidedAssembly =
/// and adjust the 'Assembly' property of all provided type definitions to return that
/// assembly.
/// </summary>
/// <param name="enclosingTypeNames">A path of type names to wrap the generated types. The generated types are then generated as nested types.</param>
/// <param name="types">A list of nested ProvidedTypeDefinitions to add to the ProvidedAssembly.</param>
/// <param name="enclosingGeneratedTypeNames">A path of type names to wrap the generated types. The generated types are then generated as nested types.</param>
member AddNestedTypes : types : ProvidedTypeDefinition list * enclosingGeneratedTypeNames: string list -> unit

#if FX_NO_LOCAL_FILESYSTEM
Expand Down
1 change: 1 addition & 0 deletions tests/service/data/TestTP/TestTP.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net472</TargetFramework>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<UnitTestType>nunit</UnitTestType>
<OtherFlags>--nowarn:3390 --nowarn:3218</OtherFlags>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace Microsoft.VisualStudio.FSharp.Editor

open System.Composition
open System.Threading.Tasks

open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes

[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "ChangeRefCellDerefToNotExpression"); Shared>]
type internal FSharpChangeRefCellDerefToNotExpressionCodeFixProvider
[<ImportingConstructor>]
(
checkerProvider: FSharpCheckerProvider,
projectInfoManager: FSharpProjectOptionsManager
) =
inherit CodeFixProvider()

static let userOpName = "FSharpChangeRefCellDerefToNotExpressionCodeFix"
let fixableDiagnosticIds = set ["FS0001"]

override __.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds

override this.RegisterCodeFixesAsync context : Task =
asyncMaybe {
let document = context.Document
let! parsingOptions, _ = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document, context.CancellationToken, userOpName)
let! sourceText = context.Document.GetTextAsync(context.CancellationToken)
let! parseResults = checkerProvider.Checker.ParseFile(document.FilePath, sourceText.ToFSharpSourceText(), parsingOptions, userOpName) |> liftAsync

let errorRange = RoslynHelpers.TextSpanToFSharpRange(document.FilePath, context.Span, sourceText)
let! derefRange = parseResults.TryRangeOfRefCellDereferenceContainingPos errorRange.Start
let! derefSpan = RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, derefRange)

let title = SR.UseNotForNegation()

let diagnostics =
context.Diagnostics
|> Seq.filter (fun x -> fixableDiagnosticIds |> Set.contains x.Id)
|> Seq.toImmutableArray

let codeFix =
CodeFixHelpers.createTextChangeCodeFix(
title,
context,
(fun () -> asyncMaybe.Return [| TextChange(derefSpan, "not ") |]))

context.RegisterCodeFix(codeFix, diagnostics)
}
|> Async.Ignore
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
1 change: 1 addition & 0 deletions vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Compile Include="Commands\FsiCommandService.fs" />
<Compile Include="Commands\XmlDocCommandService.fs" />
<Compile Include="CodeFix\CodeFixHelpers.fs" />
<Compile Include="CodeFix\ChangeRefCellDerefToNotExpression.fs" />
<Compile Include="CodeFix\WrapExpressionInParentheses.fs" />
<Compile Include="CodeFix\ChangePrefixNegationToInfixSubtraction.fs" />
<Compile Include="CodeFix\AddNewKeywordToDisposableConstructorInvocation.fs" />
Expand Down
5 changes: 4 additions & 1 deletion vsintegration/src/FSharp.Editor/FSharp.Editor.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -219,6 +219,9 @@
<data name="FSharpDisposableTopLevelValuesClassificationType" xml:space="preserve">
<value>F# Dispostable Values (top-level)</value>
</data>
<data name="UseNotForNegation" xml:space="preserve">
<value>Use 'not' to negate expression</value>
</data>
<data name="WrapExpressionInParentheses" xml:space="preserve">
<value>Wrap expression in parentheses</value>
</data>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">Formátování</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">Formatierung</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">Formato</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">Mise en forme</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">Formattazione</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">書式設定</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">서식</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">Formatowanie</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">Formatação</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">Форматирование</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">Biçimlendirme</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">正在格式化</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
<target state="translated">格式化</target>
<note />
</trans-unit>
<trans-unit id="UseNotForNegation">
<source>Use 'not' to negate expression</source>
<target state="new">Use 'not' to negate expression</target>
<note />
</trans-unit>
<trans-unit id="WrapExpressionInParentheses">
<source>Wrap expression in parentheses</source>
<target state="new">Wrap expression in parentheses</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<OtherFlags>--nowarn:3390 --nowarn:3218</OtherFlags>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 1d7b23b

Please sign in to comment.