Search code examples
intellij-ideaintellij-plugin

Intellij open and lay out file programmatically through custom plugin


I started competing recently at HackerRank and I'd like to implement an intellij plugin to optimize my coding environment for upcoming contests. What I need is simple: open 3 custom files programmatically (input, expected and actual) when my solution fails a test case.

For better context here's the exact scenario I'm facing:

  1. I write a solution for a given problem as quick as I can and submit it to the HackerRank platform
  2. If my submission gets rejected, I generate hundreds of random small test cases under an "input" directory.
  3. I write a brute force algorithm to solve each generated input, and save expected output of each generated test case under an "expected" directory.
  4. I run a prewritten correctness test case which automatically invokes my efficient solution (which got rejected) for each input file and writes output files under an "actual" directory. The test fails when actual doesn't match expected for any given generated test case.

The problem with the above is that whenever a test fails I have to go find and open input, expected and actual manually and then lay them out side by side next to code using vertical splits so I can debug conveniently (see below)

enter image description here

Ideally I'd get to programmatically open all 3 files from my prewritten test case whenever a failure is detected and have them laid-out as in screenshot above. Would such a thing be possible with a custom written plugin, does IntelliJ allow to open files programmatically?


Solution

  • I have made something similar. A console filter which added hyperlinks for opening a Diff window, where I was comparing a xml/json from the console to a file.

    https://github.com/krasa/ProjectCommandLauncher/blob/master/src/krasa/console/RequestComparatorFilter.java

    It should be easy to customize it to make a 3-way diff, or even open it automatically instead of using console hyperlinks.

    Or if you really want to open editors, then find usages of OpenFileDescriptor in intellij-community and look into the following plugin: https://github.com/dkandalov/tab-shifter