Skip to content

Commit

Permalink
Merge pull request #10 from maiqingqiang/next
Browse files Browse the repository at this point in the history
v1.2.2
  • Loading branch information
johnmai-dev authored Aug 6, 2023
2 parents a651023 + cd8ea5f commit dc4eab8
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 62 deletions.
63 changes: 63 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Bug report
description: Create a report to help us improve
labels: ["bug"]
body:

- type: textarea
id: issue
attributes:
label: What happened?
description: A clear and concise description of what the bug is.
validations:
required: true

- type: textarea
id: logs
attributes:
label: Relevant log output or stack trace
description: |
Please copy and paste any relevant log output.
Add the full stack trace if available.
If possible, run the failing task with `--stacktrace` flag.
*This will be automatically formatted into code, so there is no need for backticks.*
render: shell

- type: textarea
id: steps
attributes:
label: Steps to reproduce
description: Steps to reproduce the behavior – provide your build configuration.
validations:
required: true

- type: input
id: version
attributes:
label: Gradle IntelliJ Plugin version
placeholder: 1.16.0
validations:
required: true

- type: input
id: gradle
attributes:
label: Gradle version
placeholder: 8.2.1
validations:
required: true

- type: dropdown
id: os
attributes:
label: Operating System
options:
- macOS
- Linux
- Windows

- type: input
id: url
attributes:
label: Link to build, i.e. failing GitHub Action job
placeholder: https://github.com/username/project/actions/runs/1234567890
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blank_issues_enabled: true
contact_links:
- name: Documentation
url: https://github.com/JetBrains/intellij-platform-plugin-template
about: Check the README file in the first place.
- name: Getting Help
url: https://plugins.jetbrains.com/docs/intellij/getting-help.html
about: Check if you search for a help in plugin development.
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Feature request
description: Suggest an idea for this project
labels: ["enhancement"]
body:

- type: textarea
id: cause
attributes:
label: Describe the need of your request
description: A clear and concise description of what the need or problem is.
validations:
required: true

- type: textarea
id: solution
attributes:
label: Proposed solution
description: A clear and concise description of what you want to happen.
validations:
required: true

- type: textarea
id: alternatives
attributes:
label: Alternatives you've considered
description: What did you try so far to accomplish the goal?

- type: textarea
id: context
attributes:
label: Additional context
description: Add any other context or screenshots about the feature request here.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

## [Unreleased]

## [1.2.2] - 2023-08-06

### Fixed

- When using the DAO tool to generate a model, the field names are directly used as saved in the DAO. #9

## [1.2.1] - 2023-07-25

### Added
Expand Down Expand Up @@ -63,6 +69,8 @@

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

[1.2.2]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.1...v1.2.2

[1.2.1]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.0...v1.2.1

[1.2.0]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.1.0...v1.2.0
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = com.github.maiqingqiang.goormhelper
pluginName = Go ORM Helper
pluginRepositoryUrl = https://github.com/maiqingqiang/go-orm-helper
# SemVer format -> https://semver.org
pluginVersion = 1.2.1
pluginVersion = 1.2.2

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 222
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# libraries
annotations = "24.0.1"
lombok = "1.18.28"
guava = "32.1.1-jre"
guava = "32.1.2-jre"
druid = "1.2.18"
jsqlparser = "4.6"
evoInflector = "1.3"
Expand All @@ -13,7 +13,7 @@ kotlin = "1.9.0"
changelog = "2.1.2"
gradleIntelliJPlugin = "1.15.0"
qodana = "0.1.13"
kover = "0.7.2"
kover = "0.7.3"

[libraries]
annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }
Expand Down
6 changes: 5 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
rootProject.name = "Go ORM Helper"
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.6.0"
}

rootProject.name = "Go ORM Helper"
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull

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

argument = findAgainArgument(argument);
argument = findAgainArgument(argument, parameters, descriptor, result);

GoORMHelperCacheManager manager = GoORMHelperCacheManager.getInstance(project);

Expand Down Expand Up @@ -156,7 +156,7 @@ protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull
}
}

