Skip to content

Commit 207915c

Browse files
committed
Merge branch 'master' into Endpoint
# Conflicts: # resources/META-INF/plugin.xml # test-resources/testData/ParsingTestData.txt
2 parents 34e558f + 14d9498 commit 207915c

File tree

10 files changed

+105
-13
lines changed

10 files changed

+105
-13
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## 1.4.4 (2016-11-28)
2+
3+
Fixes:
4+
5+
- Assertion failed: Caret model is in its update process. All requests are illegal at this point. (#42)
6+
7+
## 1.4.3 (2016-10-30)
8+
9+
Features:
10+
11+
- Add GraphQL configuration page for indentation (#29)
12+
13+
Fixes:
14+
15+
- Language Service 1.3.2: Object literal for variables in getFragment closes Relay.QL template expression.
16+
117
## 1.4.2 (2016-09-25)
218

319
Features:

resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
<change-notes><![CDATA[
3131
<ul>
32+
<li>1.4.4: Fixes Assertion failed: Caret model is in its update process.</li>
33+
<li>1.4.3: GraphQL configuration page for indentation. Language Service 1.3.2: Object literal for variables in getFragment closes Relay.QL template expression.</li>
3234
<li>1.4.2: Language Service 1.3.1: Support __schema root in schema.json.</li>
3335
<li>1.4.1: Support for gql tagged templates used by Apollo and Lokka GraphQL Clients. Fixes false Error in Relay Mutation.</li>
3436
<li>1.4.0: Language Service 1.2.0 based on graphql 0.7.0 and codemirror-graphql 0.5.4. Basic editor support for GraphQL Schema (.graphqls)</li>

src/main/com/intellij/lang/jsgraphql/ide/editor/JSGraphQLQueryContextHighlightVisitor.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void visit(@NotNull PsiElement element) {
105105
@Override
106106
public boolean analyze(final @NotNull PsiFile file, boolean updateWholeFile, @NotNull HighlightInfoHolder holder, @NotNull Runnable action) {
107107

108-
final PsiElement operationAtCursor = getOperationAtCursor(file);
108+
final PsiElement operationAtCursor = getOperationAtCursor(file, null);
109109
if (operationAtCursor != null && hasMultipleVisibleTopLevelElement(file)) {
110110

111111
// store the range of the current operation for use in the caret listener
@@ -172,7 +172,7 @@ public void caretPositionChanged(CaretEvent e) {
172172

173173
if (!sameOperation) {
174174
// moved to somewhere outside the previous operation
175-
if (hadOperation || getOperationAtCursor(psiFile) != null) {
175+
if (hadOperation || getOperationAtCursor(psiFile, e) != null) {
176176
// perform a new highlighting pass
177177
DaemonCodeAnalyzer.getInstance(project).restart(psiFile);
178178
}
@@ -328,7 +328,7 @@ public static JSGraphQLQueryContext getQueryContextBufferAndHighlightUnused(fina
328328

329329
// no selection -- see if the caret is inside an operation
330330

331-
final PsiElement operationAtCursor = getOperationAtCursor(psiFile);
331+
final PsiElement operationAtCursor = getOperationAtCursor(psiFile, null);
332332
if (operationAtCursor != null) {
333333
final HashSet<JSGraphQLFragmentDefinitionPsiElement> foundFragments = Sets.newHashSet();
334334
findFragmentsInsideOperation(operationAtCursor, foundFragments, null);
@@ -439,11 +439,22 @@ private static void showQueryContextHint(Editor editor, String hintText) {
439439
* Gets the operation that wraps the current caret position, or <code>null</code> if none is found,
440440
* e.g. when outside any operation or inside a fragment definition
441441
*/
442-
private static PsiElement getOperationAtCursor(PsiFile psiFile) {
442+
private static PsiElement getOperationAtCursor(PsiFile psiFile, CaretEvent caretEvent) {
443443
final FileEditor fileEditor = FileEditorManager.getInstance(psiFile.getProject()).getSelectedEditor(psiFile.getVirtualFile());
444444
if (fileEditor instanceof TextEditor) {
445445
final Editor editor = ((TextEditor) fileEditor).getEditor();
446-
final int currentOffset = editor.getCaretModel().getOffset();
446+
final int currentOffset;
447+
if(caretEvent != null) {
448+
currentOffset = editor.logicalPositionToOffset(caretEvent.getNewPosition());
449+
} else {
450+
try {
451+
currentOffset = editor.getCaretModel().getOffset();
452+
} catch (Throwable e) {
453+
// a caret update is in progress, so can't determine the operation at this time,
454+
// but a new caretPositionChanged event will follow
455+
return null;
456+
}
457+
}
447458
PsiElement currentElement = psiFile.findElementAt(currentOffset);
448459
while (currentElement != null && !(currentElement.getParent() instanceof PsiFile)) {
449460
currentElement = currentElement.getParent();

src/main/com/intellij/lang/jsgraphql/ide/formatter/JSGraphQLBlock.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ public Indent getIndent() {
117117
if (NO_INDENT_ELEMENT_TYPES.contains(myNode.getElementType())) {
118118
return Indent.getNoneIndent();
119119
}
120+
if(myNode.getElementType() == JSGraphQLTokenTypes.PUNCTUATION) {
121+
if(",".equals(myNode.getText())) {
122+
return Indent.getNormalIndent();
123+
}
124+
}
120125

121126
if(parent != null) {
122127
JSGraphQLElementType astNode = getAstNode(parent);

src/main/com/intellij/lang/jsgraphql/languageservice/api/Token.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ public void setKind(String kind) {
5050
this.kind = kind;
5151
}
5252

53+
public Token withTextAndOffset(String text, int offset) {
54+
final Token token = new Token();
55+
token.type = type;
56+
token.text = text;
57+
token.kind = kind;
58+
token.start = start + offset;
59+
token.end = token.start + text.length();
60+
return token;
61+
}
62+
5363
@Override
5464
public String toString() {
5565
return "Token{" +

src/main/com/intellij/lang/jsgraphql/lexer/JSGraphQLCodeMirrorTokenMapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ public class JSGraphQLCodeMirrorTokenMapper {
1818

1919
private final static Map<String, IElementType> mappings = Maps.newConcurrentMap();
2020

21+
public static final String CODEMIRROR_WHITESPACE = "ws";
22+
2123
static {
2224
for (IElementType tokenType : JSGraphQLTokenTypes.ALL_TOKEN_TYPES) {
2325
if(tokenType instanceof JSGraphQLTokenType) {
2426
mappings.put(((JSGraphQLTokenType)tokenType).getLexerTokenType(), tokenType);
2527
} else if(tokenType.equals(JSGraphQLTokenTypes.WHITESPACE)) {
26-
mappings.put("ws", tokenType); // CodeMirror uses 'ws' for whitespace
28+
mappings.put(CODEMIRROR_WHITESPACE, tokenType); // CodeMirror uses 'ws' for whitespace
2729
} else if(tokenType.equals(JSGraphQLTokenTypes.INVALIDCHAR)) {
2830
mappings.put("invalidchar", tokenType); // CodeMirror uses 'invalidchar' for whitespace
2931
}

src/main/com/intellij/lang/jsgraphql/lexer/JSGraphQLLexer.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.intellij.openapi.diagnostic.Logger;
1919
import com.intellij.openapi.project.Project;
2020
import com.intellij.psi.tree.IElementType;
21+
22+
import org.apache.commons.lang.StringUtils;
2123
import org.jetbrains.annotations.NotNull;
2224
import org.jetbrains.annotations.Nullable;
2325

@@ -99,6 +101,21 @@ private void fetchTokensFromLanguageService() {
99101
final IElementType punctuationTokenType = getPunctuationTokenType(text);
100102
if (punctuationTokenType != null) {
101103
tokenType = punctuationTokenType;
104+
} else if(text.contains(",")) {
105+
// separate out commas from surrounding whitespace to support indentation on ", field" lines
106+
int offset = 0;
107+
final String[] parts = StringUtils.splitByCharacterType(text);
108+
for (String part : parts) {
109+
final Token partSourceToken = token.withTextAndOffset(part, offset);
110+
if(part.equals(",")) {
111+
tokens.add(new JSGraphQLToken(tokenType, partSourceToken));
112+
} else {
113+
partSourceToken.setKind(JSGraphQLCodeMirrorTokenMapper.CODEMIRROR_WHITESPACE);
114+
tokens.add(new JSGraphQLToken(JSGraphQLTokenTypes.WHITESPACE, partSourceToken));
115+
}
116+
offset += part.length();
117+
}
118+
continue; // already added the required tokens
102119
} else if (JSGraphQLKeywords.FRAGMENT_DOTS.equals(text)) {
103120
// consider the "..." spread operator a keyword for highlighting
104121
tokenType = JSGraphQLTokenTypes.KEYWORD;

test-resources/testData/FormatterExpectedResult.graphql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ query queryName($foo: TestInput, $site: TestEnum = RED) {
126126
}
127127
}
128128

129+
130+
### comma before fields ###
131+
132+
query Commas {
133+
foo {
134+
bar
135+
, baz
136+
, baz2
137+
}
138+
}
139+
129140
### --------- annotations.graphql --------- ###
130141

131142
type AnnotatedObject @foo(foo: {test: true}) {

test-resources/testData/FormatterTestData.graphql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ __typename
126126
}
127127
}
128128

129+
130+
### comma before fields ###
131+
132+
query Commas {
133+
foo {
134+
bar
135+
, baz
136+
, baz2
137+
}
138+
}
139+
129140
### --------- annotations.graphql --------- ###
130141

131142
type AnnotatedObject @foo(foo: {test: true}) {

test-resources/testData/ParsingTestData.txt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@ GraphQL File(0,2428)
497497
PsiElement(OPEN_QUOTE)('"')(1471,1472)
498498
PsiElement(STRING)('foo')(1472,1475)
499499
PsiElement(CLOSE_QUOTE)('"')(1475,1476)
500-
PsiElement(PUNCTUATION)(', ')(1476,1478)
500+
PsiElement(PUNCTUATION)(',')(1476,1477)
501+
PsiWhiteSpace(' ')(1477,1478)
501502
JSGraphQLAttributePsiElement(Attribute)(1478,1484)
502503
PsiElement(ATTRIBUTE)('option')(1478,1484)
503504
PsiElement(PUNCTUATION)(':')(1484,1485)
@@ -584,7 +585,8 @@ GraphQL File(0,2428)
584585
PsiWhiteSpace(' ')(1734,1735)
585586
JSGraphQLNamedTypePsiElement(Atom)(1735,1744)
586587
PsiElement(ATOM)('TestInput')(1735,1744)
587-
PsiElement(PUNCTUATION)(', ')(1744,1746)
588+
PsiElement(PUNCTUATION)(',')(1744,1745)
589+
PsiWhiteSpace(' ')(1745,1746)
588590
PsiElement(VARIABLE)('$')(1746,1747)
589591
PsiElement(VARIABLE)('site')(1747,1751)
590592
PsiElement(PUNCTUATION)(':')(1751,1752)
@@ -644,9 +646,11 @@ GraphQL File(0,2428)
644646
JSGraphQLPsiElement(ListValue)(1869,1887)
645647
PsiElement(LBRACKET)('[')(1869,1870)
646648
PsiElement(<UNKNOWN>)('RED')(1870,1873)
647-
PsiElement(PUNCTUATION)(', ')(1873,1875)
649+
PsiElement(PUNCTUATION)(',')(1873,1874)
650+
PsiWhiteSpace(' ')(1874,1875)
648651
PsiElement(<UNKNOWN>)('GREEN')(1875,1880)
649-
PsiElement(PUNCTUATION)(', ')(1880,1882)
652+
PsiElement(PUNCTUATION)(',')(1880,1881)
653+
PsiWhiteSpace(' ')(1881,1882)
650654
PsiElement(<UNKNOWN>)('BLUE')(1882,1886)
651655
PsiElement(RBRACKET)(']')(1886,1887)
652656
PsiWhiteSpace('\n')(1887,1888)
@@ -666,9 +670,11 @@ GraphQL File(0,2428)
666670
JSGraphQLPsiElement(ListValue)(1922,1949)
667671
PsiElement(LBRACKET)('[')(1922,1923)
668672
PsiElement(NUMBER)('1.23')(1923,1927)
669-
PsiElement(PUNCTUATION)(', ')(1927,1929)
673+
PsiElement(PUNCTUATION)(',')(1927,1928)
674+
PsiWhiteSpace(' ')(1928,1929)
670675
PsiElement(NUMBER)('1.3e-1')(1929,1935)
671-
PsiElement(PUNCTUATION)(', ')(1935,1937)
676+
PsiElement(PUNCTUATION)(',')(1935,1936)
677+
PsiWhiteSpace(' ')(1936,1937)
672678
PsiElement(NUMBER)('-1.35384e+3')(1937,1948)
673679
PsiElement(RBRACKET)(']')(1948,1949)
674680
PsiWhiteSpace('\n')(1949,1950)
@@ -842,7 +848,8 @@ GraphQL File(0,2428)
842848
PsiElement(OPEN_QUOTE)('"')(2340,2341)
843849
PsiElement(STRING)('test')(2341,2345)
844850
PsiElement(CLOSE_QUOTE)('"')(2345,2346)
845-
PsiElement(PUNCTUATION)(', ')(2346,2348)
851+
PsiElement(PUNCTUATION)(',')(2346,2347)
852+
PsiWhiteSpace(' ')(2347,2348)
846853
JSGraphQLArgumentPsiElement(Argument)(2348,2365)
847854
JSGraphQLAttributePsiElement(Attribute)(2348,2351)
848855
PsiElement(ATTRIBUTE)('foo')(2348,2351)

0 commit comments

Comments
 (0)