Skip to content

Commit 60f8782

Browse files
committed
Merged 1.1.1 to master
2 parents 4795257 + f5ccb61 commit 60f8782

File tree

4 files changed

+40
-49
lines changed

4 files changed

+40
-49
lines changed

resources/META-INF/plugin.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<idea-plugin version="2">
1111
<id>com.intellij.lang.jsgraphql</id>
1212
<name>JS GraphQL</name>
13-
<version>1.1.0</version>
13+
<version>1.1.1</version>
1414
<vendor>Jim Kynde Meyer - [email protected]</vendor>
1515

1616
<description><![CDATA[
@@ -27,11 +27,13 @@
2727
</ul>
2828
]]></description>
2929

30-
<!--<change-notes><![CDATA[-->
31-
<!--Add change notes here.<br>-->
32-
<!--<em>most HTML tags may be used</em>-->
33-
<!--]]>-->
34-
<!--</change-notes>-->
30+
<change-notes><![CDATA[
31+
<ul>
32+
<li>1.1.1: Completion after ... fragment spread operator. Language Service 1.1.1 based on graphql 0.4.16 and codemirror-graphql 0.2.2</li>
33+
<li>1.1.0: Find usages, schema viewer, structure view</li>
34+
</ul>
35+
]]>
36+
</change-notes>
3537

3638
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
3739
<idea-version since-build="143.0"/>

