Skip to content

Commit dc4eab8

Browse files
authored
Merge pull request #10 from maiqingqiang/next
v1.2.2
2 parents a651023 + cd8ea5f commit dc4eab8

File tree

14 files changed

+220
-62
lines changed

14 files changed

+220
-62
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Bug report
2+
description: Create a report to help us improve
3+
labels: ["bug"]
4+
body:
5+
6+
- type: textarea
7+
id: issue
8+
attributes:
9+
label: What happened?
10+
description: A clear and concise description of what the bug is.
11+
validations:
12+
required: true
13+
14+
- type: textarea
15+
id: logs
16+
attributes:
17+
label: Relevant log output or stack trace
18+
description: |
19+
Please copy and paste any relevant log output.
20+
Add the full stack trace if available.
21+
If possible, run the failing task with `--stacktrace` flag.
22+
23+
*This will be automatically formatted into code, so there is no need for backticks.*
24+
render: shell
25+
26+
- type: textarea
27+
id: steps
28+
attributes:
29+
label: Steps to reproduce
30+
description: Steps to reproduce the behavior – provide your build configuration.
31+
validations:
32+
required: true
33+
34+
- type: input
35+
id: version
36+
attributes:
37+
label: Gradle IntelliJ Plugin version
38+
placeholder: 1.16.0
39+
validations:
40+
required: true
41+
42+
- type: input
43+
id: gradle
44+
attributes:
45+
label: Gradle version
46+
placeholder: 8.2.1
47+
validations:
48+
required: true
49+
50+
- type: dropdown
51+
id: os
52+
attributes:
53+
label: Operating System
54+
options:
55+
- macOS
56+
- Linux
57+
- Windows
58+
59+
- type: input
60+
id: url
61+
attributes:
62+
label: Link to build, i.e. failing GitHub Action job
63+
placeholder: https://github.com/username/project/actions/runs/1234567890

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
blank_issues_enabled: true
2+
contact_links:
3+
- name: Documentation
4+
url: https://github.com/JetBrains/intellij-platform-plugin-template
5+
about: Check the README file in the first place.
6+
- name: Getting Help
7+
url: https://plugins.jetbrains.com/docs/intellij/getting-help.html
8+
about: Check if you search for a help in plugin development.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Feature request
2+
description: Suggest an idea for this project
3+
labels: ["enhancement"]
4+
body:
5+
6+
- type: textarea
7+
id: cause
8+
attributes:
9+
label: Describe the need of your request
10+
description: A clear and concise description of what the need or problem is.
11+
validations:
12+
required: true
13+
14+
- type: textarea
15+
id: solution
16+
attributes:
17+
label: Proposed solution
18+
description: A clear and concise description of what you want to happen.
19+
validations:
20+
required: true
21+
22+
- type: textarea
23+
id: alternatives
24+
attributes:
25+
label: Alternatives you've considered
26+
description: What did you try so far to accomplish the goal?
27+
28+
- type: textarea
29+
id: context
30+
attributes:
31+
label: Additional context
32+
description: Add any other context or screenshots about the feature request here.

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
## [Unreleased]
66

7+
## [1.2.2] - 2023-08-06
8+
9+
### Fixed
10+
11+
- When using the DAO tool to generate a model, the field names are directly used as saved in the DAO. #9
12+
713
## [1.2.1] - 2023-07-25
814

915
### Added
@@ -63,6 +69,8 @@
6369

6470
[Unreleased]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.1...HEAD
6571

72+
[1.2.2]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.1...v1.2.2
73+
6674
[1.2.1]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.0...v1.2.1
6775

6876
[1.2.0]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.1.0...v1.2.0

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginGroup = com.github.maiqingqiang.goormhelper
44
pluginName = Go ORM Helper
55
pluginRepositoryUrl = https://github.com/maiqingqiang/go-orm-helper
66
# SemVer format -> https://semver.org
7-
pluginVersion = 1.2.1
7+
pluginVersion = 1.2.2
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
pluginSinceBuild = 222

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# libraries
33
annotations = "24.0.1"
44
lombok = "1.18.28"
5-
guava = "32.1.1-jre"
5+
guava = "32.1.2-jre"
66
druid = "1.2.18"
77
jsqlparser = "4.6"
88
evoInflector = "1.3"
@@ -13,7 +13,7 @@ kotlin = "1.9.0"
1313
changelog = "2.1.2"
1414
gradleIntelliJPlugin = "1.15.0"
1515
qodana = "0.1.13"
16-
kover = "0.7.2"
16+
kover = "0.7.3"
1717

