Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Commit

Permalink
Add action to create a file type report for further debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
jansorg committed Aug 27, 2018
1 parent db47825 commit 443afff
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
@@ -1,3 +1,6 @@
#### 2018-08-27:
- Add action to create a report on the currently detected file type

#### 2018-08-25:
- fix to improve handling of local variables in functions
- \#566: Fix slow startup of the IDE when BashSupport is installed
Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Expand Up @@ -48,6 +48,11 @@ allprojects {
pluginName 'BashSupport'
plugins 'IntelliLang', 'terminal'
downloadSources Boolean.valueOf(sources)

patchPluginXml {
sinceBuild '145.0'
untilBuild '182.*'
}
}

publishPlugin {
Expand Down
2 changes: 2 additions & 0 deletions dev-resources/META-INF/plugin.xml
Expand Up @@ -64,6 +64,8 @@
<add-to-group group-id="ToolsMenu" anchor="last"/>
</action>

<action class="com.ansorgit.plugins.bash.actions.ReportFileTypeAction" id="bash.reportType" />

<action id="Bash.NewBashScript" class="com.ansorgit.plugins.bash.actions.NewBashFileAction"
text="Bash Script" description="Create new Bash script file">
<add-to-group group-id="NewGroup" relative-to-action="NewFile" anchor="after"/>
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
@@ -1,7 +1,7 @@
ideaBranch=182
ideaVersion=182.2574.2
javaVersion=1.8
kotlinVersion=1.2.60
kotlinVersion=1.2.61
sources=false
pluginChannels=eap

Expand Down
2 changes: 1 addition & 1 deletion pluginVersion.txt
@@ -1 +1 @@
1.6.13
1.6.900
23 changes: 18 additions & 5 deletions resources/META-INF/plugin.xml
Expand Up @@ -24,7 +24,7 @@

<vendor url="https://www.plugin-dev.com/" email="mail@plugin-dev.com">Joachim Ansorg</vendor>

<!-- Requires IDEA 182.x or later -->
<!-- Requires IDEA 145.x to IDEA 182.x -->
<idea-version since-build="145.0" until-build="182.*"/>

<!-- Mark the plugin as compatible with RubyMine and other products based on the IntelliJ platform -->
Expand All @@ -39,14 +39,26 @@

<change-notes><![CDATA[
<html>
<b>Changes in version 1.7.0:</b>
<b>Changes in version 1.7.0 (eap release):</b>
<ul>
<li></li>
<li>Add action to create a report on the currently detected file type</li>
<li>fix to improve handling of local variables in functions</li>
<li>#566: Fix slow startup of the IDE when BashSupport is installed</li>
<li>Enhancement: show path next to path command completion items</li>
<li>new icons for plugin (contributed by nosovae-dev)</li>
<li>Feature: Add folding for variables (contributed by nosovae-dev)</li>
<li>Add kotlin language for development plugin (contributed by nosovae-dev)</li>
<li>#558: Enable execute button of Bash run configuration even when IntelliJ is indexing</li>
<li>#551: Add default value TERM=xterm-256color when running a Bash script if there's not value defined in the run configuration</li>
<li>#545: Don't parse "in" in "read in" as keyword, but as variable name</li>
<li>#482: Make new Bash files executable for the current user by default</li>
<li>Feature: Add inspection to check, whether function name is in lower camel case (contribued by dheid)</li>
<li>Feature: Add inspection and quickfix to detect double brackets (contribued by dheid)</li>
</ul>
<br/>
<br/>
<a href="https://github.com/jansorg/BashSupport/blob/idea-162.x/Changelog.md">Full changelog</a>
<a href="https://github.com/jansorg/BashSupport/blob/master/Changelog.md">Full changelog</a>
</html>
]]>
</change-notes>
Expand All @@ -70,6 +82,7 @@
<add-to-group group-id="NewGroup" relative-to-action="NewFile" anchor="after"/>
</action>

<action class="com.ansorgit.plugins.bash.actions.ReportFileTypeAction" id="bash.reportType" />

<!-- A subset of the REPL actions that should be displayed in the panel toolbar. -->
<group id="Bash.REPL.Group"
Expand All @@ -89,7 +102,7 @@
<!-- The factory registers the known file extensions-->
<fileTypeFactory implementation="com.ansorgit.plugins.bash.file.BashFileTypeLoader"/>
<!-- The detector looks at the content of a file and tries to guess if it is a bash file-->
<fileTypeDetector implementation="com.ansorgit.plugins.bash.file.BashFileTypeDetector"/>
<fileTypeDetector implementation="com.ansorgit.plugins.bash.file.BashFileTypeDetector" />

<!-- Syntax highlighting -->
<syntaxHighlighter key="Bash" implementationClass="com.ansorgit.plugins.bash.editor.highlighting.BashSyntaxHighlighter"/>
Expand Down
80 changes: 80 additions & 0 deletions src/com/ansorgit/plugins/bash/actions/ReportFileTypeAction.kt
@@ -0,0 +1,80 @@
package com.ansorgit.plugins.bash.actions

import com.ansorgit.plugins.bash.file.BashFileTypeDetector
import com.ansorgit.plugins.bash.util.BashIcons
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.fileTypes.FileTypeRegistry
import com.intellij.openapi.fileTypes.ex.FileTypeManagerEx
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.util.SystemInfoRt
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.psi.PsiDocumentManager

/**
* @author jansorg
*/
class ReportFileTypeAction() : AnAction("Bash: file type detection report", "", BashIcons.BASH_FILE_ICON) {
override fun actionPerformed(e: AnActionEvent) {
val project = e.getData(CommonDataKeys.PROJECT) as Project
val editor = CommonDataKeys.EDITOR.getData(e.dataContext)
if (editor == null) {
Messages.showInfoMessage("No open file found.", "Bash file type detection")
return
}

val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.document)
if (psiFile == null) {
Messages.showInfoMessage("No PSI file found.", "Bash file type detection")
return
}

val virtualFile = psiFile.virtualFile

val typeRegistry = FileTypeRegistry.getInstance()
val detectedType = typeRegistry.getFileTypeByFile(virtualFile)
val isIgnored = typeRegistry.isFileIgnored(virtualFile)
val typeByName = typeRegistry.getFileTypeByFileName(psiFile.name)

val psiFileType = psiFile.fileType
val vfsFileType = virtualFile?.fileType

val typeManager = FileTypeManagerEx.getInstanceEx()

val initialContent = VfsUtilCore.loadText(virtualFile, 512)
val firstLine = initialContent.lines().firstOrNull()
val bashDetectedType = when (firstLine) {
null -> null
else -> BashFileTypeDetector.detect(virtualFile, firstLine)
}

val report = """
Please report an issue at https://github.com/BashSupport/BashSupport/issues
if the Bash file isn't properly displayed. You can select and copy the information below.
File name: ${virtualFile.path}
File extension: ${virtualFile.extension}
First line: $firstLine
Attached PSI file type: $psiFileType
Attached VFS file type: $vfsFileType
Detected file type: ${detectedType}
Ignored: ${isIgnored}
Type by filename: ${typeByName}
Ignored files: ${typeManager.ignoredFilesList}
Detected by content: ${typeManager.detectFileTypeFromContent(virtualFile)}
Detected by bash detector: ${bashDetectedType}
IDE: ${ApplicationInfo.getInstance().build}
OS: ${SystemInfoRt.OS_NAME}
OS version: ${SystemInfoRt.OS_VERSION}
File system case sensitive: ${SystemInfoRt.isFileSystemCaseSensitive}
""".trimIndent()

Messages.showInfoMessage(report, "Bash file type detection")
}
}
5 changes: 5 additions & 0 deletions src/com/ansorgit/plugins/bash/file/BashFileType.java
Expand Up @@ -42,6 +42,11 @@ protected BashFileType() {
super(new BashLanguage());
}

@Override
public String toString() {
return "BashFileType";
}

@NotNull
public String getName() {
return "Bash";
Expand Down
5 changes: 5 additions & 0 deletions src/com/ansorgit/plugins/bash/file/BashFileTypeDetector.java
Expand Up @@ -44,6 +44,11 @@ public class BashFileTypeDetector implements FileTypeRegistry.FileTypeDetector {
@Nullable
@Override
public FileType detect(@NotNull VirtualFile file, @NotNull ByteSequence firstBytes, @Nullable CharSequence textContent) {
return detect(file, textContent);
}

@Nullable
public static FileType detect(@NotNull VirtualFile file, @Nullable CharSequence textContent) {
if (textContent == null || file.getExtension() != null) {
return null;
}
Expand Down

0 comments on commit 443afff

Please sign in to comment.