diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Analyzers/RedundantQualifierAnalyzer.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Analyzers/RedundantQualifierAnalyzer.fs index 16d7612f45..288cb3ddf0 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Analyzers/RedundantQualifierAnalyzer.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Analyzers/RedundantQualifierAnalyzer.fs @@ -22,7 +22,7 @@ let isGlobal (fcsReference: FSharpSymbolReference) = not fcsReference.IsQualified && let referenceOwner = fcsReference.GetElement() - isNotNull referenceOwner && getTokenType referenceOwner.FSharpIdentifier == FSharpTokenType.GLOBAL + isNotNull referenceOwner && getTokenType referenceOwner.NameIdentifier == FSharpTokenType.GLOBAL let isModuleOrNamespace (fcsReference: FSharpSymbolReference) = let entity = fcsReference.GetFcsSymbol().As() diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/FcsErrorsStageProcessBase.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/FcsErrorsStageProcessBase.fs index d1d2b9b908..9432885909 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/FcsErrorsStageProcessBase.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/FcsErrorsStageProcessBase.fs @@ -197,7 +197,7 @@ type FcsErrorsStageProcessBase(fsFile, daemonProcess) = let createHighlightingFromMappedExpression mapping highlightingCtor range (error: FSharpDiagnostic): IHighlighting = let expr = nodeSelectionProvider.GetExpressionInRange(fsFile, range, false, null) |> mapping - if isNotNull expr then highlightingCtor(expr, error.Message) :> _ else null + if isNotNull expr then highlightingCtor (expr, error.Message) :> _ else null let createCachedDiagnostic (error: FSharpDiagnostic) range = let pos = error.Range.Start @@ -227,8 +227,8 @@ type FcsErrorsStageProcessBase(fsFile, daemonProcess) = createTypeMismatchHighlighting MatchClauseWrongTypeError range error | Some(:? TypeMismatchDiagnosticExtendedData as data) -> - let expr = nodeSelectionProvider.GetExpressionInRange(fsFile, range, false, null) |> getResultExpr - if isNull expr then + let node = nodeSelectionProvider.GetExpressionInRange(fsFile, range, false, null) |> getResultNode + if isNull node then null elif isUnit data.ExpectedType then createHighlightingFromNodeWithMessage UnitTypeExpectedError range error @@ -359,7 +359,7 @@ type FcsErrorsStageProcessBase(fsFile, daemonProcess) = | _ -> createGenericHighlighting error range | UnitTypeExpected -> - createHighlightingFromMappedExpression getResultExpr UnitTypeExpectedWarning range error + createHighlightingFromMappedExpression getResultNode UnitTypeExpectedWarning range error | UseBindingsIllegalInModules -> createHighlightingFromNode UseBindingsIllegalInModulesWarning range @@ -550,14 +550,14 @@ type FcsErrorsStageProcessBase(fsFile, daemonProcess) = | MissingErrorNumber -> match error.ExtendedData with | Some (:? ExpressionIsAFunctionExtendedData) -> - createHighlightingFromMappedExpression getResultExpr FunctionValueUnexpectedWarning range error + createHighlightingFromMappedExpression getResultNode FunctionValueUnexpectedWarning range error | Some (:? FieldNotContainedDiagnosticExtendedData) -> createHighlightingFromParentNodeWithMessage FieldNotContainedTypesDifferError range error | Some (:? TypeMismatchDiagnosticExtendedData as data) -> if isUnit data.ExpectedType then - createHighlightingFromMappedExpression getResultExpr UnitTypeExpectedError range error else + createHighlightingFromMappedExpression getResultNode UnitTypeExpectedError range error else createTypeMismatchHighlighting TypeConstraintMismatchError range error diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/AddIgnoreFix.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/AddIgnoreFix.fs index cd14c432bb..f01f43c095 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/AddIgnoreFix.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/AddIgnoreFix.fs @@ -6,12 +6,13 @@ open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Util open JetBrains.ReSharper.Plugins.FSharp.Psi.Impl open JetBrains.ReSharper.Plugins.FSharp.Psi.Tree open JetBrains.ReSharper.Psi.ExtensionsAPI.Tree -open JetBrains.ReSharper.Psi.ExtensionsAPI open JetBrains.ReSharper.Resources.Shell -type AddIgnoreFix(expr: IFSharpExpression) = +type AddIgnoreFix(node: IFSharpTypeOwnerNode) = inherit FSharpModernQuickFixBase() + let expr = node.As() + let shouldAddNewLine (expr: IFSharpExpression) = if expr.IsSingleLine then false else if lastBlockHasSameIndent expr then false else @@ -47,13 +48,13 @@ type AddIgnoreFix(expr: IFSharpExpression) = addParensIfNeeded replaced.LeftArgument |> ignore new (warning: UnitTypeExpectedWarning) = - AddIgnoreFix(warning.Expr) + AddIgnoreFix(warning.Node) new (warning: FunctionValueUnexpectedWarning) = - AddIgnoreFix(warning.Expr) + AddIgnoreFix(warning.Node) new (error: UnitTypeExpectedError) = - AddIgnoreFix(error.Expr) + AddIgnoreFix(error.Node) override x.Text = "Ignore value" override x.IsAvailable _ = isValid expr diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/AddParensToTypedLikeExprFix.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/AddParensToTypedLikeExprFix.fs index 0c42aed022..7a2478e173 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/AddParensToTypedLikeExprFix.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/AddParensToTypedLikeExprFix.fs @@ -17,7 +17,7 @@ type AddParensToTypedLikeExprFix(typedLikeExpr: ITypedLikeExpr) = AddParensToTypedLikeExprFix(error.Expr) new (error: TypeConstraintMismatchError) = - let typedLikeExpr = TypedLikeExprNavigator.GetByExpression(error.Expr) + let typedLikeExpr = TypedLikeExprNavigator.GetByExpression(error.Node.As()) AddParensToTypedLikeExprFix typedLikeExpr override x.Text = diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ChangeTypeFix.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ChangeTypeFix.fs index 0684c962d4..043ae47993 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ChangeTypeFix.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ChangeTypeFix.fs @@ -18,7 +18,7 @@ open JetBrains.ReSharper.Resources.Shell open JetBrains.Util [] -type ChangeTypeFixBase(expr: IFSharpExpression, fcsDiagnosticInfo: FcsCachedDiagnosticInfo) = +type ChangeTypeFixBase(node: IFSharpTypeOwnerNode, fcsDiagnosticInfo: FcsCachedDiagnosticInfo) = inherit FSharpQuickFixBase() let canUpdateType (decl: ITreeNode) = @@ -26,7 +26,7 @@ type ChangeTypeFixBase(expr: IFSharpExpression, fcsDiagnosticInfo: FcsCachedDiag decl :? IFSharpParameterDeclaration member this.TargetFcsType = - use pinCheckResultsCookie = expr.FSharpFile.PinTypeCheckResults(true, "ChangeTypeFixBase") + use pinCheckResultsCookie = node.FSharpFile.PinTypeCheckResults(true, "ChangeTypeFixBase") this.GetTargetFcsType(fcsDiagnosticInfo.TypeMismatchData) abstract DeclaredElement: IDeclaredElement @@ -86,16 +86,18 @@ type ChangeTypeFixBase(expr: IFSharpExpression, fcsDiagnosticInfo: FcsCachedDiag // todo: test signatures, virtual/abstract members -type ChangeParameterTypeFromArgumentFix(expr, fcsDiagnosticInfo: FcsCachedDiagnosticInfo) = - inherit ChangeTypeFixBase(expr, fcsDiagnosticInfo) +type ChangeParameterTypeFromArgumentFix(node: IFSharpTypeOwnerNode, fcsDiagnosticInfo: FcsCachedDiagnosticInfo) = + inherit ChangeTypeFixBase(node, fcsDiagnosticInfo) - let fsParamIndex = FSharpArgumentsOwnerUtil.TryGetFSharpParameterIndex(expr) + let expr = node.As() + + let fsParamIndex = FSharpArgumentsOwnerUtil.TryGetFSharpParameterIndex(node) new (error: TypeEquationError) = - ChangeParameterTypeFromArgumentFix(error.Expr, error.DiagnosticInfo) + ChangeParameterTypeFromArgumentFix(error.Node, error.DiagnosticInfo) new (error: TypeConstraintMismatchError) = - ChangeParameterTypeFromArgumentFix(error.Expr, error.DiagnosticInfo) + ChangeParameterTypeFromArgumentFix(error.Node, error.DiagnosticInfo) override this.Text = $"Change type of parameter to '{this.TargetFcsType.Format()}'" @@ -119,39 +121,39 @@ type ChangeParameterTypeFromArgumentFix(expr, fcsDiagnosticInfo: FcsCachedDiagno decl.SetParameterFcsType(fsParamIndex.Value, fcsType) -type ChangeTypeFromElementReferenceFix(expr, fcsDiagnosticInfo) = - inherit ChangeTypeFixBase(expr, fcsDiagnosticInfo) +type ChangeTypeFromElementReferenceFix(node, fcsDiagnosticInfo) = + inherit ChangeTypeFixBase(node, fcsDiagnosticInfo) new (error: TypeEquationError) = - ChangeTypeFromElementReferenceFix(error.Expr, error.DiagnosticInfo) + ChangeTypeFromElementReferenceFix(error.Node, error.DiagnosticInfo) new (error: TypeConstraintMismatchError) = - ChangeTypeFromElementReferenceFix(error.Expr, error.DiagnosticInfo) + ChangeTypeFromElementReferenceFix(error.Node, error.DiagnosticInfo) override this.GetTargetFcsType(data) = data.ExpectedType override this.DeclaredElement = - let refExpr = expr.As() - if isNull refExpr then null else + let referenceOwner = node.As() + if isNull referenceOwner then null else - refExpr.Reference.Resolve().DeclaredElement + referenceOwner.Reference.Resolve().DeclaredElement -type ChangeReturnTypeFromInvocationFix(expr: IFSharpExpression, fcsDiagnosticInfo) = - inherit ChangeTypeFixBase(expr, fcsDiagnosticInfo) +type ChangeReturnTypeFromInvocationFix(node: IFSharpTypeOwnerNode, fcsDiagnosticInfo) = + inherit ChangeTypeFixBase(node, fcsDiagnosticInfo) new (error: TypeEquationError) = - ChangeReturnTypeFromInvocationFix(error.Expr, error.DiagnosticInfo) + ChangeReturnTypeFromInvocationFix(error.Node, error.DiagnosticInfo) new (error: TypeConstraintMismatchError) = - ChangeReturnTypeFromInvocationFix(error.Expr, error.DiagnosticInfo) + ChangeReturnTypeFromInvocationFix(error.Node, error.DiagnosticInfo) override this.GetTargetFcsType(data) = data.ExpectedType override this.DeclaredElement = - let appExpr = expr.As() + let appExpr = node.As() if isNull appExpr then null else let reference = appExpr.InvokedFunctionReference @@ -185,33 +187,47 @@ type ChangeReturnTypeFromInvocationFix(expr: IFSharpExpression, fcsDiagnosticInf |> FSharpTypeUsageUtil.updateTypeUsage fcsType -type ChangeTypeFromRecordFieldBindingFix(expr, fcsDiagnosticInfo) = - inherit ChangeTypeFixBase(expr, fcsDiagnosticInfo) +type ChangeTypeFromRecordFieldBindingFix(node, fcsDiagnosticInfo) = + inherit ChangeTypeFixBase(node, fcsDiagnosticInfo) + + let tryGetFieldReferenceOwner (node: IFSharpTypeOwnerNode) : IFSharpReferenceOwner = + match node with + | :? IFSharpExpression as expr -> + let fieldBinding = RecordFieldBindingNavigator.GetByExpression(expr.IgnoreParentParens()) + if isNotNull fieldBinding then fieldBinding.ReferenceName else null + + | :? IFSharpPattern as pat -> + let fieldPat = FieldPatNavigator.GetByPattern(pat.IgnoreParentParens()) + if isNotNull fieldPat then fieldPat.ReferenceName else null + + | _ -> null new (error: TypeEquationError) = - ChangeTypeFromRecordFieldBindingFix(error.Expr, error.DiagnosticInfo) + ChangeTypeFromRecordFieldBindingFix(error.Node, error.DiagnosticInfo) new (error: TypeConstraintMismatchError) = - ChangeTypeFromRecordFieldBindingFix(error.Expr, error.DiagnosticInfo) + ChangeTypeFromRecordFieldBindingFix(error.Node, error.DiagnosticInfo) override this.GetTargetFcsType(data) = data.ActualType override this.DeclaredElement = - let binding = RecordFieldBindingNavigator.GetByExpression(expr.IgnoreParentParens()) - if isNull binding then null else + let referenceOwner = tryGetFieldReferenceOwner node + if isNull referenceOwner then null else + + referenceOwner.Reference.Resolve().DeclaredElement - binding.ReferenceName.Reference.Resolve().DeclaredElement +type ChangeTypeFromSetExprFix(node, fcsDiagnosticInfo) = + inherit ChangeTypeFixBase(node, fcsDiagnosticInfo) -type ChangeTypeFromSetExprFix(expr, fcsDiagnosticInfo) = - inherit ChangeTypeFixBase(expr, fcsDiagnosticInfo) + let expr = node.As() new (error: TypeEquationError) = - ChangeTypeFromSetExprFix(error.Expr, error.DiagnosticInfo) + ChangeTypeFromSetExprFix(error.Node, error.DiagnosticInfo) new (error: TypeConstraintMismatchError) = - ChangeTypeFromSetExprFix(error.Expr, error.DiagnosticInfo) + ChangeTypeFromSetExprFix(error.Node, error.DiagnosticInfo) override this.GetTargetFcsType(data) = data.ActualType diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ConvertTupleToArrayOrListElementsFix.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ConvertTupleToArrayOrListElementsFix.fs index 63fbc64b11..9f2b90d14d 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ConvertTupleToArrayOrListElementsFix.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ConvertTupleToArrayOrListElementsFix.fs @@ -16,7 +16,7 @@ open JetBrains.Util type ConvertTupleToArrayOrListElementsFix(warning: TypeEquationError) = inherit FSharpQuickFixBase() - let expr = warning.Expr + let expr = warning.Node.As() override x.Text = "Use ';' separators" diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/IntroduceVarFix.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/IntroduceVarFix.fs index bb92d27de3..6797fb9b3a 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/IntroduceVarFix.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/IntroduceVarFix.fs @@ -10,10 +10,10 @@ module IntroduceVarFix = let [] introduceVarText = "Introduce 'let' binding" let [] introduceVarOutsideLambdaText = "Introduce 'let' binding outside lambda" -type IntroduceVarFix(expr: IFSharpExpression, removeExpr, escapeLambdas, addMutable, text) = +type IntroduceVarFix(node: IFSharpTypeOwnerNode, removeExpr, escapeLambdas, addMutable, text) = inherit FSharpQuickFixBase() - let mutable expr = expr + let mutable expr = node.As() let suggestInnerExpression (expr: IFSharpExpression) = let binaryAppExpr = expr.As() @@ -23,13 +23,13 @@ type IntroduceVarFix(expr: IFSharpExpression, removeExpr, escapeLambdas, addMuta null new (warning: UnitTypeExpectedWarning) = - IntroduceVarFix(warning.Expr, true, false, false, IntroduceVarFix.introduceVarText) + IntroduceVarFix(warning.Node, true, false, false, IntroduceVarFix.introduceVarText) new (warning: FunctionValueUnexpectedWarning) = - IntroduceVarFix(warning.Expr, true, false, false, IntroduceVarFix.introduceVarText) + IntroduceVarFix(warning.Node, true, false, false, IntroduceVarFix.introduceVarText) new (error: UnitTypeExpectedError) = - IntroduceVarFix(error.Expr, true, false, false, IntroduceVarFix.introduceVarText) + IntroduceVarFix(error.Node, true, false, false, IntroduceVarFix.introduceVarText) new (error: CantTakeAddressOfExpressionError) = IntroduceVarFix(error.Expr.Expression, false, false, true, IntroduceVarFix.introduceVarText) diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/RemoveSubsequentFix.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/RemoveSubsequentFix.fs index e25e7bda62..261bbe1187 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/RemoveSubsequentFix.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/RemoveSubsequentFix.fs @@ -4,19 +4,20 @@ open JetBrains.ReSharper.Plugins.FSharp.Psi open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Daemon.Highlightings open JetBrains.ReSharper.Plugins.FSharp.Psi.Services.Util open JetBrains.ReSharper.Plugins.FSharp.Psi.Tree -open JetBrains.ReSharper.Psi.ExtensionsAPI open JetBrains.ReSharper.Psi.ExtensionsAPI.Tree open JetBrains.ReSharper.Psi.Util open JetBrains.ReSharper.Resources.Shell -type RemoveSubsequentFix(expr: IFSharpExpression) = +type RemoveSubsequentFix(node: IFSharpTypeOwnerNode) = inherit FSharpQuickFixBase() + let expr = node.As() + new (warning: UnitTypeExpectedWarning) = - RemoveSubsequentFix(warning.Expr) + RemoveSubsequentFix(warning.Node) new (warning: FunctionValueUnexpectedWarning) = - RemoveSubsequentFix(warning.Expr) + RemoveSubsequentFix(warning.Node) override x.Text = "Remove subsequent expressions" diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ReplaceReturnTypeFix.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ReplaceReturnTypeFix.fs index 48621f9b66..231f0be15d 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ReplaceReturnTypeFix.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ReplaceReturnTypeFix.fs @@ -11,9 +11,11 @@ open JetBrains.ReSharper.Psi.ExtensionsAPI open JetBrains.ReSharper.Psi.Tree open JetBrains.ReSharper.Resources.Shell -type ReplaceReturnTypeFix(expr: IFSharpExpression, diagnosticInfo: FcsCachedDiagnosticInfo) = +type ReplaceReturnTypeFix(node: IFSharpTypeOwnerNode, diagnosticInfo: FcsCachedDiagnosticInfo) = inherit FSharpQuickFixBase() + let expr = node.As() + let unwrapDecl (decl: IDeclaration) = match decl with | :? IFSharpTypeOwnerDeclaration as typeOwnerDecl -> typeOwnerDecl @@ -39,11 +41,11 @@ type ReplaceReturnTypeFix(expr: IFSharpExpression, diagnosticInfo: FcsCachedDiag new (error: TypeConstraintMismatchError) = // error FS0193: Type constraint mismatch. The type 'A.B' is not compatible with type 'Thing' - ReplaceReturnTypeFix(error.Expr, error.DiagnosticInfo) + ReplaceReturnTypeFix(error.Node, error.DiagnosticInfo) new (error: TypeEquationError) = // error FS0001: This expression was expected to have type 'int' but here has type 'string' - ReplaceReturnTypeFix(error.Expr, error.DiagnosticInfo) + ReplaceReturnTypeFix(error.Node, error.DiagnosticInfo) new (error: MatchClauseWrongTypeError) = // All branches of a pattern match expression must return values implicitly convertible to the type of the first branch, which here is 'int'. diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ReplaceWithAssignmentExpressionFix.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ReplaceWithAssignmentExpressionFix.fs index 3e9a0e80be..6869062891 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ReplaceWithAssignmentExpressionFix.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Intentions/src/QuickFixes/ReplaceWithAssignmentExpressionFix.fs @@ -6,7 +6,6 @@ open JetBrains.ReSharper.Plugins.FSharp.Psi open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Daemon.Highlightings open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Util.FSharpExpressionUtil open JetBrains.ReSharper.Plugins.FSharp.Psi.Tree -open JetBrains.ReSharper.Psi.ExtensionsAPI open JetBrains.ReSharper.Psi open JetBrains.ReSharper.Resources.Shell @@ -14,10 +13,10 @@ type ReplaceWithAssignmentExpressionFix(expr: IBinaryAppExpr) = inherit FSharpQuickFixBase() new (error: UnitTypeExpectedError) = - ReplaceWithAssignmentExpressionFix(error.Expr.As()) + ReplaceWithAssignmentExpressionFix(error.Node.As()) new (warning: UnitTypeExpectedWarning) = - ReplaceWithAssignmentExpressionFix(warning.Expr.As()) + ReplaceWithAssignmentExpressionFix(warning.Node.As()) override x.IsAvailable _ = if not (isValid expr && isPredefinedFunctionRef "=" expr.Operator) then false else diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Daemon/Highlightings/FSharpErrorUtil.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Daemon/Highlightings/FSharpErrorUtil.fs index 203c521b56..15ed7e7464 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Daemon/Highlightings/FSharpErrorUtil.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Daemon/Highlightings/FSharpErrorUtil.fs @@ -57,21 +57,25 @@ let getRefExprNameRange (refExpr: IReferenceExpr) = | null -> refExpr.GetHighlightingRange() | identifier -> identifier.GetHighlightingRange() -let rec getResultExpr (expr: IFSharpExpression) = - match expr with - | :? ILetOrUseExpr as letExpr -> - let inExpr = letExpr.InExpression - if isNotNull inExpr then getResultExpr inExpr else expr +let rec getResultNode (node: IFSharpTypeOwnerNode) : IFSharpTypeOwnerNode = + match node with + | :? IFSharpExpression as expr -> + match expr with + | :? ILetOrUseExpr as letExpr -> + let inExpr = letExpr.InExpression + if isNotNull inExpr then getResultNode inExpr else expr - | :? ISequentialExpr as seqExpr -> - let lastExpr = seqExpr.Expressions.LastOrDefault() - if isNotNull lastExpr then getResultExpr lastExpr else expr + | :? ISequentialExpr as seqExpr -> + let lastExpr = seqExpr.Expressions.LastOrDefault() + if isNotNull lastExpr then getResultNode lastExpr else expr - | :? IParenOrBeginEndExpr as parenExpr -> - let innerExpr = parenExpr.InnerExpression - if isNotNull innerExpr && not parenExpr.IsSingleLine then getResultExpr innerExpr else expr + | :? IParenOrBeginEndExpr as parenExpr -> + let innerExpr = parenExpr.InnerExpression + if isNotNull innerExpr && not parenExpr.IsSingleLine then getResultNode innerExpr else expr + + | _ -> expr - | _ -> expr + | _ -> node let getAttributeSuffixRange (attribute: IAttribute) = let referenceName = attribute.ReferenceName diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Daemon/Highlightings/FcsErrors.xml b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Daemon/Highlightings/FcsErrors.xml index d17fcbd67a..d9e1c3fc03 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Daemon/Highlightings/FcsErrors.xml +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Daemon/Highlightings/FcsErrors.xml @@ -20,12 +20,12 @@ - + fcsMessage - expr.GetHighlightingRange() + node.GetHighlightingRange() ConvertTupleToArrayOrListElementsFix ReplaceReturnTypeFix @@ -37,12 +37,12 @@ - + fcsMessage - expr.GetHighlightingRange() + node.GetHighlightingRange() ReplaceWithAssignmentExpressionFix AddIgnoreFix @@ -119,12 +119,12 @@ - + fcsMessage - expr.GetHighlightingRange() + node.GetHighlightingRange() IntroduceVarFix AddIgnoreFix @@ -192,7 +192,7 @@ fcsMessage - reference.GetElement().FSharpIdentifier.GetHighlightingRange() + reference.GetElement().NameIdentifier.GetHighlightingRange() ToRecursiveFunctionFix FSharpImportTypeFix @@ -241,7 +241,7 @@ fcsMessage - reference.GetElement().FSharpIdentifier.GetHighlightingRange() + reference.GetElement().NameIdentifier.GetHighlightingRange() FSharpImportModuleMemberFix @@ -286,12 +286,12 @@ - + fcsMessage - expr.GetHighlightingRange() + node.GetHighlightingRange() IntroduceVarFix AddIgnoreFix @@ -300,12 +300,12 @@ - + fcsMessage - expr.GetHighlightingRange() + node.GetHighlightingRange() AddParensToTypedLikeExprFix ReplaceReturnTypeFix @@ -610,7 +610,7 @@ fcsMessage - reference.GetElement().FSharpIdentifier.GetHighlightingRange() + reference.GetElement().NameIdentifier.GetHighlightingRange() FSharpImportTypeFix FSharpReferenceModuleAndTypeFix diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Util/FSharpMethodInvocationUtil.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Util/FSharpMethodInvocationUtil.fs index 0a03c9bb2b..780dc8d273 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Util/FSharpMethodInvocationUtil.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Util/FSharpMethodInvocationUtil.fs @@ -31,7 +31,7 @@ let getArgsOwner (expr: IFSharpExpression) = let getReferenceName (fsArgsOwner: IFSharpArgumentsOwner) = let identifier = match fsArgsOwner with - | :? IFSharpReferenceOwner as refOwner -> refOwner.FSharpIdentifier + | :? IFSharpReferenceOwner as refOwner -> refOwner.NameIdentifier | :? IPrefixAppExpr as prefixAppExpr -> let invokedRefExpr = prefixAppExpr.InvokedReferenceExpression diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Util/FSharpResolveUtil.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Util/FSharpResolveUtil.fs index f514d82081..39b16ee797 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Util/FSharpResolveUtil.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Services/src/Util/FSharpResolveUtil.fs @@ -109,7 +109,7 @@ let getAllMethods (reference: FSharpSymbolReference) shiftEndColumn opName = | :? IFSharpQualifiableReferenceOwner as referenceOwner -> List.ofSeq referenceOwner.Names | _ -> [reference.GetName()] - let identifier = referenceOwner.FSharpIdentifier + let identifier = referenceOwner.NameIdentifier if isNull identifier then None else let endCoords = identifier.GetDocumentEndOffset().ToDocumentCoords() diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Cache2/Parts/FSharpTypeParametersOwnerPart.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Cache2/Parts/FSharpTypeParametersOwnerPart.cs index 418b326b39..ca1a07083a 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Cache2/Parts/FSharpTypeParametersOwnerPart.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Cache2/Parts/FSharpTypeParametersOwnerPart.cs @@ -117,7 +117,7 @@ private IEnumerable GetTypeParameterConstraints(string name) foreach (var typeConstraint in GetAllTypeParameterConstraints()) foreach (var referenceName in typeConstraint.ReferenceNames) { - if (referenceName.FSharpIdentifier.GetSourceName() == name) + if (referenceName.NameIdentifier.GetSourceName() == name) yield return typeConstraint; } } @@ -162,7 +162,7 @@ private static TypeParameterConstraintFlags GetTypeConstraintFlags(string typePa { foreach (var referenceName in typeConstraint.ReferenceNames) { - if (referenceName.FSharpIdentifier.GetSourceName() == typeParamName) + if (referenceName.NameIdentifier.GetSourceName() == typeParamName) flags |= GetTypeConstraintFlags(typeParamName, typeConstraint); } } diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/FSharpArgumentsOwnerUtil.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/FSharpArgumentsOwnerUtil.cs index c0d57a69b8..8d8d61da84 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/FSharpArgumentsOwnerUtil.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/FSharpArgumentsOwnerUtil.cs @@ -102,36 +102,45 @@ argExpr is ITupleExpr tupleExpr && }).ToList(); } - public static FSharpParameterIndex? TryGetFSharpParameterIndex([NotNull] IFSharpExpression expr) + public static FSharpParameterIndex? TryGetFSharpParameterIndex([NotNull] IFSharpTypeOwnerNode node) { - // todo: named args - // todo: return property setters - - var tupleItemExpr = expr.IgnoreParentParens(); - var tupleExpr = TupleExprNavigator.GetByExpression(tupleItemExpr); - var parameterIndex = tupleExpr?.Expressions.IndexOf(tupleItemExpr); - - var argGroupExpr = tupleExpr.IgnoreParentParens() ?? tupleItemExpr; - var argOwner = FSharpArgumentOwnerNavigator.GetByArgumentExpression(argGroupExpr); - if (argOwner == null) - return null; - - if (argOwner is IAttribute or INewExpr) - return new FSharpParameterIndex(0, parameterIndex); - - var paramGroupIndex = 0; - while (argOwner is IPrefixAppExpr prefixAppExpr) + if (node is IFSharpExpression expr) { - if (prefixAppExpr.FunctionExpression is IPrefixAppExpr funPrefixAppExpr) + // todo: named args + // todo: return property setters + + var tupleItemExpr = expr.IgnoreParentParens(); + var tupleExpr = TupleExprNavigator.GetByExpression(tupleItemExpr); + var parameterIndex = tupleExpr?.Expressions.IndexOf(tupleItemExpr); + + var argGroupExpr = tupleExpr.IgnoreParentParens() ?? tupleItemExpr; + var argOwner = FSharpArgumentOwnerNavigator.GetByArgumentExpression(argGroupExpr); + if (argOwner == null) + return null; + + if (argOwner is IAttribute or INewExpr) + return new FSharpParameterIndex(0, parameterIndex); + + var paramGroupIndex = 0; + while (argOwner is IPrefixAppExpr prefixAppExpr) { - argOwner = funPrefixAppExpr; - paramGroupIndex++; + if (prefixAppExpr.FunctionExpression is IPrefixAppExpr funPrefixAppExpr) + { + argOwner = funPrefixAppExpr; + paramGroupIndex++; + } + else + break; } - else - break; + + return new FSharpParameterIndex(paramGroupIndex, parameterIndex); + } + + if (node is IFSharpPattern pat) + { } - return new FSharpParameterIndex(paramGroupIndex, parameterIndex); + return null; } } } diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/FSharpImplUtil.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/FSharpImplUtil.cs index a012882af9..0d558a9416 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/FSharpImplUtil.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/FSharpImplUtil.cs @@ -835,7 +835,7 @@ typeUsage is IParameterSignatureTypeUsage parameterSignatureTypeUsage public static IFSharpReferenceOwner SetName([NotNull] this IFSharpReferenceOwner referenceOwner, [NotNull] string name) { - if (referenceOwner.FSharpIdentifier?.IdentifierToken is { } id) + if (referenceOwner.NameIdentifier?.IdentifierToken is { } id) ModificationUtil.ReplaceChild(id, new FSharpIdentifierToken(name)); return referenceOwner; diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ActivePatternNamedCaseReferenceName.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ActivePatternNamedCaseReferenceName.cs index 03b034244f..28126dbea9 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ActivePatternNamedCaseReferenceName.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ActivePatternNamedCaseReferenceName.cs @@ -8,7 +8,7 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Tree { internal partial class ActivePatternNamedCaseReferenceName { - public override IFSharpIdentifier FSharpIdentifier => Identifier; + public override IFSharpIdentifier NameIdentifier => Identifier; public override FSharpReferenceContext? ReferenceContext => FSharpReferenceContext.Pattern; protected override FSharpSymbolReference CreateReference() => diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/Attribute.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/Attribute.cs index 542f1bd678..8a67b14a5e 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/Attribute.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/Attribute.cs @@ -15,7 +15,7 @@ internal partial class Attribute protected override FSharpSymbolReference CreateReference() => new CtorReference(this); - public override IFSharpIdentifier FSharpIdentifier => ReferenceName?.Identifier; + public override IFSharpIdentifier NameIdentifier => ReferenceName?.Identifier; public IList ParameterArguments => myParameterArguments.GetValue(this, static expr => expr.CalculateParameterArguments([expr.Expression])); diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/FieldPat.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/FieldPat.cs index c7bcb8fcc4..d6a5bd7e76 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/FieldPat.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/FieldPat.cs @@ -8,9 +8,12 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Tree; internal partial class FieldPat { - public FSharpSymbolReference Reference => ReferenceName?.Reference; + public FSharpSymbolReference Reference => ReferenceName.Reference; public string ShortName => ReferenceName?.ShortName ?? SharedImplUtil.MISSING_DECLARATION_NAME; public override IEnumerable NestedPatterns => Pattern?.NestedPatterns ?? EmptyList.Instance; + + IFSharpReferenceOwner IFSharpReferenceOwner.SetName(string name) => this.SetName(name); + public FSharpReferenceContext? ReferenceContext => FSharpReferenceContext.Pattern; } diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/LocalReferencePat.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/LocalReferencePat.cs index 87315d4e90..b7eade7a2f 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/LocalReferencePat.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/LocalReferencePat.cs @@ -30,7 +30,11 @@ public void SetIsMutable(bool value) public bool CanBeMutable => Binding != null; public IBindingLikeDeclaration Binding => this.GetBindingFromHeadPattern(); - public FSharpSymbolReference Reference => ReferenceName?.Reference; + public FSharpSymbolReference Reference => ReferenceName.Reference; + + IFSharpReferenceOwner IFSharpReferenceOwner.SetName(string name) => FSharpImplUtil.SetName(this, name); + public FSharpReferenceContext? ReferenceContext => FSharpReferenceContext.Pattern; + public override ConstantValue ConstantValue => this.GetConstantValue(); public AccessRights GetAccessRights() => FSharpModifiersUtil.GetAccessRights(AccessModifier); public IFSharpParameter FSharpParameter => this.TryGetDeclaredFSharpParameter(); diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/NewExpr.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/NewExpr.cs index dbd3464276..6419c37506 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/NewExpr.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/NewExpr.cs @@ -12,7 +12,7 @@ internal partial class NewExpr { private readonly CachedPsiValue> myParameterArguments = new FileCachedPsiValue>(); - public override IFSharpIdentifier FSharpIdentifier => TypeName?.Identifier; + public override IFSharpIdentifier NameIdentifier => TypeName?.Identifier; protected override FSharpSymbolReference CreateReference() => new CtorReference(this); diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ParametersOwnerPat.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ParametersOwnerPat.cs index 3c29032e21..934d9d5d66 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ParametersOwnerPat.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ParametersOwnerPat.cs @@ -10,5 +10,8 @@ internal partial class ParametersOwnerPat public override IEnumerable NestedPatterns => Parameters.SelectMany(param => param.NestedPatterns); - public FSharpSymbolReference Reference => ReferenceName?.Reference; + public FSharpSymbolReference Reference => ReferenceName.Reference; + + public IFSharpReferenceOwner SetName(string name) => FSharpImplUtil.SetName(this, name); + public FSharpReferenceContext? ReferenceContext => FSharpReferenceContext.Pattern; } diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/RecordExpr.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/RecordExpr.cs index d7aeadc48a..bbda997886 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/RecordExpr.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/RecordExpr.cs @@ -13,7 +13,7 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Tree { internal partial class RecordExpr { - public override IFSharpIdentifier FSharpIdentifier => null; + public override IFSharpIdentifier NameIdentifier => null; public override IFSharpReferenceOwner SetName(string name) => this; public override FSharpReferenceContext? ReferenceContext => null; diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceExpr.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceExpr.cs index c4eda47c7a..eee43c85c9 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceExpr.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceExpr.cs @@ -117,6 +117,8 @@ public override ConstantValue ConstantValue } public override bool IsConstantValue() => !ConstantValue.IsErrorOrNonCompileTimeConstantValue(); + + public IFSharpIdentifier NameIdentifier => Identifier; } public class ReferenceExpressionTypeReference : FSharpSymbolReference diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceName.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceName.cs index 12ed29a392..8144c2598d 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceName.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceName.cs @@ -11,8 +11,8 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Tree { internal partial class TypeReferenceName { - public override IFSharpIdentifier FSharpIdentifier => Identifier; - public string ShortName => FSharpIdentifier?.Name ?? SharedImplUtil.MISSING_DECLARATION_NAME; + public override IFSharpIdentifier NameIdentifier => Identifier; + public string ShortName => NameIdentifier?.Name ?? SharedImplUtil.MISSING_DECLARATION_NAME; public string QualifiedName => this.GetQualifiedName(); public IList Names => this.GetNames(); @@ -29,7 +29,7 @@ public void SetQualifier(IClrDeclaredElement declaredElement, ITreeNode context internal partial class ExpressionReferenceName { - public override IFSharpIdentifier FSharpIdentifier => Identifier; + public override IFSharpIdentifier NameIdentifier => Identifier; public override FSharpReferenceContext? ReferenceContext => ReferencePatNavigator.GetByReferenceName(this) != null @@ -38,7 +38,7 @@ internal partial class ExpressionReferenceName protected override FSharpSymbolReference CreateReference() => new(this); - public string ShortName => FSharpIdentifier?.Name ?? SharedImplUtil.MISSING_DECLARATION_NAME; + public string ShortName => NameIdentifier?.Name ?? SharedImplUtil.MISSING_DECLARATION_NAME; public string QualifiedName => this.GetQualifiedName(); public IList Names => this.GetNames(); diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceOwnerBase.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceOwnerBase.cs index 1fed7738ff..dda3a05a89 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceOwnerBase.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceOwnerBase.cs @@ -26,7 +26,7 @@ public FSharpSymbolReference Reference } } - public abstract IFSharpIdentifier FSharpIdentifier { get; } + public abstract IFSharpIdentifier NameIdentifier { get; } protected abstract FSharpSymbolReference CreateReference(); diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceOwnerExprBase.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceOwnerExprBase.cs index 32f1c125b2..59f5e9aa25 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceOwnerExprBase.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/ReferenceOwnerExprBase.cs @@ -26,7 +26,7 @@ public FSharpSymbolReference Reference } } - public abstract IFSharpIdentifier FSharpIdentifier { get; } + public abstract IFSharpIdentifier NameIdentifier { get; } protected abstract FSharpSymbolReference CreateReference(); diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/TopReferencePat.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/TopReferencePat.cs index dcbb4419d4..7c43bbdc36 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/TopReferencePat.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/TopReferencePat.cs @@ -40,7 +40,11 @@ public void SetIsMutable(bool value) } public override IBindingLikeDeclaration Binding => this.GetBindingFromHeadPattern(); - public FSharpSymbolReference Reference => ReferenceName?.Reference; + public FSharpSymbolReference Reference => ReferenceName.Reference; + + IFSharpReferenceOwner IFSharpReferenceOwner.SetName(string name) => FSharpImplUtil.SetName(this, name); + public FSharpReferenceContext? ReferenceContext => FSharpReferenceContext.Pattern; + public override ConstantValue ConstantValue => this.GetConstantValue(); public IFSharpParameter FSharpParameter => this.TryGetDeclaredFSharpParameter(); diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/TypeExtensionDeclaration.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/TypeExtensionDeclaration.cs index 9692ca3b6f..36e8c4a979 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/TypeExtensionDeclaration.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/TypeExtensionDeclaration.cs @@ -54,8 +54,6 @@ private TypeAugmentation TypeAugmentation public bool IsTypeExtensionAllowed => ModuleDeclarationNavigator.GetByMember(TypeDeclarationGroupNavigator.GetByTypeDeclaration(this)) != null; - public IFSharpIdentifier FSharpIdentifier => Identifier; - IFSharpReferenceOwner IFSharpReferenceOwner.SetName(string name) => FSharpImplUtil.SetName(this, name); diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/TypeInherit.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/TypeInherit.cs index 6ea9177c1f..e0aa9d8c4b 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/TypeInherit.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Impl/Tree/TypeInherit.cs @@ -6,7 +6,7 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Tree internal partial class TypeInherit { protected override FSharpSymbolReference CreateReference() => new(this); - public override IFSharpIdentifier FSharpIdentifier => TypeName?.Identifier; + public override IFSharpIdentifier NameIdentifier => TypeName?.Identifier; public override FSharpReferenceContext? ReferenceContext => FSharpReferenceContext.Type; } diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Resolve/FSharpSymbolReference.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Resolve/FSharpSymbolReference.cs index ae1c030958..c51b7b2849 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Resolve/FSharpSymbolReference.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Resolve/FSharpSymbolReference.cs @@ -36,7 +36,7 @@ public virtual TreeOffset SymbolOffset { get { - if (myOwner.FSharpIdentifier is { } fsIdentifier) + if (myOwner.NameIdentifier is { } fsIdentifier) return fsIdentifier.NodeType == FSharpTokenType.LPAREN_STAR_RPAREN ? fsIdentifier.GetTreeStartOffset() : fsIdentifier.NameRange.StartOffset; @@ -89,7 +89,7 @@ protected virtual IDeclaredElement GetDeclaredElement() } public override string GetName() => - myOwner.FSharpIdentifier?.Name ?? SharedImplUtil.MISSING_DECLARATION_NAME; + myOwner.NameIdentifier?.Name ?? SharedImplUtil.MISSING_DECLARATION_NAME; public override bool HasMultipleNames => AttributeNavigator.GetByReferenceName(myOwner as ITypeReferenceName) != null; @@ -103,7 +103,7 @@ public override HybridCollection GetAllNames() } public override TreeTextRange GetTreeTextRange() => - myOwner.FSharpIdentifier?.NameRange ?? TreeTextRange.InvalidRange; + myOwner.NameIdentifier?.NameRange ?? TreeTextRange.InvalidRange; public override IAccessContext GetAccessContext() => new DefaultAccessContext(myOwner); @@ -160,7 +160,7 @@ public FSharpList ResolveWithFcs([NotNull] string opName, bool : new[] {GetName()}; var symbolUses = - checkerService.ResolveNameAtLocation(referenceOwner.FSharpIdentifier, names, resolveExpr, opName); + checkerService.ResolveNameAtLocation(referenceOwner.NameIdentifier, names, resolveExpr, opName); return FilterSymbols(symbolUses); } diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Resolve/TypeExtensionReference.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Resolve/TypeExtensionReference.cs index 976764a298..6bbd3e1436 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Resolve/TypeExtensionReference.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Resolve/TypeExtensionReference.cs @@ -12,7 +12,7 @@ public TypeExtensionReference([NotNull] IFSharpReferenceOwner owner) : base(owne public override FSharpSymbol GetFcsSymbol() { - var token = myOwner.FSharpIdentifier?.IdentifierToken; + var token = myOwner.NameIdentifier?.IdentifierToken; if (token == null) return null; diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpExpression.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpExpression.cs index 7cf8c5a948..580190e02a 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpExpression.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpExpression.cs @@ -2,7 +2,5 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Tree { - public partial interface IFSharpExpression : IExpression - { - } + public partial interface IFSharpExpression : IFSharpTypeOwnerNode, IExpression; } diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpPattern.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpPattern.cs index bd81c21a35..c1f6426519 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpPattern.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpPattern.cs @@ -5,7 +5,7 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Tree { - public partial interface IFSharpPattern : IFSharpParameterDeclaration, IConstantValueOwner + public partial interface IFSharpPattern : IFSharpParameterDeclaration, IFSharpTypeOwnerNode, IConstantValueOwner { /// In simple cases uses syntax to determine whether this pattern uses an existing symbol or introduces a new one. /// In complex cases uses resolve via FCS. diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpReferenceOwner.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpReferenceOwner.cs index aaafb49c46..94d2c4f8c0 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpReferenceOwner.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpReferenceOwner.cs @@ -18,12 +18,10 @@ public enum FSharpReferenceContext Type } - public interface IFSharpReferenceOwner : IFSharpTreeNode + public interface IFSharpReferenceOwner : INameIdentifierOwner { [NotNull] FSharpSymbolReference Reference { get; } - [CanBeNull] IFSharpIdentifier FSharpIdentifier { get; } - [NotNull] IFSharpReferenceOwner SetName([NotNull] string name); @@ -44,7 +42,7 @@ public static void SetQualifier([NotNull] this IFSharpQualifiableReferenceOwner [NotNull] Func factory, [NotNull] IClrDeclaredElement declaredElement, ITreeNode context = null) { - var identifier = referenceOwner.FSharpIdentifier; + var identifier = referenceOwner.NameIdentifier; Assertion.Assert(identifier != null, "referenceOwner.FSharpIdentifier != null"); // todo: type args diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpTypeOwnerNode.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpTypeOwnerNode.cs new file mode 100644 index 0000000000..fc26b0be02 --- /dev/null +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFSharpTypeOwnerNode.cs @@ -0,0 +1,10 @@ +using FSharp.Compiler.Symbols; +using JetBrains.Annotations; + +namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Tree; + +public interface IFSharpTypeOwnerNode : IFSharpTreeNode +{ + // todo + // [CanBeNull] FSharpType FcsType { get; } +} diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFieldPat.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFieldPat.cs new file mode 100644 index 0000000000..da9738e70b --- /dev/null +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IFieldPat.cs @@ -0,0 +1,8 @@ +using JetBrains.Annotations; + +namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Tree; + +public partial interface IFieldPat +{ + [NotNull] string ShortName { get; } +} diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IReferenceOwnerPat.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IReferenceOwnerPat.cs index e084640a7e..c852a8ae9e 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IReferenceOwnerPat.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IReferenceOwnerPat.cs @@ -1,10 +1,4 @@ -using JetBrains.Annotations; -using JetBrains.ReSharper.Plugins.FSharp.Psi.Resolve; - namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Tree { - public partial interface IReferenceNameOwnerPat - { - [CanBeNull] FSharpSymbolReference Reference { get; } - } + public partial interface IReferenceNameOwnerPat : IFSharpReferenceOwner; } diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IReferencePat.cs b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IReferencePat.cs index e1431fb15a..1e068d051c 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IReferencePat.cs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi/src/Tree/IReferencePat.cs @@ -8,9 +8,4 @@ public partial interface IReferencePat : IMutableModifierOwner, IFSharpDeclarati bool IsLocal { get; } [CanBeNull] IBindingLikeDeclaration Binding { get; } } - - public partial interface IFieldPat - { - [NotNull] string ShortName { get; } - } } diff --git a/ReSharper.FSharp/test/data/features/quickFixes/changeType/init/Record - Pattern 01.fs b/ReSharper.FSharp/test/data/features/quickFixes/changeType/init/Record - Pattern 01.fs new file mode 100644 index 0000000000..a6c9428bbf --- /dev/null +++ b/ReSharper.FSharp/test/data/features/quickFixes/changeType/init/Record - Pattern 01.fs @@ -0,0 +1,6 @@ +module Module + +type R = { Field: int } + +match { Field = 1 } with +| { Field = ""{caret} } -> () diff --git a/ReSharper.FSharp/test/data/features/quickFixes/changeType/init/Record - Pattern 01.fs.gold b/ReSharper.FSharp/test/data/features/quickFixes/changeType/init/Record - Pattern 01.fs.gold new file mode 100644 index 0000000000..fb800074f3 --- /dev/null +++ b/ReSharper.FSharp/test/data/features/quickFixes/changeType/init/Record - Pattern 01.fs.gold @@ -0,0 +1,6 @@ +module Module + +type R = { Field: string } + +match { Field = 1 } with +| { Field = ""{caret} } -> () diff --git a/ReSharper.FSharp/test/data/features/quickFixes/changeType/reference/Literal - Expr 01.fs b/ReSharper.FSharp/test/data/features/quickFixes/changeType/reference/Literal - Expr 01.fs new file mode 100644 index 0000000000..3eb119b3ea --- /dev/null +++ b/ReSharper.FSharp/test/data/features/quickFixes/changeType/reference/Literal - Expr 01.fs @@ -0,0 +1,5 @@ +module Module + +let [] I = 1 + +let s: string = I{caret} diff --git a/ReSharper.FSharp/test/data/features/quickFixes/changeType/reference/Literal - Expr 01.fs.gold b/ReSharper.FSharp/test/data/features/quickFixes/changeType/reference/Literal - Expr 01.fs.gold new file mode 100644 index 0000000000..12d557fa0a --- /dev/null +++ b/ReSharper.FSharp/test/data/features/quickFixes/changeType/reference/Literal - Expr 01.fs.gold @@ -0,0 +1,5 @@ +module Module + +let [] I: string = 1 + +let s: string = I{caret} diff --git a/ReSharper.FSharp/test/data/features/quickFixes/changeType/reference/Literal - Pattern 01.fs b/ReSharper.FSharp/test/data/features/quickFixes/changeType/reference/Literal - Pattern 01.fs new file mode 100644 index 0000000000..f59a796c5b --- /dev/null +++ b/ReSharper.FSharp/test/data/features/quickFixes/changeType/reference/Literal - Pattern 01.fs @@ -0,0 +1,6 @@ +module Module + +let [] I = 1 + +match "" with +| I{caret} -> () diff --git a/ReSharper.FSharp/test/src/FSharp.Intentions.Tests/src/QuickFixes/ReplaceReturnTypeTest.fs b/ReSharper.FSharp/test/src/FSharp.Intentions.Tests/src/QuickFixes/ReplaceReturnTypeTest.fs index 87b1bb0da8..1dd4c67a03 100644 --- a/ReSharper.FSharp/test/src/FSharp.Intentions.Tests/src/QuickFixes/ReplaceReturnTypeTest.fs +++ b/ReSharper.FSharp/test/src/FSharp.Intentions.Tests/src/QuickFixes/ReplaceReturnTypeTest.fs @@ -99,6 +99,9 @@ type ChangeElementTypeTest() = [] member x.``Field - Record 03``() = x.DoNamedTest() [] member x.``Field - Struct 01``() = x.DoNamedTest() + [] member x.``Literal - Expr 01``() = x.DoNamedTest() + [] member x.``Literal - Pattern 01``() = x.DoNamedTest() + [] member x.``Prop - Auto 01``() = x.DoNamedTest() [] member x.``Prop - Auto 02``() = x.DoNamedTest() [] member x.``Prop - Auto 03``() = x.DoNamedTest() @@ -130,6 +133,7 @@ type ChangeElementTypeFromFieldBindingTest() = override x.RelativeTestDataPath = "features/quickFixes/changeType/init" + [] member x.``Record - Pattern 01``() = x.DoNamedTest() [] member x.``Record 01``() = x.DoNamedTest() [] member x.``Record 02``() = x.DoNamedTest() [] member x.``Record 03``() = x.DoNamedTest()