1818
[libraries]
1919
annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }

settings.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
rootProject.name = "Go ORM Helper"
1+
plugins {
2+
id("org.gradle.toolchains.foojay-resolver-convention") version "0.6.0"
3+
}
4+
5+
rootProject.name = "Go ORM Helper"

src/main/java/com/github/maiqingqiang/goormhelper/orm/ORMCompletionProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull
9393

9494
LOG.info("argument: " + argument);
9595

96-
argument = findAgainArgument(argument);
96+
argument = findAgainArgument(argument, parameters, descriptor, result);
9797

9898
GoORMHelperCacheManager manager = GoORMHelperCacheManager.getInstance(project);
9999

@@ -156,7 +156,7 @@ protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull
156156
}
157157
}
158158

159-
protected GoCompositeElement findAgainArgument(GoCompositeElement argument) {
159+
protected GoCompositeElement findAgainArgument(GoCompositeElement argument, @NotNull CompletionParameters parameters, GoCallableDescriptor descriptor, @NotNull CompletionResultSet result) {
160160
return argument;
161161
}
162162

@@ -358,7 +358,7 @@ private void scanFields(@NotNull CompletionParameters parameters, GoCallableDesc
358358
}
359359

360360
if (column != null && column.isEmpty()) {
361-
if (field.getFieldDefinitionList().size() == 0 && field.getAnonymousFieldDefinition() != null) {
361+
if (field.getFieldDefinitionList().isEmpty() && field.getAnonymousFieldDefinition() != null) {
362362
GoType goType = field.getAnonymousFieldDefinition().getGoType(ResolveState.initial());
363363
if (goType == null) continue;
364364

@@ -401,7 +401,7 @@ private void scanFields(@NotNull CompletionParameters parameters, GoCallableDesc
401401
}
402402
}
403403

404-
private void addElement(@NotNull CompletionResultSet result, String column, String comment, String type, @NotNull GoTypeSpec goTypeSpec) {
404+
protected void addElement(@NotNull CompletionResultSet result, String column, String comment, String type, @NotNull GoTypeSpec goTypeSpec) {
405405
LookupElementBuilder builder = LookupElementBuilder
406406
.createWithSmartPointer(column, goTypeSpec)
407407
.withPresentableText(column)

src/main/java/com/github/maiqingqiang/goormhelper/orm/goframe/codeInsights/completion/GoFrameColumnCompletionProvider.java

Lines changed: 94 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@
44
import com.github.maiqingqiang.goormhelper.orm.ORMCompletionProvider;
55
import com.github.maiqingqiang.goormhelper.orm.goframe.GoFrameTypes;
66
import com.github.maiqingqiang.goormhelper.ui.Icons;
7+
import com.github.maiqingqiang.goormhelper.utils.Strings;
8+
import com.goide.documentation.GoDocumentationProvider;
79
import com.goide.inspections.core.GoCallableDescriptor;
810
import com.goide.inspections.core.GoCallableDescriptorSet;
911
import com.goide.psi.*;
1012
import com.goide.psi.impl.GoPsiUtil;
13+
import com.google.common.base.CaseFormat;
14+
import com.intellij.codeInsight.completion.CompletionParameters;
15+
import com.intellij.codeInsight.completion.CompletionResultSet;
16+
import com.intellij.psi.PsiReference;
1117
import com.intellij.psi.ResolveState;
1218
import com.intellij.util.ObjectUtils;
1319
import org.jetbrains.annotations.Contract;
1420
import org.jetbrains.annotations.NotNull;
1521
import org.jetbrains.annotations.Nullable;
1622

1723
import javax.swing.*;
18-
import java.util.List;
19-
import java.util.Map;
20-
import java.util.Objects;
21-
import java.util.Set;
24+
import java.util.*;
2225

2326
public class GoFrameColumnCompletionProvider extends ORMCompletionProvider {
2427

@@ -147,12 +150,97 @@ protected GoCompositeElement customFindGoCompositeElementByGoCallExpr(GoCallExpr
147150
}
148151

149152
@Override
150-
protected GoCompositeElement findAgainArgument(GoCompositeElement argument) {
153+
protected GoCompositeElement findAgainArgument(GoCompositeElement argument, @NotNull CompletionParameters parameters, GoCallableDescriptor descriptor, @NotNull CompletionResultSet result) {
151154
if (argument instanceof GoCallExpr goCallExpr) {
152155
GoType newArgument = findGoTypeByReceiver(goCallExpr, Set.of(GoTypeSpecDescriptor.of("builtin.string")));
153-
if (newArgument != null) return newArgument;
156+
if (newArgument != null && newArgument.resolve(ResolveState.initial()) instanceof GoTypeSpec goTypeSpec) {
157+
158+
HashMap<String, String> columnMap = new HashMap<>();
159+
160+
for (PsiReference search : GoReferencesSearch.search(goTypeSpec)) {
161+
if (search.getElement().getParent() instanceof GoCompositeLit goCompositeLit) {
162+
GoLiteralValue goLiteralValue = goCompositeLit.getLiteralValue();
163+
if (goLiteralValue != null) {
164+
for (GoElement goElement : goLiteralValue.getElementList()) {
165+
166+
if (goElement.getKey() != null && goElement.getKey().getFieldName() != null && goElement.getValue() != null && goElement.getValue().getExpression() instanceof GoStringLiteral goStringLiteral) {
167+
columnMap.put(goElement.getKey().getFieldName().getIdentifier().getText(), goStringLiteral.getDecodedText());
168+
}
169+
}
170+
}
171+
}
172+
}
173+
174+
scanFieldsByGoFrame(parameters, descriptor, result, goTypeSpec, columnMap);
175+
176+
return null;
177+
}
154178
}
155179
return argument;
156180
}
157181

182+
183+
private void scanFieldsByGoFrame(@NotNull CompletionParameters parameters, GoCallableDescriptor descriptor, @NotNull CompletionResultSet result, @NotNull GoTypeSpec goTypeSpec, HashMap<String, String> columnMap) {
184+
if (goTypeSpec.getSpecType().getType() instanceof GoStructType goStructType) {
185+
for (GoFieldDeclaration field : goStructType.getFieldDeclarationList()) {
186+
187+
if (!checkGoFieldDeclaration(field)) continue;
188+
189+
String name = field.getFieldDefinitionList().get(0).getName();
190+
191+
String column = columnMap.get(name);
192+
String comment = getComment(field);
193+
String type = "";
194+
195+
if (field.getType() != null) {
196+
type = field.getType().getPresentationText();
197+
}
198+
199+
if (column != null && column.isEmpty()) {
200+
column = getColumn(field);
201+
202+
if (column != null && column.isEmpty()) {
203+
if (field.getFieldDefinitionList().isEmpty() && field.getAnonymousFieldDefinition() != null) {
204+
GoType goType = field.getAnonymousFieldDefinition().getGoType(ResolveState.initial());
205+
if (goType == null) continue;
206+
207+
GoTypeSpec spec = (GoTypeSpec) goType.resolve(ResolveState.initial());
208+
if (spec == null) continue;
209+
210+
scanFieldsByGoFrame(parameters, descriptor, result, spec, columnMap);
211+
continue;
212+
}
213+
214+
if (name != null) {
215+
column = Strings.replaceCommonInitialisms(name);
216+
column = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, column);
217+
}
218+
}
219+
}
220+
221+
222+
if (comment != null && comment.isEmpty()) {
223+
comment = GoDocumentationProvider.getCommentText(GoDocumentationProvider.getCommentsForElement(field), false);
224+
}
225+
226+
if (column != null && !column.contains(result.getPrefixMatcher().getPrefix())) continue;
227+
228+
addElement(result, column, comment, type, goTypeSpec);
229+
230+
if (!(parameters.getPosition().getParent().getParent() instanceof GoKey)) {
231+
Map<GoCallableDescriptor, List<String>> queryExpr = queryExpr();
232+
if (queryExpr != null) {
233+
List<String> whereExpr = queryExpr.get(descriptor);
234+
if (whereExpr != null) {
235+
for (String s : whereExpr) {
236+
addElement(result, String.format(s, column), comment, type, goTypeSpec);
237+
}
238+
}
239+
}
240+
}
241+
}
242+
}
243+
}
244+
245+
158246
}

src/main/java/com/github/maiqingqiang/goormhelper/orm/goframe/codeInsights/completion/GoFrameCompletionContributor.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)