IntelliJ IDEA not recognizing .feature files - intellij-idea

I have installed the cucumber-java and gherkin plugins in IntelliJ IDEA but when I create a .feature file it is not recognized as a feature file. I did restart IntelliJ and have checked to make sure the plugins are enabled in the plugins settings window.feature file in IntelliJ

If you have Substeps IntelliJ Plugin enabled then that might be the issue. you will need to remove and restart.

Check Settings->Editor->File Types. Verify that Cucumber Scenario is set to a Registered Pattern of *.feature.

Check File -> Settings -> Editor -> File Types and click on the Text file type. Look at the Registered Patterns section below and verify that the file you're trying to create is not in the list of recognized patterns for Text file types.
This might happen if you created the file without initially giving it the .feature extension. If you do that and then try to add the extension afterwards IntelliJ will probably still think it's a text file and will not treat it as a feature file. This was the fix for me.
If you're seeing IntelliJ recognizing your intended feature file as some other type of file then check the recognized patterns for that file type and verify again that the file you're trying to create is NOT in that list.
See http://www.gisremotesensing.com/2014/11/solution-intellij-not-recognizing.html
For some setups, this is only half the story. Once, you have removed the old file type; now follow the steps:
Select "Cucumber scenario" in the "Recognized file types"
In the "Registered patterns" box click the "+" and type "*.feature"
Now you are all set. The feature files will be back to normal.

Navigate to the settings from File option at menu then -> Editor -> File Types --> Select Cucumber scenario (Recognized file types )
observe that if Registered patterns has *.feature if not then click on + icon and add *.feature in Registered patterns.
Apply changes and save.
It solved my problem of .feature file. Thanks!

The root cause for this problem is Cucumber-Java plugin looking for BDD annotations that are imported from the package cucumber.api.java.en.Given (depricated) in StepDefinitions file. If the StepDefinitions file consists of BDD annotations from the package io.cucumber.java.en.Given the feature file won't recognize/highlight those steps. This issue is nowhere related to Intellij Version.
Temporary solution
Change your import statement in your StepDefinitions file from import io.cucumber.java.en.Given; to import cucumber.api.java.en.Given; Apply the same to When, Then and But unless if you don't mind using deprecated methods ;)
Note
If you use the info.cukesdependency you won't have any problem with the cucumber-java plugin
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>
You need to use the Temporary Solution if you have the io.cucumber dependency
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.6.0</version>
</dependency>

I had the same issue:
Substeps not enabled in my IDE... soooo:
Check if you have garbage .feature of former Files in your File Types patterns. Somehow i had two feature files under the text-Format File Type... that caused new feature files not being recognized as such on creation.
I think this happens if you do not mark files as feature-files on creation and do this afterwards with refactoring. Then intelliJ saves the pattern of the feature-file under text-type...

InjelliJ IDEA 2021.1.2
I had my feature filename listed under Settings > Editor > File Types > Auto-Detect file type by content. Removed it and its all working.

I had a typo in the file name extension. Easy to miss.
Verify that the feature file name ends with .feature.

For me it was even worse. The .feature extension was assigned to text. Which was odd as previously created .feature files remained real feature files. Yet newly created feature files were seen as plain text. So do check all relevant file types as intelIj does strange things with this.

In my case when I tried to add .feature file, a prompt came up and I added the file as text. Then Intellij automatically suggested that it found plugins(Gherkin plugin) matching .feature file. After installing Gherkin plugin , IntelliJ automatically formatted the file with Gherkin format

Using IntelliJ IDEA 2022.1.2 (Ultimate Edition)
A quite quick manual patch is to right click on the .feature file you want to be recognised. A dropdown menu should appear. Click on the "Override File Type" option. Then, scroll down until you find "Gherkin", and select it.

Related

Intellij IDEA. Check syntax for files without extension

