how to extend system behavior (Go Struct customized tag autocomplete)

Answered

I am going add customize tag autocomplete for go struct.

 

is there any way to achieve this?

 

0
7 comments

Hi,

Here you go:

  • Navigate to Settings / Preferences | Editor | Live Templates | Go Struct Tags.
  • Click on the Plus button to create a new template, select Live Template.
  • Fill out an abbreviation, e.g. graphql, description and template text like graphql:"$FIELD_NAME$"$END$
  • Click on Edit variables button and type fieldName() on the Expression field or camelCase(fieldName()) if you prefer camelCase instead of snake_case. Click on OK button.
  • Define the context of the template by clicking on Define button. Select Tag literal option.
  • Apply changes, return to the struct, start typing `gr and invoke Code Completion (Control(Ctrl)+Space).

I hope it helps.

0

thank you very much! 

In fact I want to achieve this by a plugin. are there any examples?

0

In fact I want to achieve this by a plugin. are there any examples?

Could you elaborate, please? Do you mean Go plugin with IntelliJ IDEA?

0

yes, I found the example.

com.goide.inspections.tag.GoTagValueCompletionContributor

 

@NotNull
static Capture<PsiElement> rawStringInStructTag() {
Capture var10000 = GoTagUtil.RAW_STRING_IN_STRUCT_TAG;
if (var10000 == null) {
$$$reportNull$$$0(0);
}

return var10000;
}
0

Absolutely the same steps.

0

I found the example.

com.goide.inspections.tag.GoTagValueCompletionContributor

 

@NotNull
static Capture<PsiElement> rawStringInStructTag() {
Capture var10000 = GoTagUtil.RAW_STRING_IN_STRUCT_TAG;
if (var10000 == null) {
$$$reportNull$$$0(0);
}

return var10000;
}

 

I am trying to understanding the source code. can you tell me what's the meaning of the below code block?

as we dont have the source code.

 

if (var10000 == null) {
$$$reportNull$$$0(0);
}

 

0

Please follow the guide: https://plugins.jetbrains.com/docs/intellij/goland.html

I am trying to understanding the source code. can you tell me what's the meaning of the below code block?

Could you please provide a link to the source?

0

Please sign in to leave a comment.