-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GraphQL configuration page for indentation (#29)
(cherry picked from commit 6289c01)
- Loading branch information
1 parent
a67868b
commit 930389d
Showing
4 changed files
with
100 additions
and
1 deletion.
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
77 changes: 77 additions & 0 deletions
77
...com/intellij/lang/jsgraphql/ide/formatter/JSGraphQLLanguageCodeStyleSettingsProvider.java
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,77 @@ | ||
/** | ||
* Copyright (c) 2015-present, Jim Kynde Meyer | ||
* All rights reserved. | ||
* <p> | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
package com.intellij.lang.jsgraphql.ide.formatter; | ||
|
||
import com.intellij.application.options.IndentOptionsEditor; | ||
import com.intellij.lang.Language; | ||
import com.intellij.lang.jsgraphql.JSGraphQLLanguage; | ||
import com.intellij.openapi.application.ApplicationBundle; | ||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings; | ||
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
|
||
public class JSGraphQLLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsProvider { | ||
|
||
@NotNull | ||
@Override | ||
public Language getLanguage() { | ||
return JSGraphQLLanguage.INSTANCE; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public CommonCodeStyleSettings getDefaultCommonSettings() { | ||
final CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(getLanguage()); | ||
CommonCodeStyleSettings.IndentOptions indentOptions = defaultSettings.initIndentOptions(); | ||
indentOptions.INDENT_SIZE = 4; | ||
indentOptions.USE_TAB_CHARACTER = false; | ||
return defaultSettings; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public IndentOptionsEditor getIndentOptionsEditor() { | ||
return new IndentOptionsEditor() { | ||
protected void addComponents() { | ||
addTabOptions(); | ||
myTabSizeField = new JTextField(); | ||
myTabSizeLabel = new JLabel(); | ||
myIndentField = createIndentTextField(); | ||
myIndentLabel = new JLabel(ApplicationBundle.message("editbox.indent.indent")); | ||
add(myIndentLabel, myIndentField); | ||
} | ||
|
||
protected void addTabOptions() { | ||
myCbUseTab = new JCheckBox(""); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public String getCodeSample(@NotNull SettingsType settingsType) { | ||
return "query MyQuery {\n" + | ||
" __schema {\n" + | ||
" types {\n" + | ||
" ...FullType\n" + | ||
" }\n" + | ||
" }\n" + | ||
"}\n" + | ||
"\n" + | ||
"fragment FullType on __Type {\n" + | ||
" # Note: __Type has a lot more fields than this\n" + | ||
" name\n" + | ||
"}\n" + | ||
"\n" + | ||
"mutation MyMutation($input: MyInput!) {\n" + | ||
" # Payload\n" + | ||
"}\n"; | ||
} | ||
} |
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