Skip to content

Commit 5561b08

Browse files
committed
fixed GoParamDefinition Completion
1 parent 9e81bd3 commit 5561b08

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

src/main/java/com/github/maiqingqiang/goormhelper/actions/EditorPasteListener.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,9 @@ protected void doExecute(@NotNull Editor editor, @Nullable Caret caret, DataCont
7575
}
7676

7777
private boolean verifySQL(String sql) {
78-
7978
Validation validation = new Validation(Collections.singletonList(FeaturesAllowed.CREATE), sql);
8079
List<ValidationError> errors = validation.validate();
8180

82-
for (ValidationError error : errors) {
83-
LOG.warn(error.toString());
84-
}
85-
8681
return errors.size() == 0;
8782
}
8883

src/main/java/com/github/maiqingqiang/goormhelper/orm/gorm/codeInsights/completion/GormColumnCompletionProvider.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ private String searchGoVarDefinitionReferences(GoVarDefinition goVarDefinition)
193193
for (PsiReference psiReference : GoReferencesSearch.search(goVarDefinition)) {
194194
GoStatement statement = (GoStatement) PsiTreeUtil.findFirstParent(psiReference.getElement(), element -> element instanceof GoStatement);
195195
if (statement == null) continue;
196-
System.out.println("statement " + statement.getText());
197196
schema = findSchema(statement);
198197
if (!schema.isEmpty()) return schema;
199198

@@ -225,29 +224,32 @@ private static String findSchema(@NotNull GoStatement statement) {
225224
if (!schema.isEmpty()) return schema;
226225

227226
for (GoCallExpr goCallExpr : PsiTreeUtil.findChildrenOfType(statement, GoCallExpr.class)) {
227+
228228
GoCallableDescriptor descriptor = GormTypes.ORM_MODEL_CALLABLES_SET.find(goCallExpr, false);
229229
if (descriptor == null) continue;
230230

231231
Integer argumentIndex = GormTypes.GORM_MODEL_CALLABLES.get(descriptor);
232232

233-
System.out.println("argumentIndex " + argumentIndex);
234-
System.out.println("getExpressionList " + goCallExpr.getArgumentList().getExpressionList().get(argumentIndex));
235-
236233
GoExpression argument = goCallExpr.getArgumentList().getExpressionList().get(argumentIndex);
237234

238235
if (argument instanceof GoUnaryExpr goUnaryExpr) {
239236
if (goUnaryExpr.getExpression() instanceof GoCompositeLit goCompositeLit) {
240237
if (goCompositeLit.getTypeReferenceExpression() == null) continue;
241238
schema = goCompositeLit.getTypeReferenceExpression().getIdentifier().getText();
242239
} else if (goUnaryExpr.getExpression() instanceof GoReferenceExpression goReferenceExpression) {
243-
GoVarDefinition goVarDefinition = (GoVarDefinition) goReferenceExpression.resolve();
244-
245-
if (goVarDefinition == null) continue;
246-
247-
GoType goType = goVarDefinition.getGoType(ResolveState.initial());
248-
if (goType == null || goType.getTypeReferenceExpression() == null) continue;
249-
250-
schema = goType.getTypeReferenceExpression().getIdentifier().getText();
240+
if (goReferenceExpression.resolve() instanceof GoVarDefinition goVarDefinition) {
241+
GoType goType = goVarDefinition.getGoType(ResolveState.initial());
242+
if (goType == null || goType.getTypeReferenceExpression() == null) continue;
243+
244+
schema = goType.getTypeReferenceExpression().getIdentifier().getText();
245+
} else if (goReferenceExpression.resolve() instanceof GoParamDefinition goParamDefinition) {
246+
GoPointerType goPointerType = PsiTreeUtil.findChildOfType(goParamDefinition.getParent(), GoPointerType.class);
247+
GoType goType = PsiTreeUtil.findChildOfType(goPointerType, GoType.class);
248+
if (goType != null) {
249+
if (goType.getTypeReferenceExpression() == null) continue;
250+
schema = goType.getTypeReferenceExpression().getIdentifier().getText();
251+
}
252+
}
251253
}
252254
} else if (argument instanceof GoBuiltinCallExpr goBuiltinCallExpr) {
253255
GoType goType = PsiTreeUtil.findChildOfType(goBuiltinCallExpr, GoType.class);

src/main/java/com/github/maiqingqiang/goormhelper/orm/xorm/completion/XormColumnCompletionProvider.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,19 @@ private static String findSchema(@NotNull GoStatement statement) {
242242
if (goCompositeLit.getTypeReferenceExpression() == null) continue;
243243
schema = goCompositeLit.getTypeReferenceExpression().getIdentifier().getText();
244244
} else if (goUnaryExpr.getExpression() instanceof GoReferenceExpression goReferenceExpression) {
245-
GoVarDefinition goVarDefinition = (GoVarDefinition) goReferenceExpression.resolve();
246-
247-
if (goVarDefinition == null) continue;
248-
249-
GoType goType = goVarDefinition.getGoType(ResolveState.initial());
250-
if (goType == null || goType.getTypeReferenceExpression() == null) continue;
251-
252-
schema = goType.getTypeReferenceExpression().getIdentifier().getText();
245+
if (goReferenceExpression.resolve() instanceof GoVarDefinition goVarDefinition) {
246+
GoType goType = goVarDefinition.getGoType(ResolveState.initial());
247+
if (goType == null || goType.getTypeReferenceExpression() == null) continue;
248+
249+
schema = goType.getTypeReferenceExpression().getIdentifier().getText();
250+
} else if (goReferenceExpression.resolve() instanceof GoParamDefinition goParamDefinition) {
251+
GoPointerType goPointerType = PsiTreeUtil.findChildOfType(goParamDefinition.getParent(), GoPointerType.class);
252+
GoType goType = PsiTreeUtil.findChildOfType(goPointerType, GoType.class);
253+
if (goType != null) {
254+
if (goType.getTypeReferenceExpression() == null) continue;
255+
schema = goType.getTypeReferenceExpression().getIdentifier().getText();
256+
}
257+
}
253258
}
254259
} else if (argument instanceof GoBuiltinCallExpr goBuiltinCallExpr) {
255260
GoType goType = PsiTreeUtil.findChildOfType(goBuiltinCallExpr, GoType.class);

0 commit comments

Comments
 (0)