-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/endgame-202310' into develop
- Loading branch information
Showing
95 changed files
with
1,184 additions
and
1,114 deletions.
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
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
58 changes: 58 additions & 0 deletions
58
...zure/toolkit/intellij/cosmos/code/function/AzureCosmosDBResourceReferenceContributor.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 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
package com.microsoft.azure.toolkit.intellij.cosmos.code.function; | ||
|
||
import com.intellij.openapi.util.TextRange; | ||
import com.intellij.psi.*; | ||
import com.intellij.util.ProcessingContext; | ||
import com.microsoft.azure.toolkit.intellij.connector.Connection; | ||
import com.microsoft.azure.toolkit.intellij.connector.code.function.FunctionAnnotationResourceReference; | ||
import com.microsoft.azure.toolkit.lib.common.model.AzResource; | ||
import com.microsoft.azure.toolkit.lib.cosmos.sql.SqlDatabase; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Optional; | ||
import java.util.function.BiFunction; | ||
|
||
import static com.intellij.patterns.PsiJavaPatterns.psiElement; | ||
import static com.microsoft.azure.toolkit.intellij.cosmos.code.function.CosmosDBContainerNameCompletionProvider.COSMOS_CONTAINER_NAME_PAIR_PATTERN; | ||
import static com.microsoft.azure.toolkit.intellij.cosmos.code.function.CosmosDBDatabaseNameCompletionProvider.COSMOS_DATABASE_NAME_PAIR_PATTERN; | ||
|
||
public class AzureCosmosDBResourceReferenceContributor extends PsiReferenceContributor { | ||
@Override | ||
public void registerReferenceProviders(@Nonnull PsiReferenceRegistrar registrar) { | ||
registrar.registerReferenceProvider(psiElement(PsiLiteralExpression.class).withParent(COSMOS_DATABASE_NAME_PAIR_PATTERN), new PsiReferenceProvider() { | ||
@Override | ||
public PsiReference[] getReferencesByElement(@Nonnull PsiElement element, @Nonnull ProcessingContext context) { | ||
final PsiLiteralExpression literal = (PsiLiteralExpression) element; | ||
final String value = literal.getValue() instanceof String ? (String) literal.getValue() : StringUtils.EMPTY; | ||
if (StringUtils.isNotBlank(value)) { | ||
final TextRange range = new TextRange(1, value.length() + 1); | ||
return new PsiReference[]{new FunctionAnnotationResourceReference(element, range, | ||
(ann, con) -> CosmosDBDatabaseNameCompletionProvider.getConnectedDatabase(ann))}; | ||
} | ||
return PsiReference.EMPTY_ARRAY; | ||
} | ||
}); | ||
registrar.registerReferenceProvider(psiElement(PsiLiteralExpression.class).withParent(COSMOS_CONTAINER_NAME_PAIR_PATTERN), new PsiReferenceProvider() { | ||
@Override | ||
public PsiReference[] getReferencesByElement(@Nonnull PsiElement element, @Nonnull ProcessingContext context) { | ||
final PsiLiteralExpression literal = (PsiLiteralExpression) element; | ||
final String value = literal.getValue() instanceof String ? (String) literal.getValue() : StringUtils.EMPTY; | ||
final BiFunction<PsiAnnotation, Connection<?, ?>, AzResource> function = (annotation, connection) -> { | ||
final SqlDatabase database = CosmosDBDatabaseNameCompletionProvider.getConnectedDatabase(annotation); | ||
return Optional.ofNullable(database).map(d -> d.containers().get(value, database.getResourceGroupName())).orElse(null); | ||
}; | ||
if (StringUtils.isNotBlank(value)) { | ||
final TextRange range = new TextRange(1, value.length() + 1); | ||
return new PsiReference[]{new FunctionAnnotationResourceReference(element, range, function)}; | ||
} | ||
return PsiReference.EMPTY_ARRAY; | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.