Skip to content

Commit 47a36c3

Browse files
committed
Code completion includes element directives
Directives that override standard HTML elements are not included. Element parameters are not included.
1 parent 29de193 commit 47a36c3

16 files changed

+33504
-549
lines changed

src/resharper-angularjs/Feature/Services/Caches/AngularJsCache.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ namespace JetBrains.ReSharper.Plugins.AngularJS.Feature.Services.Caches
3535
{
3636
public class Directive
3737
{
38+
public const string AnyTagName = "ANY";
39+
3840
public readonly string OriginalName;
3941
public readonly string Name;
4042
public readonly string Restrictions;
@@ -58,24 +60,29 @@ public Directive(string originalName, string name, string restrictions, string[]
5860
public bool IsElement { get; private set; }
5961
public bool IsClass { get; private set; }
6062

61-
public bool IsForTag(string tag)
63+
public bool IsForTag(string tagName)
6264
{
6365
foreach (var t in Tags)
6466
{
65-
if (t.Equals("ANY", StringComparison.InvariantCultureIgnoreCase) ||
66-
t.Equals(tag, StringComparison.InvariantCultureIgnoreCase))
67+
if (t.Equals(AnyTagName, StringComparison.InvariantCultureIgnoreCase) ||
68+
t.Equals(tagName, StringComparison.InvariantCultureIgnoreCase))
6769
{
6870
return true;
6971
}
7072
}
7173
return false;
7274
}
7375

76+
public bool IsForTagSpecific(string tagName)
77+
{
78+
return Tags.Any(t => t.Equals(tagName, StringComparison.InvariantCultureIgnoreCase));
79+
}
80+
7481
public bool IsForAnyTag()
7582
{
7683
foreach (var t in Tags)
7784
{
78-
if (t.Equals("ANY", StringComparison.InvariantCultureIgnoreCase))
85+
if (t.Equals(AnyTagName, StringComparison.InvariantCultureIgnoreCase))
7986
return true;
8087
}
8188
return false;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Linq;
2+
using JetBrains.ReSharper.Feature.Services.CodeCompletion.Infrastructure;
3+
using JetBrains.ReSharper.Feature.Services.CodeCompletion.Infrastructure.LookupItems;
4+
using JetBrains.ReSharper.Features.Intellisense.CodeCompletion.Html;
5+
using JetBrains.ReSharper.Plugins.AngularJS.Psi.Html;
6+
using JetBrains.ReSharper.Psi;
7+
using JetBrains.ReSharper.Psi.Html;
8+
9+
namespace JetBrains.ReSharper.Plugins.AngularJS.Feature.Services.CodeCompletion
10+
{
11+
// Removes the regular HTML declared elements that match AngularJS items, e.g. the
12+
// `a` element is implemented by
13+
[Language(typeof (HtmlLanguage))]
14+
public class OverriddenAngularJsItemsRemover : ItemsProviderOfSpecificContext<HtmlCodeCompletionContext>
15+
{
16+
protected override void TransformItems(HtmlCodeCompletionContext context, GroupedItemsCollector collector)
17+
{
18+
var angularItems = (from item in collector.Items
19+
let unwrappedItem = GetDeclaredElementLookupItem(item)
20+
where
21+
unwrappedItem != null &&
22+
unwrappedItem.GetPreferredDeclaredElement().Element is IAngularJsDeclaredElement
23+
select item).ToHashSet();
24+
var angularItemNames = angularItems.ToHashSet(i => i.DisplayName.Text);
25+
var toRemove = from item in collector.Items
26+
where !angularItems.Contains(item) && angularItemNames.Contains(item.DisplayName.Text)
27+
select item;
28+
29+
foreach (var item in toRemove.ToList())
30+
collector.Remove(item);
31+
}
32+
33+
private static IDeclaredElementLookupItem GetDeclaredElementLookupItem(ILookupItem item)
34+
{
35+
var wrapped = item as IWrappedLookupItem;
36+
if (wrapped != null)
37+
return wrapped.Item as IDeclaredElementLookupItem;
38+
return item as IDeclaredElementLookupItem;
39+
}
40+
}
41+
}

src/resharper-angularjs/Psi/Html/AngularJsHtmlElementsProvider.cs

Lines changed: 200 additions & 44 deletions
Large diffs are not rendered by default.
Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,130 @@
11
using System.Collections.Generic;
22
using System.Xml;
33
using JetBrains.ReSharper.Psi;
4+
using JetBrains.ReSharper.Psi.Html;
45
using JetBrains.ReSharper.Psi.Html.Html;
6+
using JetBrains.ReSharper.Psi.Html.Impl.Html;
7+
using JetBrains.ReSharper.Psi.Html.Impl.TagPrefixes;
58
using JetBrains.ReSharper.Psi.Html.Tree;
69
using JetBrains.ReSharper.Psi.Tree;
10+
using JetBrains.Util;
711
using JetBrains.Util.DataStructures;
812

913
namespace JetBrains.ReSharper.Plugins.AngularJS.Psi.Html
1014
{
11-
public class AngularJsHtmlTagDeclaredElement : IHtmlTagDeclaredElement
15+
public class AngularJsHtmlTagDeclaredElement : IHtmlTagDeclaredElement, IAngularJsDeclaredElement
1216
{
17+
private readonly IPsiServices psiServices;
18+
private readonly HtmlDeclaredElementsCache declaredElementsCache;
19+
20+
public AngularJsHtmlTagDeclaredElement(IPsiServices psiServices, HtmlDeclaredElementsCache declaredElementsCache,
21+
string shortName, IEnumerable<AttributeInfo> ownAttributes, IEnumerable<AttributeInfo> inheritedAttributes)
22+
{
23+
ShortName = shortName;
24+
this.psiServices = psiServices;
25+
this.declaredElementsCache = declaredElementsCache;
26+
OwnAttributes = ownAttributes;
27+
InheritedAttributes = inheritedAttributes;
28+
}
29+
1330
public IPsiServices GetPsiServices()
1431
{
15-
throw new System.NotImplementedException();
32+
return psiServices;
1633
}
1734

1835
public IList<IDeclaration> GetDeclarations()
1936
{
20-
throw new System.NotImplementedException();
37+
// TODO: Return proper declarations
38+
// Can this work? Declaration might be a comment node!?
39+
return EmptyList<IDeclaration>.InstanceList;
2140
}
2241

2342
public IList<IDeclaration> GetDeclarationsIn(IPsiSourceFile sourceFile)
2443
{
25-
throw new System.NotImplementedException();
44+
// TODO: Return proper declarations
45+
// Can this work? Declaration might be a comment node!?
46+
return EmptyList<IDeclaration>.InstanceList;
2647
}
2748

2849
public DeclaredElementType GetElementType()
2950
{
30-
throw new System.NotImplementedException();
51+
return HtmlDeclaredElementType.HTML_TAG;
3152
}
3253

3354
public XmlNode GetXMLDoc(bool inherit)
3455
{
35-
throw new System.NotImplementedException();
56+
return null;
3657
}
3758

3859
public XmlNode GetXMLDescriptionSummary(bool inherit)
3960
{
40-
throw new System.NotImplementedException();
61+
return null;
4162
}
4263

4364
public bool IsValid()
4465
{
45-
throw new System.NotImplementedException();
66+
return true;
4667
}
4768

4869
public bool IsSynthetic()
4970
{
50-
throw new System.NotImplementedException();
71+
return false;
5172
}
5273

5374
public HybridCollection<IPsiSourceFile> GetSourceFiles()
5475
{
55-
throw new System.NotImplementedException();
76+
// TODO: Should be able to return source file
77+
return HybridCollection<IPsiSourceFile>.Empty;
5678
}
5779

5880
public bool HasDeclarationsIn(IPsiSourceFile sourceFile)
5981
{
60-
throw new System.NotImplementedException();
82+
// TODO: Should be able to return source file
83+
return false;
6184
}
6285

6386
public string ShortName { get; private set; }
64-
public bool CaseSensistiveName { get; private set; }
65-
public PsiLanguageType PresentationLanguage { get; private set; }
66-
public bool Obsolete { get; private set; }
67-
public bool NonStandard { get; private set; }
87+
public bool CaseSensistiveName { get { return false; } }
88+
public PsiLanguageType PresentationLanguage { get { return HtmlLanguage.Instance; } }
89+
public bool Obsolete { get { return false; } }
90+
public bool NonStandard { get { return false; } }
91+
6892
public IEnumerable<AttributeInfo> GetAllowedAttributes(IPsiSourceFile sourceFile, bool strict = false)
6993
{
70-
throw new System.NotImplementedException();
94+
return CollectionUtil.EnumerateAll(OwnAttributes, InheritedAttributes,
95+
declaredElementsCache.GetAdditionalAttributesForTag(sourceFile, this, strict));
7196
}
7297

7398
public IType GetType(IHtmlTag treeTag)
7499
{
75-
throw new System.NotImplementedException();
100+
// This is used by asp.net, to map tags to controls, I think
101+
return TypeFactory.CreateUnknownType(treeTag.GetPsiModule(), treeTag.GetResolveContext());
76102
}
77103

78-
public TagClosingRequirement ClosingRequirement { get; private set; }
104+
public TagClosingRequirement ClosingRequirement { get { return TagClosingRequirement.REGULAR_TAG_CLOSING_REQUIRED; } }
105+
106+
// OwnAttributes are tag specific. InheritedAttributes are shared between tags (e.g. I18N, events, etc.)
107+
// The only real difference here is sorting when showing a description - own are shown before inherited
79108
public IEnumerable<AttributeInfo> OwnAttributes { get; private set; }
80109
public IEnumerable<AttributeInfo> InheritedAttributes { get; private set; }
81-
public bool OnlyOnce { get; private set; }
110+
111+
public bool OnlyOnce { get { return false; } }
112+
113+
public override bool Equals(object obj)
114+
{
115+
if (ReferenceEquals(this, obj)) return true;
116+
117+
var attribute = obj as AngularJsHtmlAttributeDeclaredElement;
118+
if (attribute == null) return false;
119+
120+
// TODO: Other fields?
121+
return attribute.ShortName == ShortName;
122+
}
123+
124+
public override int GetHashCode()
125+
{
126+
// TODO: Other fields?
127+
return ShortName.GetHashCode();
128+
}
82129
}
83130
}

src/resharper-angularjs/Resources/Logo/ThemedIcons.Logo.Generated.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by a tool.
4-
// Runtime Version:4.0.30319.0
4+
// Runtime Version:4.0.30319.42000
55
//
66
// Changes to this file may cause incorrect behavior and will be lost if
77
// the code is regenerated.

src/resharper-angularjs/resharper-angularjs.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
<Compile Include="Feature\Services\Caches\AngularJsCache.cs" />
150150
<Compile Include="Feature\Services\CodeCompletion\AbbreviatedItemsProvider.cs" />
151151
<Compile Include="Feature\Services\CodeCompletion\AbbreviatedTextLookupItem.cs" />
152+
<Compile Include="Feature\Services\CodeCompletion\OverriddenAngularJsItemsRemover.cs" />
152153
<Compile Include="Feature\Services\Descriptions\AngularJsHtmlElementDescriptionProvider.cs" />
153154
<Compile Include="Psi\Html\AngularJsDeclaredElementIconProvider.cs" />
154155
<Compile Include="Psi\Html\AngularJsHtmlAttributeDeclaredElement.cs" />

0 commit comments

Comments
 (0)