protected GoCompositeElement findAgainArgument(GoCompositeElement argument) {
protected GoCompositeElement findAgainArgument(GoCompositeElement argument, @NotNull CompletionParameters parameters, GoCallableDescriptor descriptor, @NotNull CompletionResultSet result) {
return argument;
}

Expand Down Expand Up @@ -358,7 +358,7 @@ private void scanFields(@NotNull CompletionParameters parameters, GoCallableDesc
}

if (column != null && column.isEmpty()) {
if (field.getFieldDefinitionList().size() == 0 && field.getAnonymousFieldDefinition() != null) {
if (field.getFieldDefinitionList().isEmpty() && field.getAnonymousFieldDefinition() != null) {
GoType goType = field.getAnonymousFieldDefinition().getGoType(ResolveState.initial());
if (goType == null) continue;

Expand Down Expand Up @@ -401,7 +401,7 @@ private void scanFields(@NotNull CompletionParameters parameters, GoCallableDesc
}
}

private void addElement(@NotNull CompletionResultSet result, String column, String comment, String type, @NotNull GoTypeSpec goTypeSpec) {
protected void addElement(@NotNull CompletionResultSet result, String column, String comment, String type, @NotNull GoTypeSpec goTypeSpec) {
LookupElementBuilder builder = LookupElementBuilder
.createWithSmartPointer(column, goTypeSpec)
.withPresentableText(column)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import com.github.maiqingqiang.goormhelper.orm.ORMCompletionProvider;
import com.github.maiqingqiang.goormhelper.orm.goframe.GoFrameTypes;
import com.github.maiqingqiang.goormhelper.ui.Icons;
import com.github.maiqingqiang.goormhelper.utils.Strings;
import com.goide.documentation.GoDocumentationProvider;
import com.goide.inspections.core.GoCallableDescriptor;
import com.goide.inspections.core.GoCallableDescriptorSet;
import com.goide.psi.*;
import com.goide.psi.impl.GoPsiUtil;
import com.google.common.base.CaseFormat;
import com.intellij.codeInsight.completion.CompletionParameters;
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.psi.PsiReference;
import com.intellij.psi.ResolveState;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;

public class GoFrameColumnCompletionProvider extends ORMCompletionProvider {

Expand Down Expand Up @@ -147,12 +150,97 @@ protected GoCompositeElement customFindGoCompositeElementByGoCallExpr(GoCallExpr
}

@Override
protected GoCompositeElement findAgainArgument(GoCompositeElement argument) {
protected GoCompositeElement findAgainArgument(GoCompositeElement argument, @NotNull CompletionParameters parameters, GoCallableDescriptor descriptor, @NotNull CompletionResultSet result) {
if (argument instanceof GoCallExpr goCallExpr) {
GoType newArgument = findGoTypeByReceiver(goCallExpr, Set.of(GoTypeSpecDescriptor.of("builtin.string")));
if (newArgument != null) return newArgument;
if (newArgument != null && newArgument.resolve(ResolveState.initial()) instanceof GoTypeSpec goTypeSpec) {

HashMap<String, String> columnMap = new HashMap<>();

for (PsiReference search : GoReferencesSearch.search(goTypeSpec)) {
if (search.getElement().getParent() instanceof GoCompositeLit goCompositeLit) {
GoLiteralValue goLiteralValue = goCompositeLit.getLiteralValue();
if (goLiteralValue != null) {
for (GoElement goElement : goLiteralValue.getElementList()) {

if (goElement.getKey() != null && goElement.getKey().getFieldName() != null && goElement.getValue() != null && goElement.getValue().getExpression() instanceof GoStringLiteral goStringLiteral) {
columnMap.put(goElement.getKey().getFieldName().getIdentifier().getText(), goStringLiteral.getDecodedText());
}
}
}
}
}

scanFieldsByGoFrame(parameters, descriptor, result, goTypeSpec, columnMap);

return null;
}
}
return argument;
}


private void scanFieldsByGoFrame(@NotNull CompletionParameters parameters, GoCallableDescriptor descriptor, @NotNull CompletionResultSet result, @NotNull GoTypeSpec goTypeSpec, HashMap<String, String> columnMap) {
if (goTypeSpec.getSpecType().getType() instanceof GoStructType goStructType) {
for (GoFieldDeclaration field : goStructType.getFieldDeclarationList()) {

if (!checkGoFieldDeclaration(field)) continue;

String name = field.getFieldDefinitionList().get(0).getName();

String column = columnMap.get(name);
String comment = getComment(field);
String type = "";

if (field.getType() != null) {
type = field.getType().getPresentationText();
}

if (column != null && column.isEmpty()) {
column = getColumn(field);

if (column != null && column.isEmpty()) {
if (field.getFieldDefinitionList().isEmpty() && field.getAnonymousFieldDefinition() != null) {
GoType goType = field.getAnonymousFieldDefinition().getGoType(ResolveState.initial());
if (goType == null) continue;

GoTypeSpec spec = (GoTypeSpec) goType.resolve(ResolveState.initial());
if (spec == null) continue;

scanFieldsByGoFrame(parameters, descriptor, result, spec, columnMap);
continue;
}

if (name != null) {
column = Strings.replaceCommonInitialisms(name);
column = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, column);
}
}
}


if (comment != null && comment.isEmpty()) {
comment = GoDocumentationProvider.getCommentText(GoDocumentationProvider.getCommentsForElement(field), false);
}

if (column != null && !column.contains(result.getPrefixMatcher().getPrefix())) continue;

addElement(result, column, comment, type, goTypeSpec);

if (!(parameters.getPosition().getParent().getParent() instanceof GoKey)) {
Map<GoCallableDescriptor, List<String>> queryExpr = queryExpr();
if (queryExpr != null) {
List<String> whereExpr = queryExpr.get(descriptor);
if (whereExpr != null) {
for (String s : whereExpr) {
addElement(result, String.format(s, column), comment, type, goTypeSpec);
}
}
}
}
}
}
}


}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class GormColumnCompletionProvider extends ORMCompletionProvider {

for (int i = 0; i < names.length; i++) {
int j = i;
if (names[j].length() > 0) {
if (!names[j].isEmpty()) {
while (names[j].charAt(names[j].length() - 1) == '\\') {
i++;
names[j] = names[j].substring(0, names[j].length() - 1) + ";" + names[i];
Expand All @@ -34,7 +34,7 @@ public class GormColumnCompletionProvider extends ORMCompletionProvider {

if (values.length >= 2) {
settings.put(k, String.join(":", Arrays.copyOfRange(values, 1, values.length)));
} else if (!k.equals("")) {
} else if (!k.isEmpty()) {
settings.put(k, k);
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public String getComment(@NotNull GoFieldDeclaration field) {
@NotNull List<Tag> tags = parseTag(tag.getValue("xorm"));

for (Tag t : tags) {
if (t.getName().equals("comment") && t.getParams().size() > 0) {
if (t.getName().equals("comment") && !t.getParams().isEmpty()) {
comment = t.getParams().get(0).replaceAll("'", "");
}
}
Expand Down
Loading

0 comments on commit dc4eab8

Please sign in to comment.