Skip to content

Instantly share code, notes, and snippets.

@vanhoavn
Last active January 2, 2017 03:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save vanhoavn/579e929e6a82037f58736ba567c880fe to your computer and use it in GitHub Desktop.
IntelijIDEA's JavaScriptLanguage plugin's patch to group .vue component files.
package com.intellij.lang.javascript.projectView;
import com.intellij.ide.projectView.ProjectViewNestingRulesProvider;
import com.intellij.ide.projectView.ProjectViewNestingRulesProvider.Consumer;
import org.jetbrains.annotations.NotNull;
public class JSNestingRulesProvider
implements ProjectViewNestingRulesProvider
{
public void addFileNestingRules(@NotNull ProjectViewNestingRulesProvider.Consumer consumer)
{
if (consumer == null) {
throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "consumer", "com/intellij/lang/javascript/projectView/JSNestingRulesProvider", "addFileNestingRules" }));
}
consumer.addNestingRule(".js", ".min.js");
consumer.addNestingRule(".js", ".min.js.map");
consumer.addNestingRule(".js", ".map");
consumer.addNestingRule(".js", ".js.map");
consumer.addNestingRule(".js", "-compiled.js");
consumer.addNestingRule(".js", "-compiled.js.map");
consumer.addNestingRule(".jsx", ".js");
consumer.addNestingRule(".jsx", ".js.map");
consumer.addNestingRule(".es6", ".js");
consumer.addNestingRule(".es6", ".js.map");
consumer.addNestingRule(".ts", ".js");
consumer.addNestingRule(".ts", ".js.map");
consumer.addNestingRule(".ts", ".d.ts");
consumer.addNestingRule(".tsx", ".js");
consumer.addNestingRule(".tsx", ".js.map");
consumer.addNestingRule(".tsx", ".d.ts");
consumer.addNestingRule(".tsx", ".jsx");
consumer.addNestingRule(".tsx", ".jsx.map");
// below is the new .vue group
consumer.addNestingRule(".vue", ".html");
consumer.addNestingRule(".vue", ".pug");
consumer.addNestingRule(".vue", ".jade");
consumer.addNestingRule(".vue", ".js");
consumer.addNestingRule(".vue", ".ts");
consumer.addNestingRule(".vue", ".d.ts");
consumer.addNestingRule(".vue", ".tsx");
consumer.addNestingRule(".vue", ".d.tsx");
consumer.addNestingRule(".vue", ".coffee");
consumer.addNestingRule(".vue", ".css");
consumer.addNestingRule(".vue", ".scss");
consumer.addNestingRule(".vue", ".styl");
}
}
<?php
$lib = '/Applications/WebStorm.app/Contents/lib';
// actually only need annotations.jar:openapi.jar
passthru('javac -cp '.escapeshellarg(implode(":", glob("$lib/*.jar"))).' JSNestingRulesProvider.java');
apply_patch('/Applications/WebStorm.app/Contents/plugins/JavaScriptLanguage/lib/JavaScriptLanguage.jar');
function apply_patch($target){
echo "* APPLY PATCH FOR $target\n";
if (!file_exists($target)) {
echo " ==> File not found\n";
return -1;
}
$backup = backup_file($target);
echo "* Backup file is $backup\n";
if (!file_exists($backup)) {
echo "* Creating backup file\n";
@copy($target, $backup);
}
if (!file_exists($backup)) {
echo "* Cannot create backup file\n";
return -1;
}
echo "* Reset\n";
@unlink($target);
@copy($backup, $target);
passthru("rm -rf build\n");
mkdir("build/com/intellij/lang/javascript/projectView", 0777, true);
@copy('JSNestingRulesProvider.class', 'build/com/intellij/lang/javascript/projectView/JSNestingRulesProvider.class');
passthru("jar ufv ".escapeshellarg($target)." -C build com/intellij/lang/javascript/projectView/JSNestingRulesProvider.class");
}
function backup_file($fn){
return preg_replace('@\.[^\.]+$@ism', '--bak$0--bak', $fn);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment