Skip to content

Commit

Permalink
Remove macro registration hack (#499)
Browse files Browse the repository at this point in the history
In old versions of IntelliJ platform it was only possible to register
macros of custom names. The only way to provide custom macro was to
override one of the existing macros. We've been overriding
`FileRelativePath` macro.

Unfortunately, since version 201.x of IntelliJ platform the hack does
not work, because the data structure to keep the macros has been
changed from a HashMap to a List. This means, the entries are not
overriden, but appended to the end of the list. MacroManager looks up
only for the first ocurrence of the name, so the one in the end of the
list will never be found if the name is not unique. The change was
done in this commit JetBrains/intellij-community@6183806

Luckily, the hack is not needed since
JetBrains/intellij-community@fdf6dbc.
This means, we can use any custom name for the macro
  • Loading branch information
Tomasz Pasternak authored Feb 27, 2020
1 parent 384fb58 commit 07f0d6a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.twitter.intellij.pants.macro;

import com.intellij.application.options.PathMacrosImpl;
import com.intellij.ide.macro.Macro;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
Expand All @@ -16,14 +15,11 @@

public class FilePathRelativeToBuiltRootMacro extends Macro {
/**
* Have to use one of the names listed in {@link PathMacrosImpl#ourToolsMacros} as a workaround due to
* https://intellij-support.jetbrains.com/hc/en-us/community/posts/206103709-Custom-macro
*
* @return corresponding name of this macro
*/
@Override
public String getName() {
return "FileRelativePath";
return "PantsFilePathRelativeToBuiltRoot";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void testFilePathRelativeMacro() throws Throwable {
String expected = String.format("%s/testprojects/tests/java/%s.java", githubRepo, testClass.getQualifiedName().replace('.', '/'));

VirtualFile fileSelected = testClass.getContainingFile().getVirtualFile();
String actual = MacroManager.getInstance().expandMacrosInString(githubRepo + "/$FileRelativePath$", false, getFakeContext(fileSelected));
String actual = MacroManager.getInstance().expandMacrosInString(githubRepo + "/$PantsFilePathRelativeToBuildRoot$", false, getFakeContext(fileSelected));

assertEquals(expected, actual);
}
Expand Down

0 comments on commit 07f0d6a

Please sign in to comment.