src/main/com/intellij/lang/jsgraphql/ide/completion/JSGraphQLCompletionContributor.java

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,30 @@ protected void addCompletions(@NotNull final CompletionParameters parameters, Pr
5757

5858
result = updateResult(parameters, result);
5959

60-
if(hints.getHints().isEmpty()) {
61-
// temporary '...' completion for #4 until it's supported by codemirror-graphql -- https://github.com/graphql/codemirror-graphql/issues/7
62-
// we simply return the fragment names in the file without filtering on their applicability
63-
PsiElement originalPosition = parameters.getOriginalPosition();
64-
if(originalPosition != null) {
65-
if(originalPosition instanceof PsiWhiteSpace) {
66-
// this is the completion invoked right after '...'
67-
final PsiElement prevSibling = originalPosition.getPrevSibling();
68-
if(prevSibling != null) {
69-
final boolean isKeyword = prevSibling.getNode().getElementType() == JSGraphQLTokenTypes.KEYWORD;
70-
if(isKeyword && JSGraphQLKeywords.FRAGMENT_DOTS.equals(prevSibling.getText())) {
71-
final PsiFile file = prevSibling.getContainingFile();
72-
addFragmentCompletions(result, file);
73-
}
60+
// check if the completion was invoked after the '...' fragment spread keyword
61+
boolean isFragmentSpreadCompletion = false;
62+
PsiElement originalPosition = parameters.getOriginalPosition();
63+
if(originalPosition != null) {
64+
if(originalPosition instanceof PsiWhiteSpace) {
65+
// this is the completion invoked right after '...'
66+
final PsiElement prevSibling = originalPosition.getPrevSibling();
67+
if(prevSibling != null) {
68+
final boolean isKeyword = prevSibling.getNode().getElementType() == JSGraphQLTokenTypes.KEYWORD;
69+
if(isKeyword && JSGraphQLKeywords.FRAGMENT_DOTS.equals(prevSibling.getText())) {
70+
isFragmentSpreadCompletion = true;
7471
}
75-
} else if(originalPosition.getParent() instanceof JSGraphQLNamedTypePsiElement) {
76-
// completion inside the fragment name, e.g. after '...Fra'
77-
for (PsiElement child = originalPosition.getParent().getPrevSibling(); child != null; child = child.getPrevSibling()) {
78-
if(child instanceof PsiWhiteSpace) {
79-
continue;
80-
}
81-
final boolean isKeyword = child.getNode().getElementType() == JSGraphQLTokenTypes.KEYWORD;
82-
if(isKeyword && JSGraphQLKeywords.FRAGMENT_DOTS.equals(child.getText())) {
83-
addFragmentCompletions(result, child.getContainingFile());
84-
}
85-
break;
72+
}
73+
} else if(originalPosition.getParent() instanceof JSGraphQLNamedTypePsiElement) {
74+
// completion inside the fragment name, e.g. after '...Fra'
75+
for (PsiElement child = originalPosition.getParent().getPrevSibling(); child != null; child = child.getPrevSibling()) {
76+
if(child instanceof PsiWhiteSpace) {
77+
continue;
78+
}
79+
final boolean isKeyword = child.getNode().getElementType() == JSGraphQLTokenTypes.KEYWORD;
80+
if(isKeyword && JSGraphQLKeywords.FRAGMENT_DOTS.equals(child.getText())) {
81+
isFragmentSpreadCompletion = true;
8682
}
83+
break;
8784
}
8885
}
8986
}
@@ -103,7 +100,9 @@ protected void addCompletions(@NotNull final CompletionParameters parameters, Pr
103100
// fields with type or built-ins
104101
Icon propertyIcon = JSGraphQLIcons.Schema.Field;
105102
Icon typeIcon = hint.isRelay() ? JSGraphQLIcons.Logos.Relay : null;
106-
if(JSGraphQLSchemaLanguageProjectService.SCALAR_TYPES.contains(type)) {
103+
if(isFragmentSpreadCompletion) {
104+
propertyIcon = JSGraphQLIcons.Schema.Fragment;
105+
} else if(JSGraphQLSchemaLanguageProjectService.SCALAR_TYPES.contains(type)) {
107106
if(text.equals("true") || text.equals("false")) {
108107
propertyIcon = null;
109108
type = null;
@@ -148,22 +147,6 @@ protected void addCompletions(@NotNull final CompletionParameters parameters, Pr
148147

149148
}
150149

151-
private void addFragmentCompletions(@NotNull CompletionResultSet result, PsiFile file) {
152-
final List<JSGraphQLFragmentDefinitionPsiElement> fragmentDefinitions = getFragmentDefinitions(file);
153-
for (JSGraphQLFragmentDefinitionPsiElement fragmentDefinition : fragmentDefinitions) {
154-
final String name = fragmentDefinition.getName();
155-
if(name != null) {
156-
LookupElementBuilder element = LookupElementBuilder.create(name).withBoldness(true);
157-
element = element.withIcon(JSGraphQLIcons.Schema.Fragment);
158-
final JSGraphQLNamedTypePsiElement fragmentOnType = fragmentDefinition.getFragmentOnType();
159-
if(fragmentOnType != null) {
160-
element = element.withTypeText(fragmentOnType.getName());
161-
}
162-
result.addElement(element);
163-
}
164-
}
165-
}
166-
167150
private List<JSGraphQLFragmentDefinitionPsiElement> getFragmentDefinitions(PsiFile file) {
168151
List<JSGraphQLFragmentDefinitionPsiElement> ret = Lists.newArrayList();
169152
file.accept(new PsiRecursiveElementVisitor() {

src/main/com/intellij/lang/jsgraphql/ide/configuration/JSGraphQLConfigurationProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public VirtualFile getOrCreateFile(String name) {
139139
}
140140

141141
public List<JSGraphQLEndpoint> getEndpoints() {
142-
final VirtualFile configFile = myProject.getBaseDir().findChild(GRAPHQL_CONFIG_JSON);
142+
final VirtualFile configFile = getGraphQLConfigFile();
143143
if(configFile != null) {
144144
final JSGraphQLConfiguration configuration = getConfiguration(configFile);
145145
if(configuration != null) {

src/main/com/intellij/lang/jsgraphql/ide/project/JSGraphQLLanguageUIProjectService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ public void actionPerformed(AnActionEvent e) {
159159
// listen for editor file tab changes to update the list of current errors
160160
messageBusConnection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, this);
161161

162+
// add editor headers to already open files since we've only just added the listener for fileOpened()
163+
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
164+
for (VirtualFile virtualFile : fileEditorManager.getOpenFiles()) {
165+
insertEditorHeaderComponentIfApplicable(fileEditorManager, virtualFile);
166+
}
167+
162168
// listen for configuration changes
163169
messageBusConnection.subscribe(JSGraphQLConfigurationListener.TOPIC, this);
164170

0 commit comments

Comments
 (0)