mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
YAMLFindUsagesProvider to allow find usages in YAML-based languages
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
<lang.syntaxHighlighterFactory language="yaml" implementationClass="org.jetbrains.yaml.YAMLSyntaxHighlighterFactory"/>
|
||||
<colorSettingsPage implementation="org.jetbrains.yaml.YAMLColorsPage"/>
|
||||
<lang.braceMatcher language="yaml" implementationClass="org.jetbrains.yaml.YAMLPairedBraceMatcher"/>
|
||||
<lang.findUsagesProvider language="yaml" implementationClass="org.jetbrains.yaml.YAMLFindUsagesProvider"/>
|
||||
<lang.foldingBuilder language="yaml" implementationClass="org.jetbrains.yaml.folding.YAMLFoldingBuilder"/>
|
||||
<fileTypeFactory implementation="org.jetbrains.yaml.YAMLFileTypeLoader"/>
|
||||
<editor.backspaceModeOverride language="yaml" implementationClass="com.intellij.codeInsight.editorActions.SmartBackspaceDisabler"/>
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package org.jetbrains.yaml;
|
||||
|
||||
import com.intellij.lang.HelpID;
|
||||
import com.intellij.lang.cacheBuilder.WordsScanner;
|
||||
import com.intellij.lang.findUsages.FindUsagesProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.yaml.psi.YAMLMapping;
|
||||
import org.jetbrains.yaml.psi.YAMLScalar;
|
||||
import org.jetbrains.yaml.psi.YAMLScalarText;
|
||||
import org.jetbrains.yaml.psi.YAMLSequence;
|
||||
|
||||
/**
|
||||
* @author shalupov
|
||||
*/
|
||||
public class YAMLFindUsagesProvider implements FindUsagesProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public WordsScanner getWordsScanner() {
|
||||
return new YAMLWordsScanner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFindUsagesFor(@NotNull PsiElement psiElement) {
|
||||
return psiElement instanceof PsiNamedElement || psiElement instanceof YAMLScalar;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHelpId(@NotNull PsiElement psiElement) {
|
||||
return HelpID.FIND_OTHER_USAGES;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getType(@NotNull PsiElement element) {
|
||||
if (element instanceof YAMLScalarText) {
|
||||
return "scalar";
|
||||
} else if (element instanceof YAMLSequence) {
|
||||
return "sequence";
|
||||
} else if (element instanceof YAMLMapping) {
|
||||
return "mapping";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescriptiveName(@NotNull PsiElement element) {
|
||||
final String name = element instanceof PsiNamedElement ? ((PsiNamedElement)element).getName() : null;
|
||||
if (name != null) {
|
||||
return name;
|
||||
}
|
||||
|
||||
if (element instanceof YAMLScalar) {
|
||||
return ((YAMLScalar)element).getTextValue();
|
||||
}
|
||||
|
||||
return "<unnamed>";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
|
||||
return getDescriptiveName(element);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.jetbrains.yaml;
|
||||
|
||||
import com.intellij.lang.cacheBuilder.DefaultWordsScanner;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.yaml.lexer.YAMLFlexLexer;
|
||||
|
||||
/**
|
||||
* @author shalupov
|
||||
*/
|
||||
public class YAMLWordsScanner extends DefaultWordsScanner {
|
||||
public YAMLWordsScanner() {
|
||||
super(
|
||||
new YAMLFlexLexer(),
|
||||
TokenSet.create(
|
||||
YAMLElementTypes.SCALAR_TEXT_VALUE,
|
||||
YAMLElementTypes.SCALAR_PLAIN_VALUE,
|
||||
YAMLElementTypes.SCALAR_QUOTED_STRING),
|
||||
TokenSet.create(YAMLTokenTypes.COMMENT),
|
||||
TokenSet.EMPTY);
|
||||
setMayHaveFileRefsInLiterals(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user