generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 28
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 #412 from Adeptius/feature/html-reference-completi…
…tion feat: html reference and completition support
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/main/java/de/marhali/easyi18n/assistance/completion/XmlCompletionContributor.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,17 @@ | ||
package de.marhali.easyi18n.assistance.completion; | ||
|
||
import com.intellij.codeInsight.completion.CompletionContributor; | ||
import com.intellij.codeInsight.completion.CompletionType; | ||
import com.intellij.patterns.PlatformPatterns; | ||
import com.intellij.psi.impl.source.xml.XmlAttributeValueImpl; | ||
|
||
/** | ||
* Xml specific completion contributor. | ||
* @author adeptius | ||
*/ | ||
public class XmlCompletionContributor extends CompletionContributor { | ||
public XmlCompletionContributor() { | ||
extend(CompletionType.BASIC, PlatformPatterns.psiElement().inside(XmlAttributeValueImpl.class), | ||
new KeyCompletionProvider()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/de/marhali/easyi18n/assistance/intention/XmlTranslationIntention.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,27 @@ | ||
package de.marhali.easyi18n.assistance.intention; | ||
|
||
import com.intellij.openapi.util.TextRange; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.xml.XmlAttributeValue; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Xml specific translation key intention. | ||
* @author adeptius | ||
*/ | ||
public class XmlTranslationIntention extends AbstractTranslationIntention { | ||
@Override | ||
protected @Nullable String extractText(@NotNull PsiElement element) { | ||
if(!(element.getParent() instanceof XmlAttributeValue)) { | ||
return null; | ||
} | ||
|
||
return ((XmlAttributeValue) element.getParent()).getValue(); | ||
} | ||
|
||
@Override | ||
@NotNull TextRange convertRange(@NotNull TextRange input) { | ||
return new TextRange(input.getStartOffset() + 1, input.getEndOffset() - 1); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/de/marhali/easyi18n/assistance/reference/XmlKeyReferenceContributor.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 de.marhali.easyi18n.assistance.reference; | ||
|
||
import com.intellij.openapi.project.Project; | ||
import com.intellij.patterns.PlatformPatterns; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiReference; | ||
import com.intellij.psi.PsiReferenceProvider; | ||
import com.intellij.psi.PsiReferenceRegistrar; | ||
import com.intellij.psi.impl.source.xml.XmlAttributeValueImpl; | ||
import com.intellij.util.ProcessingContext; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Xml specific key reference binding | ||
* @author adeptius | ||
*/ | ||
public class XmlKeyReferenceContributor extends AbstractKeyReferenceContributor { | ||
@Override | ||
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { | ||
registrar.registerReferenceProvider( | ||
PlatformPatterns.psiElement(XmlAttributeValueImpl.class), | ||
getProvider()); | ||
} | ||
|
||
private PsiReferenceProvider getProvider() { | ||
return new PsiReferenceProvider() { | ||
@Override | ||
public PsiReference @NotNull [] getReferencesByElement( | ||
@NotNull PsiElement element, @NotNull ProcessingContext context) { | ||
|
||
Project project = element.getProject(); | ||
XmlAttributeValueImpl literalExpression = (XmlAttributeValueImpl) element; | ||
String value = literalExpression.getValue(); | ||
return getReferences(project, element, value); | ||
} | ||
}; | ||
} | ||
} |
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