Skip to content

Commit fd9dd3c

Browse files
committed
demo
1 parent d23c7fe commit fd9dd3c

File tree

1 file changed

+37
-45
lines changed

1 file changed

+37
-45
lines changed

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

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,6 @@ module FSharpErrors =
9090
let [<Literal>] XmlDocSignatureCheckFailed = 3390
9191
let [<Literal>] InvalidXmlDocPosition = 3520
9292

93-
let [<Literal>] ifExprMissingElseBranch = "This 'if' expression is missing an 'else' branch."
94-
let [<Literal>] expressionIsAFunctionMessage = "This expression is a function value, i.e. is missing arguments. Its type is "
95-
let [<Literal>] butItsSignatureSpecifies = "but its signature specifies"
96-
let [<Literal>] theModuleContainsTheField = "The module contains the field"
97-
let [<Literal>] typeConstraintMismatchMessage = "Type constraint mismatch. The type \n '(.+)' \nis not compatible with type\n '(.+)'"
98-
99-
let [<Literal>] typeEquationMessage = "This expression was expected to have type\n '(.+)' \nbut here has type\n '(.+)'"
100-
let [<Literal>] typeDoesNotMatchMessage = "Type mismatch. Expecting a\n '(.+)' \nbut given a\n '(.+)'"
101-
let [<Literal>] elseBranchHasWrongTypeMessage = "All branches of an 'if' expression must return values implicitly convertible to the type of the first branch, which here is '(.+)'. This branch returns a value of type '(.+)'."
102-
let [<Literal>] matchClauseHasWrongTypeMessage = "All branches of a pattern match expression must return values implicitly convertible to the type of the first branch, which here is '(.+)'. This branch returns a value of type '(.+)'."
103-
let [<Literal>] ifBranchSatisfyContextTypeRequirements = "The 'if' expression needs to have type '(.+)' to satisfy context type requirements\. It currently has type '(.+)'"
104-
let [<Literal>] typeMisMatchTupleLengths = "Type mismatch. Expecting a\n '(.+)' \nbut given a\n '(.+)' \nThe tuples have differing lengths of \\d+ and \\d+"
105-
let [<Literal>] argumentNamesInTheSignatureAndImplementationDoNotMatch = "The argument names in the signature '(.+)' and implementation '(.+)' do not match. The argument name from the signature file will be used. This may cause problems when debugging or profiling."
106-
10793
let isDirectiveSyntaxError number =
10894
number >= 232 && number <= 235
10995

@@ -194,33 +180,39 @@ type FcsErrorsStageProcessBase(fsFile, daemonProcess) =
194180
| null -> null
195181
| expr -> highlightingCtor (expected, actual, expr, error.Message) :> _
196182

197-
match error.Message with
198-
| message when message.StartsWith(ifExprMissingElseBranch, StringComparison.Ordinal) ->
183+
match error.ExtendedData with
184+
| Some(:? TypeMismatchDiagnosticExtendedData as data)
185+
when data.ContextInfo = DiagnosticContextInfo.OmittedElseBranch ->
186+
199187
createHighlightingFromNodeWithMessage UnitTypeExpectedError range error
200188

201-
| Regex typeEquationMessage [expectedType; actualType]
202-
| Regex elseBranchHasWrongTypeMessage [expectedType; actualType] ->
189+
| Some(:? TypeMismatchDiagnosticExtendedData as data)
190+
when data.ContextInfo = DiagnosticContextInfo.FollowingPatternMatchClause ->
191+
192+
createTypeMismatchHighlighting
193+
MatchClauseWrongTypeError
194+
(data.ExpectedType.Format(data.DisplayContext))
195+
(data.ActualType.Format(data.DisplayContext))
196+
197+
| Some(:? TypeMismatchDiagnosticExtendedData as data) ->
198+
let expectedType = data.ExpectedType
199+
let actualType = data.ActualType
200+
let dataDisplayContext = data.DisplayContext
201+
202+
if expectedType.IsTupleType && actualType.IsTupleType &&
203+
expectedType.GenericArguments.Count <> actualType.GenericArguments.Count then
204+
createTypeMismatchHighlighting TypeMisMatchTuplesHaveDifferingLengthsError (expectedType.Format(dataDisplayContext)) (actualType.Format(dataDisplayContext))
205+
206+
else
203207
let expr = nodeSelectionProvider.GetExpressionInRange(fsFile, range, false, null)
204208
let expr = getResultExpr expr
205209
if isNotNull expr then
206-
match expectedType with
207-
| "unit" -> createHighlightingFromNodeWithMessage UnitTypeExpectedError range error
208-
| _ -> TypeEquationError(expectedType, actualType, expr, error.Message) :> _
210+
if data.ExpectedType.Format(dataDisplayContext) = "unit" then
211+
createHighlightingFromNodeWithMessage UnitTypeExpectedError range error
212+
else TypeEquationError(expectedType.Format(dataDisplayContext), actualType.Format(dataDisplayContext), expr, error.Message) :> _
209213
else
210214
null
211215