I have Jenkinsfile it's written in Groovy, but file name doesn't have approprite extension: .groovy. How can I tell IDEA to check groovy syntax of this file?
Update:
Also I interested in the same question about GoLand IDE
From the project sidebar, right-click the file and choose "Associate with File Type". Then just select Groovy from the menu, and you're all set.
GoLand does not support Groovy so this will not be possible there.
If you add following header comment in the beginning of your Jenkinsfile:
#!groovy
IntelliJ IDEA will automatically recognize this file as a Groovy source file. It should work for other editors and IDEs as well.

Contents of .feature file isn't recognized in intelliJ

I wrote feature files in a project in IntelliJ according to the cucumber syntax. This files worked in another computer. I added the cucumber-java jar files and also installed the Gherkin and cucumber plugins, but still feature files aren't recognized as they should be.
What could be the problem?
So i use IntelliJ 2018
1) go to Preference
2)in open tab search "File Types" and search for text
3) in Text inside "Registred Patterns" delete "*.feature"
4) then search Cucumber Scenario and add "*.feature"
Steps I took to get .feature files recognized. I know that you've probably done this already, but it might help checking the steps again. If all fails, you could try to reinstall the plugins.
Created a new Java project
Created a new file with the .feature extension. Because the plugins were not installed, got the message "Plugins supporting *.feature files found." with the option to install the plugins
I didn't use this option because the suggested plugins were not what I wanted (check below image):
Instead, I've opened Settings > Plugins > Browse Repositories and searched for Cucumber for Java
When trying to install this plugin you will be required to accept the installation of Gherkin as well. Make sure that after accepting, both plugins are selected.
Restart IntelliJ and you should see the feature files recognized:
Hope it helps!
After installing plugin if you till face problem as i did, my feature files are not getting recognized because of groovy
therefore I manually set
File>>Settings>>Editor>>File Types
click "cucumber Scenario" and Click + to add .Feature in Recognize Patterns.
First make sure you have cucumber for java installed, if it is installed follow the below stpes,
1) Create a new feature file, like <test.feature> , after file creation a dialog box pops up
2) Select cucumber scenario in form the list and click Ok, there you GO.
Essentially two things are required to get cucumber feature recognized as expected type.
After adding cucumber-java dependency in pom.xml
You have to add Cucumber plugin also from >
Settings>Plugin>MarketPlace>Search for cucumber for Java and install it
This will also ask you to install Gherkin as a Dependency
Select Yes>> Restart ide
Now you have to change file type from settings >> to cucumber scenario.
Note: you wont be getting Cucumber scenario as recognized type until done above installation.
Select cucumber scenario and Add + wildcard for it as-*.feature

Is it possible to configure file types mapping in Idea via gradle 'idea' plugin

A little intro:
I work on a project with legacy codebase witch uses internal xml based descriptors with specific file extensions (about may be 10 extensions).
Let it be *.desc, *.check etc.
To have code highlighting for such a files I can configure Idea to consider these types of files as XML.
It's available through:
Preferences / Editor / File types
And then add all custom extensions to 'Recognized file types': 'XML'
Our project uses gradle as build tool
and my question is:
Is it possible to make same configuration via dsl of gadle 'idea' plugin?
The short answer is: No.
One could create a custom Gradle task that will modify IDE file type preferences XML file in the config directory. While it's possible to run such task automatically on the project refresh in IntelliJ IDEA, it will most likely not work since you can't modify IDE configuration when IDE is running (the changes will be reverted). So, you will have to run it from the command line, outside of IntelliJ IDEA when IDE is not running.
It's probably not what you want, but if documented, can be used by the team as the manual step to make this configuration change easier.
Using gradle idea is not recommended anyway.
A better way might be to provide your own IDE plug-in that will associate these file extensions with XML file type and instruct the team to install this plug-in.

xml files are not copied to target intellij idea

