-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from nette-intellij/mn-code-style-and-improvem…
…ent-usage Code style settings and improvements for usage and performance
- Loading branch information
Showing
28 changed files
with
501 additions
and
201 deletions.
There are no files selected for viewing
Binary file not shown.
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
9 changes: 9 additions & 0 deletions
9
src/com/jantvrdik/intellij/latte/codeStyle/LatteCodeStyleSettings.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,9 @@ | ||
package com.jantvrdik.intellij.latte.codeStyle; | ||
|
||
import com.intellij.psi.codeStyle.*; | ||
|
||
public class LatteCodeStyleSettings extends CustomCodeStyleSettings { | ||
public LatteCodeStyleSettings(CodeStyleSettings settings) { | ||
super("LatteCodeStyleSettings", settings); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/com/jantvrdik/intellij/latte/codeStyle/LatteCodeStyleSettingsProvider.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,35 @@ | ||
package com.jantvrdik.intellij.latte.codeStyle; | ||
|
||
import com.intellij.application.options.*; | ||
import com.intellij.psi.codeStyle.*; | ||
import com.jantvrdik.intellij.latte.LatteLanguage; | ||
import org.jetbrains.annotations.*; | ||
|
||
public class LatteCodeStyleSettingsProvider extends CodeStyleSettingsProvider { | ||
@Override | ||
public CustomCodeStyleSettings createCustomSettings(CodeStyleSettings settings) { | ||
return new LatteCodeStyleSettings(settings); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getConfigurableDisplayName() { | ||
return "Latte"; | ||
} | ||
|
||
@NotNull | ||
public CodeStyleConfigurable createConfigurable(@NotNull CodeStyleSettings settings, @NotNull CodeStyleSettings modelSettings) { | ||
return new CodeStyleAbstractConfigurable(settings, modelSettings, this.getConfigurableDisplayName()) { | ||
@Override | ||
protected CodeStyleAbstractPanel createPanel(CodeStyleSettings settings) { | ||
return new LatteCodeStyleMainPanel(getCurrentSettings(), settings); | ||
} | ||
}; | ||
} | ||
|
||
private static class LatteCodeStyleMainPanel extends TabbedLanguageCodeStylePanel { | ||
public LatteCodeStyleMainPanel(CodeStyleSettings currentSettings, CodeStyleSettings settings) { | ||
super(LatteLanguage.INSTANCE, currentSettings, settings); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/com/jantvrdik/intellij/latte/codeStyle/LatteLanguageCodeStyleSettingsProvider.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,58 @@ | ||
package com.jantvrdik.intellij.latte.codeStyle; | ||
|
||
import com.intellij.application.options.IndentOptionsEditor; | ||
import com.jantvrdik.intellij.latte.LatteLanguage; | ||
import gnu.trove.THashSet; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.intellij.lang.Language; | ||
import com.intellij.psi.codeStyle.*; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class LatteLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsProvider { | ||
@NotNull | ||
@Override | ||
public Language getLanguage() { | ||
return LatteLanguage.INSTANCE; | ||
} | ||
|
||
@Override | ||
public void customizeSettings(@NotNull CodeStyleSettingsCustomizable consumer, @NotNull SettingsType settingsType) { | ||
if (settingsType == SettingsType.SPACING_SETTINGS) { | ||
consumer.showStandardOptions("SPACE_AROUND_ASSIGNMENT_OPERATORS"); | ||
consumer.renameStandardOption("SPACE_AROUND_ASSIGNMENT_OPERATORS", "Separator"); | ||
} else if (settingsType == SettingsType.BLANK_LINES_SETTINGS) { | ||
consumer.showStandardOptions("KEEP_BLANK_LINES_IN_CODE"); | ||
} else if (settingsType == SettingsType.INDENT_SETTINGS) { | ||
consumer.showStandardOptions("USE_TAB_CHARACTER"); | ||
consumer.showStandardOptions("INDENT_SIZE"); | ||
consumer.showStandardOptions("TAB_SIZE"); | ||
} | ||
} | ||
|
||
@Override | ||
public Set<String> getSupportedFields(SettingsType type) { | ||
if (type == SettingsType.BLANK_LINES_SETTINGS) { | ||
return Collections.emptySet(); | ||
} | ||
return super.getSupportedFields(type); | ||
} | ||
|
||
@Override | ||
public @Nullable IndentOptionsEditor getIndentOptionsEditor() { | ||
return new IndentOptionsEditor(); | ||
} | ||
|
||
@Override | ||
public String getCodeSample(@NotNull SettingsType settingsType) { | ||
return "{contentType text/html}\n" + | ||
"{* comment *}\n" + | ||
"{var $string = \"abc\", $number = 123}\n\n" + | ||
"{foreach $data as $key => $value}\n" + | ||
" {$key} {$value}\n" + | ||
"{/foreach}"; | ||
} | ||
} |
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
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
38 changes: 38 additions & 0 deletions
38
...om/jantvrdik/intellij/latte/completion/providers/LattePhpNamespaceCompletionProvider.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,38 @@ | ||
package com.jantvrdik.intellij.latte.completion.providers; | ||
|
||
import com.intellij.codeInsight.completion.CompletionParameters; | ||
import com.intellij.codeInsight.completion.CompletionProvider; | ||
import com.intellij.codeInsight.completion.CompletionResultSet; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.util.PsiTreeUtil; | ||
import com.intellij.util.ProcessingContext; | ||
import com.jantvrdik.intellij.latte.psi.LattePhpContent; | ||
import com.jetbrains.php.PhpIndex; | ||
import com.jetbrains.php.completion.PhpCompletionUtil; | ||
import com.jetbrains.php.completion.insert.PhpNamespaceInsertHandler; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
|
||
public class LattePhpNamespaceCompletionProvider extends CompletionProvider<CompletionParameters> { | ||
|
||
public LattePhpNamespaceCompletionProvider() { | ||
} | ||
|
||
@Override | ||
protected void addCompletions(@NotNull CompletionParameters params, ProcessingContext context, @NotNull CompletionResultSet result) { | ||
PsiElement curr = params.getPosition().getOriginalElement(); | ||
if (PsiTreeUtil.getParentOfType(curr, LattePhpContent.class) == null) { | ||
return; | ||
} | ||
|
||
PhpIndex phpIndex = PhpIndex.getInstance(curr.getProject()); | ||
String prefix = result.getPrefixMatcher().getPrefix(); | ||
String namespace = ""; | ||
if (prefix.contains("\\")) { | ||
int index = prefix.lastIndexOf("\\"); | ||
namespace = prefix.substring(0, index) + "\\"; | ||
prefix = prefix.substring(index + 1); | ||
} | ||
PhpCompletionUtil.addSubNamespaces(namespace, result.withPrefixMatcher(prefix), phpIndex, PhpNamespaceInsertHandler.getInstance()); | ||
} | ||
} |
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
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
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
Oops, something went wrong.