-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Find usages and completion for ShaderLab properties #362
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6ccbe52
Introduce ReferenceName for variable refrences
citizenmatt 000a94e
Add first class references for variables
citizenmatt 7067193
Add declarations and declared elements
citizenmatt 894a8bb
Resolve references to property declarations
citizenmatt 4e2fd60
Add find usages and context highlighting
citizenmatt 07851a2
Disable PSI for duplicate .shader files
citizenmatt 47b21f7
Add resolve error handle for multiple candidates
citizenmatt 48cfa5e
Respect Rider's context usage highlight option
citizenmatt 8c5b339
Add warnings for multiply declared properties
citizenmatt 517605d
Add tests for property usage highlights
citizenmatt 1ba982c
Add tests for ShaderLab property resolve
citizenmatt 9488435
Add tests for multiple property candidates
citizenmatt 8a91bfc
Add code completion for variable references
citizenmatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
resharper/src/resharper-unity/ShaderLab/Daemon/Stages/Resolve/ResolveProblemHighlighter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using JetBrains.ReSharper.Feature.Services.Daemon; | ||
using JetBrains.ReSharper.Plugins.Unity.ShaderLab.Daemon.Errors; | ||
using JetBrains.ReSharper.Plugins.Unity.ShaderLab.Psi; | ||
using JetBrains.ReSharper.Psi.Resolve; | ||
using JetBrains.ReSharper.Psi.Tree; | ||
|
||
namespace JetBrains.ReSharper.Plugins.Unity.ShaderLab.Daemon.Stages.Resolve | ||
{ | ||
internal class ResolveProblemHighlighter | ||
{ | ||
private readonly ResolveHighlighterRegistrar myResolveHighlighterRegistrar; | ||
|
||
public ResolveProblemHighlighter(ResolveHighlighterRegistrar resolveHighlighterRegistrar) | ||
{ | ||
myResolveHighlighterRegistrar = resolveHighlighterRegistrar; | ||
} | ||
|
||
public void CheckForResolveProblems(ITreeNode node, IHighlightingConsumer consumer, ReferenceCollection references) | ||
{ | ||
foreach (var reference in references) | ||
CheckForResolveProblems(consumer, reference); | ||
} | ||
|
||
private void CheckForResolveProblems(IHighlightingConsumer consumer, IReference reference) | ||
{ | ||
var error = reference.CheckResolveResult(); | ||
if (error == null) | ||
throw new InvalidOperationException("ResolveErrorType is null for reference " + reference.GetType().FullName); | ||
|
||
if (error == ResolveErrorType.OK) | ||
return; | ||
|
||
if (myResolveHighlighterRegistrar.ContainsHandler(ShaderLabLanguage.Instance, error)) | ||
{ | ||
var highlighting = myResolveHighlighterRegistrar.GetResolveHighlighting(reference, error); | ||
if (highlighting != null) | ||
consumer.AddHighlighting(highlighting); | ||
} | ||
else | ||
consumer.AddHighlighting(new NotResolvedError(reference)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
resharper/src/resharper-unity/ShaderLab/Psi/DeclaredElements/IShaderLabDeclaredElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using JetBrains.ReSharper.Psi; | ||
|
||
namespace JetBrains.ReSharper.Plugins.Unity.ShaderLab.Psi.DeclaredElements | ||
{ | ||
public interface IShaderLabDeclaredElement : IDeclaredElement | ||
{ | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
resharper/src/resharper-unity/ShaderLab/Psi/DeclaredElements/PropertyDeclaredElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using JetBrains.ReSharper.Psi; | ||
|
||
namespace JetBrains.ReSharper.Plugins.Unity.ShaderLab.Psi.DeclaredElements | ||
{ | ||
public class PropertyDeclaredElement : ShaderLabDeclaredElementBase | ||
{ | ||
public PropertyDeclaredElement(string shortName, IPsiSourceFile sourceFile, int treeOffset) | ||
: base(shortName, sourceFile, treeOffset) | ||
{ | ||
} | ||
|
||
public override DeclaredElementType GetElementType() => ShaderLabDeclaredElementType.Property; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
resharper/src/resharper-unity/ShaderLab/Psi/DeclaredElements/ShaderLabDeclaredElementBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System.Collections.Generic; | ||
using System.Xml; | ||
using JetBrains.ReSharper.Plugins.Unity.ShaderLab.Psi.Tree; | ||
using JetBrains.ReSharper.Psi; | ||
using JetBrains.ReSharper.Psi.Files; | ||
using JetBrains.ReSharper.Psi.Tree; | ||
using JetBrains.Util; | ||
using JetBrains.Util.DataStructures; | ||
|
||
namespace JetBrains.ReSharper.Plugins.Unity.ShaderLab.Psi.DeclaredElements | ||
{ | ||
public abstract class ShaderLabDeclaredElementBase : IShaderLabDeclaredElement | ||
{ | ||
private readonly IPsiSourceFile mySourceFile; | ||
private readonly int myTreeOffset; | ||
|
||
protected ShaderLabDeclaredElementBase(string shortName, IPsiSourceFile sourceFile, int treeOffset) | ||
{ | ||
mySourceFile = sourceFile; | ||
myTreeOffset = treeOffset; | ||
ShortName = shortName; | ||
} | ||
|
||
public IPsiServices GetPsiServices() | ||
{ | ||
return mySourceFile.GetPsiServices(); | ||
} | ||
|
||
public IList<IDeclaration> GetDeclarations() | ||
{ | ||
if (!(mySourceFile.GetPrimaryPsiFile() is IShaderLabFile psi)) | ||
return EmptyList<IDeclaration>.InstanceList; | ||
|
||
var node = psi.FindNodeAt(TreeTextRange.FromLength(new TreeOffset(myTreeOffset), 1)); | ||
while (node != null && !(node is IDeclaration)) | ||
node = node.Parent; | ||
if (node == null) | ||
return EmptyList<IDeclaration>.Instance; | ||
|
||
return new[] {(IDeclaration) node}; | ||
} | ||
|
||
public IList<IDeclaration> GetDeclarationsIn(IPsiSourceFile sourceFile) | ||
{ | ||
if (mySourceFile == sourceFile) | ||
return GetDeclarations(); | ||
return EmptyList<IDeclaration>.Instance; | ||
} | ||
|
||
public abstract DeclaredElementType GetElementType(); | ||
|
||
public XmlNode GetXMLDoc(bool inherit) => null; | ||
public XmlNode GetXMLDescriptionSummary(bool inherit) => null; | ||
public bool IsValid() => true; | ||
public bool IsSynthetic() => false; | ||
|
||
public HybridCollection<IPsiSourceFile> GetSourceFiles() | ||
{ | ||
return new HybridCollection<IPsiSourceFile>(mySourceFile); | ||
} | ||
|
||
public bool HasDeclarationsIn(IPsiSourceFile sourceFile) | ||
{ | ||
return mySourceFile == sourceFile; | ||
} | ||
|
||
public string ShortName { get; } | ||
public bool CaseSensitiveName => true; // TODO: Check! | ||
|
||
// ReSharper disable once AssignNullToNotNullAttribute | ||
public PsiLanguageType PresentationLanguage => ShaderLabLanguage.Instance; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...r/src/resharper-unity/ShaderLab/Psi/DeclaredElements/ShaderLabDeclaredElementPresenter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using JetBrains.ReSharper.Psi; | ||
using JetBrains.ReSharper.Psi.Resolve; | ||
using JetBrains.Util; | ||
|
||
namespace JetBrains.ReSharper.Plugins.Unity.ShaderLab.Psi.DeclaredElements | ||
{ | ||
[PsiSharedComponent] | ||
public class ShaderLabDeclaredElementPresenter : IDeclaredElementPresenter | ||
{ | ||
public string Format(DeclaredElementPresenterStyle style, IDeclaredElement element, ISubstitution substitution, | ||
out DeclaredElementPresenterMarking marking) | ||
{ | ||
marking = new DeclaredElementPresenterMarking(); | ||
if (!(element is IShaderLabDeclaredElement)) | ||
return null; | ||
|
||
// TODO: Type (Float, Color, etc.), display name, etc. | ||
marking.NameRange = new TextRange(0, element.ShortName.Length); | ||
return element.ShortName; | ||
} | ||
|
||
public string Format(ParameterKind parameterKind) => string.Empty; | ||
public string Format(AccessRights accessRights) => string.Empty; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
resharper/src/resharper-unity/ShaderLab/Psi/DeclaredElements/ShaderLabDeclaredElementType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using JetBrains.ReSharper.Psi; | ||
using JetBrains.ReSharper.Psi.Resources; | ||
using JetBrains.UI.Icons; | ||
|
||
namespace JetBrains.ReSharper.Plugins.Unity.ShaderLab.Psi.DeclaredElements | ||
{ | ||
public class ShaderLabDeclaredElementType : DeclaredElementType | ||
{ | ||
// TODO: Proper icon | ||
public static readonly ShaderLabDeclaredElementType Property = new ShaderLabDeclaredElementType("Property", PsiSymbolsThemedIcons.Property.Id); | ||
|
||
private readonly IconId myIconId; | ||
|
||
private ShaderLabDeclaredElementType(string name, IconId iconId) | ||
: base(name) | ||
{ | ||
PresentableName = name; | ||
myIconId = iconId; | ||
} | ||
|
||
public override string PresentableName { get; } | ||
protected override IconId GetImage() => myIconId; | ||
public override bool IsPresentable(PsiLanguageType language) => language.Is<ShaderLabLanguage>(); | ||
protected override IDeclaredElementPresenter DefaultPresenter => | ||
ShaderLabLanguage.Instance.DeclaredElementPresenter(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want some unity-specific icon here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I'll add a request