Skip to content

Commit bdfbec1

Browse files
authored
Merge pull request #1003 from JetBrains/bug/RIDER-23429
Downgrade unresolved symbol error to warning
2 parents c85e1c6 + 54dac2e commit bdfbec1

File tree

10 files changed

+73
-33
lines changed

10 files changed

+73
-33
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ This plugin has functionality that is common to both ReSharper and Rider. It als
1717
- Mark more methods as expensive inside a performance critical context (#1000)
1818
- Improve performance of rename and find usages with YAML files (#983)
1919
- Improve performance of typing in YAML files, by incrementally re-parsing only the YAML document that contains the change (#993)
20+
- Remove repeated use of project name from Unity Explorer when under assembly definition (#982, #989)
21+
- Changed unresolved symbol error in `GetComponent`, `AddComponent` and `ScriptableObject.CreateInstance` to a configurable warning ([RIDER-23429](https://youtrack.jetbrains.com/issue/RIDER-23429), #1003)
2022

2123
### Fixed
2224
- Fix processing hierarchy for YAML scene files (#985)
@@ -84,7 +86,7 @@ This plugin has functionality that is common to both ReSharper and Rider. It als
8486
* For Rider 2018.3.1. Not released for ReSharper
8587
* [Commits](https://github.com/JetBrains/resharper-unity/compare/183-eap10-rtm...183-eap11-rtm)
8688
* [Milestone](https://github.com/JetBrains/resharper-unity/milestone/23?closed=1)
87-
* [Tag](https://github.com/JetBrains/resharper-unity/releases/tag/183-eap11-rtm)
89+
* [GitHub release](https://github.com/JetBrains/resharper-unity/releases/tag/183-eap11-rtm)
8890

8991
### Added
9092
- Automatically disable YAML parsing if the project is too large (#973)
@@ -100,7 +102,7 @@ This plugin has functionality that is common to both ReSharper and Rider. It als
100102
* For Rider 2018.3. Not released for ReSharper
101103
* [Commits](https://github.com/JetBrains/resharper-unity/compare/182-eap12-2018.2.3...183-eap10-rtm)
102104
* [Milestone](https://github.com/JetBrains/resharper-unity/milestone/19?closed=1)
103-
* [Tag](https://github.com/JetBrains/resharper-unity/releases/tag/183-eap11-rtm)
105+
* [GitHub release](https://github.com/JetBrains/resharper-unity/releases/tag/183-eap10-rtm)
104106

105107
### Added
106108
- Add parsing of method and class usage from scene, prefab and asset files (#263, [RIDER-7460](https://youtrack.jetbrains.com/issue/RIDER-7460), #870, #873, #903, #921, [RIDER-21907](https://youtrack.jetbrains.com/issue/RIDER-21907), [RIDER-21897](https://youtrack.jetbrains.com/issue/RIDER-21897), #943, #949)

resharper/resharper-unity/src/CSharp/Daemon/Errors/CSharpErrors.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@
194194
</Description>
195195
<CompoundItemName>Possible unintended bypass of lifetime check of underlying Unity engine object</CompoundItemName>
196196
</Tag>
197+
198+
<Tag externalName="UnresolvedComponentOrScriptableObjectWarning.HIGHLIGHTING_ID" default="WARNING">
199+
<Title>Cannot resolve component or scriptable object</Title>
200+
<Description>
201+
The class referred to in the call to 'GetComponent', 'AddComponent' or 'ScriptableObject.CreateInstance' cannot
202+
be found in the current project or referenced assemblies. The call is likely to fail at runtime and return null.
203+
</Description>
204+
</Tag>
197205
</Group>
198206
</SeverityConfiguration>
199207

@@ -486,4 +494,12 @@
486494
<Range>Expression.GetHighlightingRange()</Range>
487495
<Behavour overlapResolvePolicy="WARNING" />
488496
</Warning>
497+
498+
<Warning name="UnresolvedComponentOrScriptableObject" configurableSeverity="Unity.UnresolvedComponentOrScriptableObject">
499+
<Parameter type="IReference" name="reference" />
500+
<Message value="Cannot resolve symbol '{0}'">
501+
<Argument>Reference.GetName()</Argument>
502+
</Message>
503+
<Range>Reference.GetDocumentRange()</Range>
504+
</Warning>
489505
</Errors>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
namespace JetBrains.ReSharper.Plugins.Unity.CSharp.Feature.Services.Daemon
1010
{
1111
[Language(typeof(CSharpLanguage))]
12-
public class UnityObjectIncorrectBaseTypeErrorHandler : IResolveProblemHighlighter
12+
public class UnityObjectReferenceErrorHandler : IResolveProblemHighlighter
1313
{
1414
// We only get called for our known resolve errors
1515
public IHighlighting Run(IReference reference)
1616
{
1717
var errorType = reference.CheckResolveResult();
18+
if (errorType == UnityResolveErrorType.UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT)
19+
return new UnresolvedComponentOrScriptableObjectWarning(reference);
1820
if (errorType == UnityResolveErrorType.EXPECTED_COMPONENT)
1921
return new ExpectedComponentWarning(reference, KnownTypes.Component.FullName);
2022
if (errorType == UnityResolveErrorType.EXPECTED_MONO_BEHAVIOUR)
@@ -27,6 +29,7 @@ public IHighlighting Run(IReference reference)
2729

2830
public IEnumerable<ResolveErrorType> ErrorTypes => new[]
2931
{
32+
UnityResolveErrorType.UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT,
3033
UnityResolveErrorType.EXPECTED_COMPONENT,
3134
UnityResolveErrorType.EXPECTED_MONO_BEHAVIOUR,
3235
UnityResolveErrorType.EXPECTED_SCRIPTABLE_OBJECT

resharper/resharper-unity/src/CSharp/Psi/Resolve/UnityObjectTypeOrNamespaceReference.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ protected override IReference BindToInternal(IDeclaredElement declaredElement, I
8080
return this;
8181
}
8282

83+
public override ResolveResultWithInfo GetResolveResult(ISymbolTable symbolTable, string referenceName)
84+
{
85+
var result = base.GetResolveResult(symbolTable, referenceName);
86+
if (result.ResolveErrorType == ResolveErrorType.NOT_RESOLVED)
87+
{
88+
// It's not necessarily an error that we can't resolve. It might be that GetComponent (or whatever) is
89+
// being used as part of a modular architecture
90+
return new ResolveResultWithInfo(result.Result, UnityResolveErrorType.UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT);
91+
}
92+
93+
return result;
94+
}
95+
8396
public override ISymbolTable GetReferenceSymbolTable(bool useReferenceName)
8497
{
8598
if (myQualifier == null && myIsFinalPart)

resharper/resharper-unity/src/CSharp/Psi/Resolve/UnityResolveErrorType.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@ private UnityResolveErrorType([NotNull] string name)
2424

2525
[NotNull] public static readonly ResolveErrorType EXPECTED_SCRIPTABLE_OBJECT =
2626
new UnityResolveErrorType("EXPECTED_SCRIPTABLE_OBJECT");
27+
28+
[NotNull] public static readonly ResolveErrorType UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT =
29+
new UnityResolveErrorType("UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT");
2730
}
2831
}

resharper/resharper-unity/src/resharper-unity.resharper.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
- Improve redundant event function warnings
6767
- Stop Generate Code dialog selecting all event functions by default when called from the gutter icon or Code Vision marker
6868
- Prevent Respeller running on .asmdef files
69+
- Changed unresolved symbol error in `GetComponent`, `AddComponent` and `ScriptableObject.CreateInstance` to a configurable warning (RIDER-23429, #1003)
6970
- Fix C# language level override incorrectly handling latest
7071
- Fix to stop generating readonly modifier when converting auto property to property with serialised backing field
7172
- Fix bug in ShaderLab parsing Blend operations

resharper/resharper-unity/test/data/CSharp/Resolve/UnityObjectTypeInStringLiteral/AddComponent01.cs.gold

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ namespace Other
9292
}
9393

9494
------------------------------------------------
95-
0: result=NOT_RESOLVED declaredElem=null
96-
1: result=NOT_RESOLVED declaredElem=null
95+
0: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
96+
1: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
9797
2: result=TYPE_EXPECTED declaredElem=INotAClass
98-
3: result=NOT_RESOLVED declaredElem=null
99-
4: result=NOT_RESOLVED declaredElem=null
100-
5: result=NOT_RESOLVED declaredElem=null
101-
6: result=NOT_RESOLVED declaredElem=null
98+
3: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
99+
4: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
100+
5: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
101+
6: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
102102
7: result=OK declaredElem=Other
103-
8: result=NOT_RESOLVED declaredElem=null
104-
9: result=NOT_RESOLVED declaredElem=null
103+
8: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
104+
9: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
105105
10: result=EXPECTED_MONO_BEHAVIOUR declaredElem=WrongBaseType
106106
11: result=EXPECTED_MONO_BEHAVIOUR declaredElem=WrongComponentBaseType
107107
12: result=INCORRECT_TYPE_PARAMETER_NUMBER declaredElem=MonoBehaviourWithTypeParameter<T>
@@ -117,7 +117,7 @@ namespace Other
117117
22: result=OK declaredElem=Nested1.Nested2.Nested3.Nested4.MonoBehaviourInNestedNamespace
118118
23: result=OK declaredElem=Other
119119
24: result=OK declaredElem=Other.MonoBehaviourInOtherNamespace
120-
25: result=NOT_RESOLVED declaredElem=null
120+
25: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
121121
26: result=EXPECTED_COMPONENT declaredElem=null
122122
Candidates:
123123
UnityEditor.CrashReporting
@@ -134,7 +134,7 @@ Candidates:
134134
31: result=OK declaredElem=UnityEngine.HingeJoint
135135
32: result=OK declaredElem=Other
136136
33: result=OK declaredElem=Other.MonoBehaviourInOtherNamespace
137-
34: result=NOT_RESOLVED declaredElem=null
137+
34: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
138138
35: result=MULTIPLE_CANDIDATES declaredElem=null
139139
Candidates:
140140
Grid

resharper/resharper-unity/test/data/CSharp/Resolve/UnityObjectTypeInStringLiteral/GetComponent01.cs.gold

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ namespace Other
9090
}
9191

9292
------------------------------------------------
93-
0: result=NOT_RESOLVED declaredElem=null
94-
1: result=NOT_RESOLVED declaredElem=null
93+
0: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
94+
1: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
9595
2: result=TYPE_EXPECTED declaredElem=INotAClass
96-
3: result=NOT_RESOLVED declaredElem=null
97-
4: result=NOT_RESOLVED declaredElem=null
98-
5: result=NOT_RESOLVED declaredElem=null
99-
6: result=NOT_RESOLVED declaredElem=null
96+
3: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
97+
4: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
98+
5: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
99+
6: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
100100
7: result=OK declaredElem=Other
101-
8: result=NOT_RESOLVED declaredElem=null
102-
9: result=NOT_RESOLVED declaredElem=null
101+
8: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
102+
9: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
103103
10: result=EXPECTED_MONO_BEHAVIOUR declaredElem=WrongBaseType
104104
11: result=EXPECTED_MONO_BEHAVIOUR declaredElem=WrongComponentBaseType
105105
12: result=INCORRECT_TYPE_PARAMETER_NUMBER declaredElem=MonoBehaviourWithTypeParameter<T>
@@ -115,7 +115,7 @@ namespace Other
115115
22: result=OK declaredElem=Nested1.Nested2.Nested3.Nested4.MonoBehaviourInNestedNamespace
116116
23: result=OK declaredElem=Other
117117
24: result=OK declaredElem=Other.MonoBehaviourInOtherNamespace
118-
25: result=NOT_RESOLVED declaredElem=null
118+
25: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
119119
26: result=EXPECTED_COMPONENT declaredElem=null
120120
Candidates:
121121
UnityEditor.CrashReporting
@@ -132,7 +132,7 @@ Candidates:
132132
31: result=OK declaredElem=UnityEngine.HingeJoint
133133
32: result=OK declaredElem=Other
134134
33: result=OK declaredElem=Other.MonoBehaviourInOtherNamespace
135-
34: result=NOT_RESOLVED declaredElem=null
135+
34: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
136136
35: result=MULTIPLE_CANDIDATES declaredElem=null
137137
Candidates:
138138
Grid

resharper/resharper-unity/test/data/CSharp/Resolve/UnityObjectTypeInStringLiteral/ScriptableObjectCreateInstance01.cs.gold

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ namespace Nested1
7676
}
7777

7878
------------------------------------------------
79-
0: result=NOT_RESOLVED declaredElem=null
80-
1: result=NOT_RESOLVED declaredElem=null
79+
0: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
80+
1: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
8181
2: result=TYPE_EXPECTED declaredElem=INotAClass
82-
3: result=NOT_RESOLVED declaredElem=null
83-
4: result=NOT_RESOLVED declaredElem=null
84-
5: result=NOT_RESOLVED declaredElem=null
85-
6: result=NOT_RESOLVED declaredElem=null
82+
3: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
83+
4: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
84+
5: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
85+
6: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
8686
7: result=OK declaredElem=Other
87-
8: result=NOT_RESOLVED declaredElem=null
88-
9: result=NOT_RESOLVED declaredElem=null
87+
8: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
88+
9: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
8989
10: result=EXPECTED_SCRIPTABLE_OBJECT declaredElem=WrongBaseType
9090
11: result=INCORRECT_TYPE_PARAMETER_NUMBER declaredElem=ScriptableObjectWithTypeParameter<T>
9191
12: result=OK declaredElem=ScriptableObjectInGlobalNamespace
@@ -100,11 +100,11 @@ namespace Nested1
100100
21: result=OK declaredElem=Nested1.Nested2.Nested3.Nested4.ScriptableObjectInNestedNamespace
101101
22: result=OK declaredElem=Other
102102
23: result=OK declaredElem=Other.ScriptableObjectInOtherNamespace
103-
24: result=NOT_RESOLVED declaredElem=null
103+
24: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null
104104
25: result=MULTIPLE_CANDIDATES declaredElem=null
105105
Candidates:
106106
MultipleCandidates
107107
Other.MultipleCandidates
108108
26: result=OK declaredElem=Other
109109
27: result=OK declaredElem=Other.ScriptableObjectInOtherNamespace
110-
28: result=NOT_RESOLVED declaredElem=null
110+
28: result=UNRESOLVED_COMPONENT_OR_SCRIPTABLE_OBJECT declaredElem=null

rider/src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@
192192
<li>Mark more methods as expensive inside a performance critical context (<a href="https://github.com/JetBrains/resharper-unity/issues/1000">#1000</a>)</li>
193193
<li>Improve performance of rename and find usages with YAML files (<a href="https://github.com/JetBrains/resharper-unity/issues/983">#983</a>)</li>
194194
<li>Improve performance of typing in YAML files, by incrementally re-parsing only the YAML document that contains the change (<a href="https://github.com/JetBrains/resharper-unity/issues/993">#993</a>)</li>
195+
<li>Remove repeated use of project name from Unity Explorer when under assembly definition (<a href="https://github.com/JetBrains/resharper-unity/issues/982">#982</a>, <a href="https://github.com/JetBrains/resharper-unity/pull/989">#989</a>)</li>
196+
<li>Changed unresolved symbol error in `GetComponent`, `AddComponent` and `ScriptableObject.CreateInstance` to a configurable warning (<a href="https://youtrack.jetbrains.com/issue/RIDER-23429">RIDER-23429</a>, <a href="https://github.com/JetBrains/resharper-unity/issues/1003">#1003</a>)</li>
195197
</ul>
196198
<em>Fixed:</em>
197199
<ul>

0 commit comments

Comments
 (0)