212-
| Regex matchClauseHasWrongTypeMessage [expectedType; actualType] ->
213-
createTypeMismatchHighlighting MatchClauseWrongTypeError expectedType actualType
214-
215-
| Regex typeMisMatchTupleLengths [expectedType; actualType] ->
216-
createTypeMismatchHighlighting TypeMisMatchTuplesHaveDifferingLengthsError expectedType actualType
217-
218-
| Regex typeDoesNotMatchMessage [expectedType; actualType] ->
219-
createTypeMismatchHighlighting TypeDoesNotMatchTypeError expectedType actualType
220-
221-
| Regex ifBranchSatisfyContextTypeRequirements [expectedType; actualType] ->
222-
createTypeMismatchHighlighting IfExpressionNeedsTypeToSatisfyTypeRequirementsError expectedType actualType
223-
224216
| _ -> createGenericHighlighting error range
225217

226218
| NotAFunction ->
@@ -317,10 +309,10 @@ type FcsErrorsStageProcessBase(fsFile, daemonProcess) =
317309
ValueNotMutableError(refExpr) :> _
318310

319311
| ValueNotContainedMutability ->
320-
if error.Message.EndsWith("The mutability attributes differ") then
312+
match error.ExtendedData with
313+
| Some (:? ValueNotContainedDiagnosticExtendedData) ->
321314
createHighlightingFromNodeWithMessage ValueNotContainedMutabilityAttributesDifferError range error
322-
else
323-
createGenericHighlighting error range
315+
| _ -> createGenericHighlighting error range
324316

325317
| UnitTypeExpected ->
326318
createHighlightingFromMappedExpression getResultExpr UnitTypeExpectedWarning range error
@@ -422,11 +414,11 @@ type FcsErrorsStageProcessBase(fsFile, daemonProcess) =
422414
createHighlightingFromNode LiteralPatternDoesNotTakeArgumentsError range
423415

424416
| ArgumentNamesInSignatureAndImplementationDoNotMatch ->
425-
match error.Message with
426-
| Regex argumentNamesInTheSignatureAndImplementationDoNotMatch [ signature; implementation ] ->
417+
match error.ExtendedData with
418+
| Some (:? ArgumentsInSigAndImplMismatchExtendedData as data) ->
427419
match nodeSelectionProvider.GetExpressionInRange(fsFile, range, false, null) with
428420
| null -> null
429-
| expr -> ArgumentNameMismatchWarning(expr, signature, implementation, error.Message) :> _
421+
| expr -> ArgumentNameMismatchWarning(expr, data.SignatureName, data.ImplementationName, error.Message) :> _
430422

431423
| _ -> null
432424

@@ -472,23 +464,23 @@ type FcsErrorsStageProcessBase(fsFile, daemonProcess) =
472464
createHighlightingFromNodeWithMessage EmptyRecordInvalidError range error
473465

474466
| MissingErrorNumber ->
475-
match error.Message with
476-
| x when startsWith expressionIsAFunctionMessage x ->
467+
match error.ExtendedData with
468+
| Some (:? ExpressionIsAFunctionExtendedData) ->
477469
createHighlightingFromMappedExpression getResultExpr FunctionValueUnexpectedWarning range error
478470

479-
| x when (x.Contains(theModuleContainsTheField) && x.Contains(butItsSignatureSpecifies)) ->
471+
| Some (:? FieldNotContainedDiagnosticExtendedData) ->
480472
createHighlightingFromParentNodeWithMessage FieldNotContainedTypesDifferError range error
481473

482-
| Regex typeConstraintMismatchMessage [mismatchedType; typeConstraint] ->
474+
| Some (:? TypeMismatchDiagnosticExtendedData as data) ->
483475
let highlighting =
484-
match typeConstraint with
476+
match data.ExpectedType.Format(data.DisplayContext) with
485477
| "unit" -> createHighlightingFromMappedExpression getResultExpr UnitTypeExpectedError range error
486478
| _ -> null
487479

488480
if isNotNull highlighting then highlighting else
489481

490482
let expr = nodeSelectionProvider.GetExpressionInRange(fsFile, range, false, null)
491-
if isNotNull expr then TypeConstraintMismatchError(mismatchedType, expr, error.Message) else null
483+
if isNotNull expr then TypeConstraintMismatchError(data.ActualType.Format(data.DisplayContext), expr, error.Message) else null
492484

493485
| _ -> null
494486

0 commit comments

Comments
 (0)