use of org.jetbrains.yaml.psi.YAMLDocument in project intellij-community by JetBrains.
the class YamlKeyCompletionInsertHandler method handleInsert.
@Override
public void handleInsert(InsertionContext context, T item) {
final PsiElement currentElement = context.getFile().findElementAt(context.getStartOffset());
assert currentElement != null : "no element at " + context.getStartOffset();
final YAMLDocument holdingDocument = PsiTreeUtil.getParentOfType(currentElement, YAMLDocument.class);
assert holdingDocument != null;
final YAMLValue oldValue = deleteLookupTextAndRetrieveOldValue(context, currentElement);
final YAMLKeyValue created = createNewEntry(holdingDocument, item);
context.getEditor().getCaretModel().moveToOffset(created.getTextRange().getEndOffset());
if (oldValue != null) {
WriteCommandAction.runWriteCommandAction(context.getProject(), () -> created.setValue(oldValue));
}
PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getDocument());
if (!isCharAtCaret(context.getEditor(), ' ')) {
EditorModificationUtil.insertStringAtCaret(context.getEditor(), " ");
} else {
context.getEditor().getCaretModel().moveCaretRelatively(1, 0, false, false, true);
}
}
use of org.jetbrains.yaml.psi.YAMLDocument in project intellij-plugins by JetBrains.
the class JstdConfigFileReferenceContributor method registerReferenceProviders.
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(JstdConfigFileUtils.CONFIG_FILE_ELEMENT_PATTERN, new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
final YAMLKeyValue keyValue = ObjectUtils.tryCast(element, YAMLKeyValue.class);
if (keyValue == null) {
return PsiReference.EMPTY_ARRAY;
}
final YAMLDocument yamlDocument = ObjectUtils.tryCast(keyValue.getParent(), YAMLDocument.class);
if (yamlDocument == null) {
return PsiReference.EMPTY_ARRAY;
}
final BasePathInfo basePathInfo = new BasePathInfo(yamlDocument);
if (BasePathInfo.isBasePathKey(keyValue)) {
PsiReference basePathRef = createBasePathRef(basePathInfo);
if (basePathRef != null) {
return new PsiReference[] { basePathRef };
}
} else if (JstdConfigFileUtils.isTopLevelKeyWithInnerFileSequence(keyValue)) {
VirtualFile basePath = basePathInfo.getBasePath();
if (basePath != null) {
List<PsiReference> references = Lists.newArrayList();
addReferencesForKeyValueWithInnerFileSequence(basePathInfo, keyValue, references);
return references.toArray(new PsiReference[references.size()]);
}
}
return PsiReference.EMPTY_ARRAY;
}
});
}
Aggregations