Skip to content

Commit 20cfc0f

Browse files
committed
Merge pull request #37 from JetBrains/injectables_code_completion
Type information for injected services
2 parents 63cd61f + b5fe974 commit 20cfc0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1441
-58
lines changed

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public JsInvocationProcessor(AngularJsCacheItemsBuilder cacheItemsBuilder)
1414

1515
public void ProcessInvocationExpression(IInvocationExpression invocationExpression)
1616
{
17-
if (invocationExpression.Arguments.Count <= 1)
17+
if (invocationExpression.Arguments.Count != 2)
1818
return;
1919

2020
var stringLiteralExpression = invocationExpression.Arguments[0];
21-
var identifier = GetStringLiteralValue(stringLiteralExpression);
21+
var identifier = stringLiteralExpression.GetStringLiteralValue();
2222
if (identifier == null)
2323
return;
2424

@@ -34,15 +34,6 @@ public void ProcessInvocationExpression(IInvocationExpression invocationExpressi
3434
}
3535
}
3636

37-
private static string GetStringLiteralValue(IExpressionOrSpread expresion)
38-
{
39-
var literalExpression = expresion as IJavaScriptLiteralExpression;
40-
if (literalExpression != null && literalExpression.IsStringLiteral())
41-
return literalExpression.GetStringValue();
42-
43-
return null;
44-
}
45-
4637
private void ProcessDirective(IInvocationExpression invokedExpression, string identifier, int offset)
4738
{
4839
if (invokedExpression.Arguments.Count != 2)
@@ -104,7 +95,7 @@ private static string CalculateRestrictions(IInvocationExpression invokedExpress
10495
foreach (var initializer in objectLiteral.Properties.OfType<IObjectPropertyInitializer>())
10596
{
10697
if (initializer.DeclaredName == "restrict")
107-
return GetStringLiteralValue(initializer.Value) ?? defaultRestrictions;
98+
return initializer.Value.GetStringLiteralValue() ?? defaultRestrictions;
10899
}
109100
return defaultRestrictions;
110101
}

src/resharper-angularjs/Psi/JavaScript/Resolve/AngularServiceTypeInfoSupplier.cs

Lines changed: 570 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#region license
2+
// Copyright 2015 JetBrains s.r.o.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
#endregion
16+
17+
using JetBrains.ReSharper.Psi.JavaScript.Tree;
18+
using JetBrains.ReSharper.Psi.Tree;
19+
20+
namespace JetBrains.ReSharper.Plugins.AngularJS
21+
{
22+
public static class TreeNodeExtensions
23+
{
24+
public static string GetStringLiteralValue(this ITreeNode treeNode)
25+
{
26+
var literalExpression = treeNode as IJavaScriptLiteralExpression;
27+
if (literalExpression != null && literalExpression.IsStringLiteral())
28+
return literalExpression.GetStringValue();
29+
30+
return null;
31+
}
32+
}
33+
}

src/resharper-angularjs/resharper-angularjs.csproj

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@
161161
</Reference>
162162
</ItemGroup>
163163
<ItemGroup>
164-
<Compile Include="Daemon\AngularJs\Stages\AngularJsDaemonStageBase.cs" />
165-
<Compile Include="Daemon\AngularJs\Stages\AngularJsIdentifierHighlighterProcess.cs" />
166-
<Compile Include="Daemon\AngularJs\Stages\IdentifierHighlightingStage.cs" />
167164
<Compile Include="Feature\Services\Caches\AngularJsCache.cs" />
168165
<Compile Include="Feature\Services\Caches\AngularJsCacheItems.cs" />
169166
<Compile Include="Feature\Services\Caches\AngularJsCacheItemsBuilder.cs" />
@@ -178,42 +175,13 @@
178175
<Compile Include="Hacks\CodeCompletion\AutomaticTagItemsProvider.cs" />
179176
<Compile Include="Feature\Services\CodeCompletion\OverriddenAngularJsItemsRemover.cs" />
180177
<Compile Include="Feature\Services\Descriptions\AngularJsHtmlElementDescriptionProvider.cs" />
181-
<Compile Include="Psi\AngularJs\AngularJsLanguage.cs" />
182-
<Compile Include="Psi\AngularJs\AngularJsLanguageService.cs" />
183-
<Compile Include="Psi\AngularJs\CodeStyle\AngularJsCodeFormatter.cs" />
184-
<Compile Include="Psi\AngularJs\CodeStyle\AngularJsFormattingInfoProvider.cs" />
185-
<Compile Include="Psi\AngularJs\CodeStyle\AngularJsIndentingInfoProvider.cs" />
186-
<Compile Include="Psi\AngularJs\InjectedPsiProvider.cs" />
187-
<Compile Include="Psi\AngularJs\Parsing\AngularJsLexer.cs" />
188-
<Compile Include="Psi\AngularJs\Parsing\AngularJsParser.cs" />
189-
<Compile Include="Psi\AngularJs\Parsing\AngularJsTokenType.cs" />
190-
<Compile Include="Psi\AngularJs\Parsing\AngularJsTokenType.generated.cs">
191-
<DependentUpon>AngularJsTokenType.Tokens.xml</DependentUpon>
192-
</Compile>
193-
<Compile Include="Psi\AngularJs\Parsing\AngularJsTreeBuilder.cs" />
194-
<Compile Include="Psi\AngularJs\Parsing\Angular_lex.cs">
195-
<DependentUpon>Angular.lex</DependentUpon>
196-
</Compile>
197-
<Compile Include="Psi\AngularJs\Parsing\Tree\AngularJsElementType.cs" />
198-
<Compile Include="Psi\AngularJs\Parsing\Tree\FilterArgumentList.cs" />
199-
<Compile Include="Psi\AngularJs\Parsing\Tree\FilterExpression.8.2.cs" />
200-
<Compile Include="Psi\AngularJs\Parsing\Tree\FilterExpression.9.0.cs" />
201-
<Compile Include="Psi\AngularJs\Parsing\Tree\FilterExpression.cs" />
202-
<Compile Include="Psi\AngularJs\Parsing\Tree\RepeatExpression.8.2.cs" />
203-
<Compile Include="Psi\AngularJs\Parsing\Tree\RepeatExpression.9.0.cs" />
204-
<Compile Include="Psi\AngularJs\Parsing\Tree\RepeatExpression.cs" />
205-
<Compile Include="Psi\AngularJs\References\AngularJsFileLateBoundReference.cs" />
206-
<Compile Include="Psi\AngularJs\References\AngularJsFolderLateBoundReference.cs" />
207-
<Compile Include="Psi\AngularJs\References\AngularJsIncludeFileReferenceProvider.cs" />
208-
<Compile Include="Psi\AngularJs\References\AngularJsReferenceFactoryBase.cs" />
209-
<Compile Include="Psi\AngularJs\References\IgnoreRootPathFilter.cs" />
210-
<Compile Include="Psi\AngularJs\Tree\AngularJsFileData.cs" />
211-
<Compile Include="Psi\AngularJs\Tree\AngularJsNodeTypes.cs" />
212178
<Compile Include="Psi\Html\AngularJsDeclaredElementIconProvider.cs" />
213179
<Compile Include="Psi\Html\AngularJsHtmlAttributeDeclaredElement.cs" />
214180
<Compile Include="Psi\Html\AngularJsHtmlTagDeclaredElement.cs" />
215181
<Compile Include="Psi\Html\IAngularJsDeclaredElement.cs" />
182+
<Compile Include="Psi\JavaScript\Resolve\AngularServiceTypeInfoSupplier.cs" />
216183
<Compile Include="Resources\Logo\ThemedIcons.Logo.Generated.cs" />
184+
<Compile Include="TreeNodeExtensions.cs" />
217185
<Compile Include="ZoneMarker.cs" />
218186
<Compile Include="Properties\AssemblyInfo.cs" />
219187
<Compile Include="Psi\Html\AngularJsHtmlElementsProvider.cs" />
@@ -243,14 +211,6 @@
243211
<SubType>Designer</SubType>
244212
</ThemedIconsXamlV3>
245213
</ItemGroup>
246-
<ItemGroup>
247-
<CsLex Include="Psi\AngularJs\Parsing\Angular.lex" />
248-
</ItemGroup>
249-
<ItemGroup>
250-
<TokenGenerator Include="Psi\AngularJs\Parsing\AngularJsTokenType.Tokens.xml">
251-
<SubType>Designer</SubType>
252-
</TokenGenerator>
253-
</ItemGroup>
254214
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
255215
<Import Project="$(ReSharperSdkTools)\PsiGen\TokenGenerator.Targets" Condition="Exists('$(ReSharperSdkTools)\PsiGen\TokenGenerator.Targets')" />
256216
<Import Project="..\packages\JetBrains.Platform.Core.Shell.103.0.20150818.190334\build\JetBrains.Platform.Core.Shell.Targets" Condition="Exists('..\packages\JetBrains.Platform.Core.Shell.103.0.20150818.190334\build\JetBrains.Platform.Core.Shell.Targets')" />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Provider declared as a named function
2+
// $get is simple function
3+
module.controller('c1', function($cacheFactory, $cacheFactoryProvider) {
4+
var get = $cacheFactoryProvider.get;
5+
$cacheFactory.info();
6+
});
7+
8+
// Provider declared as a named function
9+
// $get method is injected function
10+
module.controller('c2', function($anchorScroll, $anchorScrollProvider) {
11+
$anchorScrollProvider.disableAutoScrolling();
12+
$anchorScroll('#foo');
13+
});
14+
15+
// Provider defined as an injected function, assigned to a variable
16+
module.controller('c3', function($animate, $animateProvider) {
17+
$animateProvider.register('thing', function() {
18+
return {};
19+
});
20+
$animate.on('enter', container,
21+
function callback(element, phase) {
22+
// cool we detected an enter animation within the container
23+
}
24+
);
25+
});
26+
27+
// Get method return value dependent on injected value
28+
module.controller('c4', function($templateCache) {
29+
var x = $templateCache.remove('templateId.html');
30+
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Provider declared as a named function
2+
// $get is simple function
3+
module.controller('c1', function($cacheFactory, $cacheFactoryProvider) {
4+
var get = |$cacheFactoryProvider|(0).|get|(1);
5+
|$cacheFactory|(2).|info|(3)();
6+
});
7+
8+
// Provider declared as a named function
9+
// $get method is injected function
10+
module.controller('c2', function($anchorScroll, $anchorScrollProvider) {
11+
|$anchorScrollProvider|(4).|disableAutoScrolling|(5)();
12+
|$anchorScroll|(6)('#foo');
13+
});
14+
15+
// Provider defined as an injected function, assigned to a variable
16+
module.controller('c3', function($animate, $animateProvider) {
17+
|$animateProvider|(7).|register|(8)('thing', function() {
18+
return {};
19+
});
20+
|$animate|(9).|on|(10)('enter', container,
21+
function callback(element, phase) {
22+
// cool we detected an enter animation within the container
23+
}
24+
);
25+
});
26+
27+
// Get method return value dependent on injected value
28+
module.controller('c4', function($templateCache) {
29+
var x = |$templateCache|(11).|remove|(12)('templateId.html');
30+
});
31+
32+
------------------------------------------------
33+
0: result=OK declaredElem=parameter $cacheFactoryProvider : any ($cacheFactory/
34+
void)
35+
1: result=DYNAMIC_OK declaredElem=property get : any
36+
2: result=OK declaredElem=parameter $cacheFactory : any ((cacheId: any, options: any) => any ({put; get; remove; removeAll; destroy; info; })/
37+
Function)
38+
3: result=DYNAMIC_OK declaredElem=property info : any (() => any)
39+
4: result=OK declaredElem=parameter $anchorScrollProvider : any ($anchorScroll/
40+
void)
41+
5: result=DYNAMIC_OK declaredElem=property disableAutoScrolling : any (() => void)
42+
6: result=OK declaredElem=parameter $anchorScroll : any ((hash: any) => void/
43+
Function)
44+
7: result=OK declaredElem=parameter $animateProvider : any ($animate/
45+
void)
46+
8: result=DYNAMIC_OK declaredElem=property register : any ((name: any, factory: any) => void)
47+
9: result=OK declaredElem=parameter $animate : any ({
48+
on;
49+
off;
50+
pin;
51+
enabled;
52+
cancel;
53+
enter;
54+
move;
55+
leave;
56+
addClass;
57+
...
58+
})
59+
10: result=DYNAMIC_OK declaredElem=property on : any (() => void)
60+
11: result=OK declaredElem=parameter $templateCache : any ({
61+
put;
62+
get;
63+
remove;
64+
removeAll;
65+
destroy;
66+
info;
67+
})
68+
12: result=DYNAMIC_OK declaredElem=property remove : any ((key: any) => void)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.controller('myController', [ '$log', '$logProvider', function(l, lp) {
2+
lp.debugEnabled(true);
3+
l.debug('hello');
4+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.controller('myController', [ '$log', '$logProvider', function(l, lp) {
2+
|lp|(0).|debugEnabled|(1)(true);
3+
|l|(2).|debug|(3)('hello');
4+
});
5+
6+
------------------------------------------------
7+
0: result=OK declaredElem=parameter lp : any ($log/
8+
void)
9+
1: result=DYNAMIC_OK declaredElem=property debugEnabled : any ((flag: any) => any (debugEnabled/void/...))
10+
2: result=OK declaredElem=parameter l : any ({
11+
log;
12+
info;
13+
warn;
14+
error;
15+
debug;
16+
})
17+
3: result=DYNAMIC_OK declaredElem=property debug : any (() => void)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.value('myValue', 42);
2+
3+
module.factory('myFactory', function() {
4+
return {
5+
'sayHi': function(name) {
6+
return 'Hi ' + name;
7+
}
8+
}
9+
});
10+
11+
module.service('myService', function() {
12+
this.sayHello = function(name) {
13+
return 'Hi ' + name;
14+
}
15+
this.sayGoodbye = function(name) {
16+
return 'Bye ' + name;
17+
}
18+
});
19+
20+
module.controller('myController', [ 'myValue', 'myFactory', 'myService', function(v, f, s) {
21+
var p = v * 2;
22+
f.sayHi('Matt');
23+
s.sayHello('Matt');
24+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.value('myValue', 42);
2+
3+
module.factory('myFactory', function() {
4+
return {
5+
'sayHi': function(name) {
6+
return 'Hi ' + name;
7+
}
8+
}
9+
});
10+
11+
module.service('myService', function() {
12+
this.sayHello = function(name) {
13+
return 'Hi ' + name;
14+
}
15+
this.sayGoodbye = function(name) {
16+
return 'Bye ' + name;
17+
}
18+
});
19+
20+
module.controller('myController', [ 'myValue', 'myFactory', 'myService', function(v, f, s) {
21+
var p = |v|(0) * 2;
22+
|f|(1).|sayHi|(2)('Matt');
23+
|s|(3).|sayHello|(4)('Matt');
24+
});
25+
26+
------------------------------------------------
27+
0: result=OK declaredElem=parameter v : any (number)
28+
1: result=OK declaredElem=parameter f : any ({
29+
sayHi;
30+
})
31+
2: result=DYNAMIC_OK declaredElem=property sayHi : any ((name: any) => any (number/string))
32+
3: result=OK declaredElem=parameter s : any (void)
33+
4: result=DYNAMIC_OK declaredElem=property sayHello : any ((name: any) => any (number/string))

0 commit comments

Comments
 (0)