Skip to content
Permalink
Browse files

skip language and file type registration for bundled languages (Git, …

…Mercurial)
  • Loading branch information...
dmitry-zhuravlev committed Jun 26, 2019
1 parent 709f603 commit a47a934cb471fff115e4f5d39692b321e073a223
@@ -41,7 +41,7 @@ intellij {
untilBuild pluginUntilBuild
}

plugins 'git4idea'
plugins 'git4idea', 'hg4idea'

publishPlugin {
username publishUsername
@@ -109,6 +109,7 @@

<depends>com.intellij.modules.lang</depends>
<depends optional="true">Git4Idea</depends>
<depends optional="true">hg4idea</depends>

<extensions defaultExtensionNs="com.intellij">

@@ -332,13 +333,7 @@
<!-- END Fossil -->

<!-- Git -->
<lang.parserDefinition language="Git"
implementationClass="mobi.hsz.idea.gitignore.lang.IgnoreParserDefinition"/>
<codeInsight.lineMarkerProvider language="Git"
implementationClass="mobi.hsz.idea.gitignore.daemon.IgnoreDirectoryMarkerProvider"/>
<lang.braceMatcher language="Git" implementationClass="mobi.hsz.idea.gitignore.lang.IgnoreBraceMatcher"/>
<lang.commenter language="Git" implementationClass="mobi.hsz.idea.gitignore.lang.IgnoreCommenter"/>
<lang.syntaxHighlighterFactory language="Git"
<lang.syntaxHighlighterFactory language="GitIgnore"
implementationClass="mobi.hsz.idea.gitignore.highlighter.IgnoreHighlighterFactory"/>
<!-- END Git -->

@@ -400,13 +395,7 @@
<!-- END Kubernetes Helm -->

<!-- Mercurial -->
<lang.parserDefinition language="Mercurial"
implementationClass="mobi.hsz.idea.gitignore.lang.IgnoreParserDefinition"/>
<codeInsight.lineMarkerProvider language="Mercurial"
implementationClass="mobi.hsz.idea.gitignore.daemon.IgnoreDirectoryMarkerProvider"/>
<lang.braceMatcher language="Mercurial" implementationClass="mobi.hsz.idea.gitignore.lang.IgnoreBraceMatcher"/>
<lang.commenter language="Mercurial" implementationClass="mobi.hsz.idea.gitignore.lang.IgnoreCommenter"/>
<lang.syntaxHighlighterFactory language="Mercurial"
<lang.syntaxHighlighterFactory language="HgIgnore"
implementationClass="mobi.hsz.idea.gitignore.highlighter.IgnoreHighlighterFactory"/>
<!-- END Mercurial -->

@@ -35,6 +35,8 @@
import mobi.hsz.idea.gitignore.IgnoreBundle;
import mobi.hsz.idea.gitignore.file.type.IgnoreFileType;
import mobi.hsz.idea.gitignore.lang.IgnoreLanguage;
import mobi.hsz.idea.gitignore.lang.kind.GitLanguage;
import mobi.hsz.idea.gitignore.lang.kind.MercurialLanguage;
import mobi.hsz.idea.gitignore.util.CommonDataKeys;
import mobi.hsz.idea.gitignore.util.ExternalFileException;
import mobi.hsz.idea.gitignore.util.Utils;
@@ -115,6 +117,9 @@ public void update(@NotNull AnActionEvent e) {
baseDir = Utils.getModuleRootForFile(file, project);

for (IgnoreLanguage language : IgnoreBundle.LANGUAGES) {
//skip already bundled languages for ignore action
if (!(this instanceof UnignoreFileGroupAction) && (language instanceof GitLanguage || language instanceof MercurialLanguage)) continue;

final IgnoreFileType fileType = language.getFileType();
List<VirtualFile> list = Utils.getSuitableIgnoreFiles(project, fileType, file);
Collections.reverse(list);
@@ -30,6 +30,8 @@
import mobi.hsz.idea.gitignore.IgnoreBundle;
import mobi.hsz.idea.gitignore.file.type.IgnoreFileType;
import mobi.hsz.idea.gitignore.lang.IgnoreLanguage;
import mobi.hsz.idea.gitignore.lang.kind.GitLanguage;
import mobi.hsz.idea.gitignore.lang.kind.MercurialLanguage;
import org.jetbrains.annotations.NotNull;

/**
@@ -48,6 +50,9 @@
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
consume(consumer, IgnoreFileType.INSTANCE);
for (final IgnoreLanguage language : IgnoreBundle.LANGUAGES) {
//skip already bundled languages
if (language instanceof GitLanguage || language instanceof MercurialLanguage) continue;

consume(consumer, language.getFileType());
}
}
@@ -27,19 +27,24 @@
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.FileTypeRegistry;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.messages.MessageBusConnection;
import git4idea.ignore.lang.GitIgnoreFileType;
import mobi.hsz.idea.gitignore.file.type.IgnoreFileType;
import mobi.hsz.idea.gitignore.lang.IgnoreLanguage;
import mobi.hsz.idea.gitignore.lang.kind.GitExcludeLanguage;
import mobi.hsz.idea.gitignore.lang.kind.GitLanguage;
import mobi.hsz.idea.gitignore.lang.kind.MercurialLanguage;
import mobi.hsz.idea.gitignore.settings.IgnoreSettings;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.ignore.lang.HgIgnoreFileType;

import javax.swing.*;
import java.util.Collection;
@@ -122,11 +127,12 @@ public IgnoreEditorManagerListener(@NotNull final Project project) {
@Override
public void fileOpened(@NotNull final FileEditorManager source, @NotNull final VirtualFile file) {
final FileType fileType = file.getFileType();
if (!(fileType instanceof IgnoreFileType) || !IgnoreSettings.getInstance().isOuterIgnoreRules()) {
if (!IgnoreSettings.getInstance().isOuterIgnoreRules()) {
return;
}

final IgnoreLanguage language = ((IgnoreFileType) fileType).getIgnoreLanguage();
IgnoreLanguage language = determineIgnoreLanguage(file, fileType);
if (language == null) return;

DumbService.getInstance(project).runWhenSmart(() -> {
final List<VirtualFile> outerFiles =
@@ -162,6 +168,20 @@ public void fileOpened(@NotNull final FileEditorManager source, @NotNull final V
});
}

@Nullable
private IgnoreLanguage determineIgnoreLanguage(@NotNull VirtualFile file, FileType fileType) {
//if language provided by platform (e.g. GitLanguage) then map to language provided by plugin with extended functionality
FileTypeRegistry typeRegistry = FileTypeRegistry.getInstance();
if (typeRegistry.isFileOfType(file, GitIgnoreFileType.INSTANCE)) {
return GitLanguage.INSTANCE;
} else if (typeRegistry.isFileOfType(file, HgIgnoreFileType.INSTANCE)) {
return MercurialLanguage.INSTANCE;
} else if (fileType instanceof IgnoreFileType) {
return ((IgnoreFileType) fileType).getIgnoreLanguage();
}
return null;
}

@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
}

0 comments on commit a47a934

Please sign in to comment.
You can’t perform that action at this time.