I have some xml files within the source folder along with the java files.
Intellij Idea is not copying them to the target folder.
I want those xml files to be along with the classes in the target.
Eclipse does this fine.
Can anyone please tell how to achieve this in Intellij Idea?
If, like me, the other answer didn't solve your problem -
If IDEA thinks your project is a Maven module (or once was), and it isn't, it'll behave like this. You can fix this by closing the project, editing the .iml file to remove the isMavenModule property, reopening, and rebuilding:
<moduleorg.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true"type="JAVA_MODULE" version="4">
In its default configuration, IDEA should copy any xml file that are in a source directory into the target directory. Other build tools may not. So this answer is assuming you are making the project via IDEA's internal build/make. If using maven (or gradle), you should place your resources in src/main/resources and not src/main/java as Engineer Dollery mentions in his/her comment.
If you are using the IDEA builds and it is still not copying them over, there is a setting you can check. Go into Settings > Build, Execution, Development > Compiler. On the Compiler settings dialog at the top is a "Resource Patterns" text field. This will define what files IDEA will and will not copy over. The default entry is:
!?*.java
!?*.form
!?*.class
!?*.groovy
!?*.scala
!?*.flex
!?*.kt
!?*.clj
!?*.aj
It is just a set of negation patterns of things not to copy over. So XML files should be copied. Check this setting and see if there is something in it to prevent xml files from being copied.

How do I add my fragment to the list of required-plugins on an existing plugin

I currently have an existing plugin, which references a class from a required plugin. I have replaced this code with a reference to a class which is part of my fragment.
I am facing two issues.
If I import my fragment as a jar file, I am not able to see the changes I have made as the plugin running as an eclipse application results in a ClassNotFoundException
To overcome this, I link an additional source (of fragment) to the existing plugin project. However, the link uses an absolute path, and makes it unfit for deployment.
I want to be able to package the plugin with the code modification and be able to "depend" on my fragment code. Is there a way I can add my fragment as a dependency?
For example:
Plugin Project I am changing : org.eclipse.*.editor
it depends on org.eclipse.*.edit
I have a fragment mydomain.*.edit which has org.eclipse.*.edit as host plugin
I want org.eclipse.*.editor to pick up mydomain.*.edit
instead of org.eclipse.*.edit
ps: I have also tried packaging the jar file for the mydomain.*.edit in the plugins directory and try and pick it up from there, it doesnt show up on the list when I click add required plugins on the dependency tab on the plugin.xml file of the org.eclipse.*.editor
Please let me know if I am not clear enough, I will try and rephrase it.
Thanks in advance!
If I understand correctly what you want to do, I don't think that it's possible. You will have to try some other way.
Plugins have dependencies on other plugins. Fragments don't exist as separate runtime entities, but only as extensions of a plugin. So your plugin can only refer to the 'editor' plugin.
Classes provided by a fragment can't (and shouldn't) be accessed directly. They can be returned by the original plugin (A) if they are implementing an executable extension provided by plugin A.
If you refer to the fragment's code from another plugin (B), the classes will be loaded by plugin B's classloader and be different from the ones that are loaded by plugin A.
What is the purpose of your fragment? Do you want to get access to internal code in plugin A? Do you want to extend an eclipse editor?
If you want to extend functionality that the original plugin is not exposing as extensible, I think the only way is to write a plugin, extend the editor class from the original plugin, register it alongside the original one and use it instead.
[Edit] Maybe this link will explain better: Eclipse FAQ
Hope this helps,
Vlad
Thanks Vlad,
Your explanation was very helpful. Unlike the extension based architecture that is truly intended for fragments, I had to modify a certain component in the editor that was not exposed as part of the extension. This modification referred to an external project I created as an fragment but could have been a normal java project packaged a jar file that I could place in the classpath of the editor.
I was able to resolve the dependency issues by placing the jar file in class path, however when I export the plugins and related plugins as jar files and place it in the dropin directory, it does not install correctly. (Nor does placing the jar files in the plugins directory)
The eclipse editor that I am trying to modify uses the EMF project. I have kept the EMF project in the workspace inorder to resolve dependencies of the editor. However when I replace the EMF jar files bundled with eclipse with the one in the workspace, the files that I want to edit are not correctly recognized.
Is there another way of doing this?