Skip to content

Commit

Permalink
Merge pull request #1443 from JetBrains/refactor/css-optional
Browse files Browse the repository at this point in the history
Make CSS an optional dependency
  • Loading branch information
citizenmatt authored Dec 10, 2019
2 parents 7720a4c + b6a3865 commit 847aa76
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 62 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,22 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0).

This plugin has functionality that is common to both ReSharper and Rider. It also contains a plugin for the Unity editor that is used to communicate with Rider. Changes marked with a "Rider:" prefix are specific to Rider, while changes for the Unity editor plugin are marked with a "Unity editor:" prefix. No prefix means that the change is common to both Rider and ReSharper.

## 2019.3.1
* [Commits](https://github.com/JetBrains/resharper-unity/compare/net193-eap7-rtm-2019.3.0...net193)
* [Milestone](https://github.com/JetBrains/resharper-unity/milestone/33?closed=1)

### Added

- Added proper file icons for `*.uxml` and `*.uss` ([RIDER-34788](https://youtrack.jetbrains.com/issue/RIDER-34788), [#1443](https://github.com/JetBrains/resharper-unity/pull/1443))

### Changed

- Entire plugin is no longer disabled if the CSS plugin is disabled ([RIDER-36523](https://youtrack.jetbrains.com/issue/RIDER-36523), [#1443](https://github.com/JetBrains/resharper-unity/pull/1443))



## 2019.3
* [Commits](https://github.com/JetBrains/resharper-unity/compare/192...net193)
* [Commits](https://github.com/JetBrains/resharper-unity/compare/192...net193-eap7-rtm-2019.3.0)
* [Milestone](https://github.com/JetBrains/resharper-unity/milestone/29?closed=1)

### Added
Expand Down Expand Up @@ -51,6 +65,7 @@ This plugin has functionality that is common to both ReSharper and Rider. It als
- Fix orphan `.meta` file during "Safe Delete" refactoring ([#856](https://github.com/JetBrains/resharper-unity/issues/856), [#1389](https://github.com/JetBrains/resharper-unity/pull/1389))
- Fix correctly keeping `.meta` files up to date in `Packages` folder ([#1231](https://github.com/JetBrains/resharper-unity/issues/1231), [#1389](https://github.com/JetBrains/resharper-unity/pull/1389))
- Fix "Add RequireComponent" context action to correctly add second attribute ([#RIDER-34390](https://youtrack.jetbrains.com/issue/RIDER-34390), [#1416](https://github.com/JetBrains/resharper-unity/pull/1416])
- Fix issues with ordering of multiplication of vector multiplication ([RIDER-33981](https://youtrack.jetbrains.com/issue/RIDER-33981), [RIDER-32798](https://youtrack.jetbrains.com/issue/RIDER-32798), [RIDER-32851](https://youtrack.jetbrains.com/issue/RIDER-32851), [#1168](https://github.com/JetBrains/resharper-unity/issues/1168), [#1428](https://github.com/JetBrains/resharper-unity/pull/1428))
- Rider: Fix race condition preventing "Attach to Unity Process" dialog from always listing players ([RIDER-34039](https://youtrack.jetbrains.com/issue/RIDER-34039), [#1298](https://github.com/JetBrains/resharper-unity/pull/1298))
- Rider: Prevent "Attach to Unity Process" attempting to attach to the same process multiple times ([#1129](https://github.com/JetBrains/resharper-unity/issues/1129), [#1298](https://github.com/JetBrains/resharper-unity/pull/1298))
- Rider: Fix show usages on Code Vision link for auto property event handlers ([#1142](https://github.com/JetBrains/resharper-unity/pull/1142))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.intellij.openapi.fileTypes.LanguageFileType
import icons.UnityIcons

object UssFileType: LanguageFileType(UssLanguage) {
override fun getIcon() = UnityIcons.FileTypes.Asset
override fun getIcon() = UnityIcons.FileTypes.Uss
override fun getName() = "USS"
override fun getDefaultExtension() = "uss"
override fun getDescription() = "UIElement Style Sheet File (Unity)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.intellij.ide.highlighter.XmlLikeFileType
import icons.UnityIcons

object UxmlFileType : XmlLikeFileType(UxmlLanguage) {
override fun getIcon() = UnityIcons.FileTypes.Asset
override fun getIcon() = UnityIcons.FileTypes.Uxml
override fun getName() = "UXML"
override fun getDefaultExtension() = "uxml"
override fun getDescription() = "UIElement UXML File (Unity)"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.jetbrains.rider.plugins.unity.ui

import com.intellij.ide.plugins.PluginManager
import com.intellij.ide.plugins.PluginManagerMain
import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.fileTypes.FileTypeRegistry
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.EditorNotificationPanel
import com.intellij.ui.EditorNotifications
import com.jetbrains.rider.isUnityProject
import com.jetbrains.rider.plugins.unity.ideaInterop.fileTypes.uss.UssFileType
import com.jetbrains.rider.plugins.unity.util.isUssFile

class UssDisabledEditorNotification: EditorNotifications.Provider<EditorNotificationPanel>() {

companion object {
private val KEY = Key.create<EditorNotificationPanel>("unity.uss.css.plugin.disabled.notification.panel")
private const val DO_NOT_SHOW_AGAIN_KEY = "unity.uss.css.plugin.disabled.do.not.show"
private const val CSS_PLUGIN_ID = "com.intellij.css"
}

override fun getKey(): Key<EditorNotificationPanel> = KEY

override fun createNotificationPanel(file: VirtualFile, fileEditor: FileEditor, project: Project): EditorNotificationPanel? {
if (project.isUnityProject() && isUssFile(file) && PluginManager.isDisabled(CSS_PLUGIN_ID)) {
if (PropertiesComponent.getInstance(project).getBoolean(DO_NOT_SHOW_AGAIN_KEY, false)) {
return null
}

val panel = EditorNotificationPanel()
panel.text("USS support requires the CSS plugin to be enabled")
panel.createActionLabel("Enable CSS plugin") {
// TODO: Maybe in 2020.1 we can do this dynamically without restart?
// That would require enabling the CSS plugin dynamically, and then enabling our PluginCssPart.xml part
// dynamically, too
PluginManager.enablePlugin(CSS_PLUGIN_ID)
PluginManagerMain.notifyPluginsUpdated(project)
EditorNotifications.getInstance(project).updateAllNotifications()
}
panel.createActionLabel("Don't show again") {
// Project level - do not show again for this project
PropertiesComponent.getInstance(project).setValue(DO_NOT_SHOW_AGAIN_KEY, true)
EditorNotifications.getInstance(project).updateAllNotifications()
}
return panel
}

return null
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.jetbrains.rider.plugins.unity.util

import com.intellij.openapi.fileTypes.FileTypeRegistry
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.text.CaseInsensitiveStringHashingStrategy
import com.jetbrains.rider.ideaInterop.fileTypes.msbuild.CsprojFileType
import com.jetbrains.rider.ideaInterop.fileTypes.sln.SolutionFileType
import com.jetbrains.rider.plugins.unity.ideaInterop.fileTypes.uss.UssFileType
import com.jetbrains.rider.plugins.unity.ideaInterop.fileTypes.uxml.UxmlFileType
import gnu.trove.THashSet

private val nonEditableExtensions = getExtensions()
Expand Down Expand Up @@ -48,8 +53,9 @@ fun isNonEditableUnityFileExtension(extension: String?): Boolean {
}

fun isGeneratedUnityFile(file: VirtualFile): Boolean {
val extension = file.extension
return extension.equals("csproj", true) || extension.equals("sln", true)
val fileTypeRegistry = FileTypeRegistry.getInstance()
return fileTypeRegistry.isFileOfType(file, CsprojFileType) || fileTypeRegistry.isFileOfType(file, SolutionFileType)
}

fun isUxmlFile(file: VirtualFile) = file.extension.equals("uxml", true)
fun isUxmlFile(file: VirtualFile) = FileTypeRegistry.getInstance().isFileOfType(file, UxmlFileType)
fun isUssFile(file: VirtualFile) = FileTypeRegistry.getInstance().isFileOfType(file, UssFileType)
6 changes: 5 additions & 1 deletion rider/src/main/kotlin/icons/UnityIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ class UnityIcons {

val AsmDef = ReSharperPsiJavaScriptIcons.Json

val UnityYaml: Icon = IconLoader.getIcon("/resharper/YamlFileType/FileYaml.svg")
val UnityYaml = IconLoader.getIcon("/resharper/YamlFileType/FileYaml.svg")
val UnityScene = IconLoader.getIcon("/resharper/UnityFileType/FileUnity.svg")
val Meta = IconLoader.getIcon("/resharper/UnityFileType/FileUnityMeta.svg")
val Asset = IconLoader.getIcon("/resharper/UnityFileType/FileUnityAsset.svg")
val Prefab = IconLoader.getIcon("/resharper/UnityFileType/FileUnityPrefab.svg")

// These are front end only file types
val Uss = IconLoader.getIcon("/Icons/fileTypes/uss.svg")
val Uxml = IconLoader.getIcon("/Icons/fileTypes/uxml.svg")
}
}

Expand Down
22 changes: 22 additions & 0 deletions rider/src/main/resources/Icons/fileTypes/uss.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions rider/src/main/resources/Icons/fileTypes/uxml.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions rider/src/main/resources/META-INF/PluginCssPluginPart.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<idea-plugin>
<!-- USS depends on CSS, but make it an optional dependency, so we don't disable all of Unity support if someone
decides to disable CSS. We'll prompt to enable CSS if they open a *.uss file -->
<extensions defaultExtensionNs="com.intellij">
<!-- USS support -->
<lang.parserDefinition language="USS" implementationClass="com.jetbrains.rider.plugins.unity.ideaInterop.fileTypes.uss.UssFileParserDefinition"/>
<lang.syntaxHighlighter language="USS" implementationClass="com.jetbrains.rider.plugins.unity.ideaInterop.fileTypes.uss.UssSyntaxHighlighter" />
<breadcrumbsInfoProvider implementation="com.jetbrains.rider.plugins.unity.ideaInterop.fileTypes.uss.UssFileBreadcrumbsProvider" />
<css.elementDescriptorProvider implementation="com.jetbrains.rider.plugins.unity.ideaInterop.fileTypes.uss.codeInsight.css.UssCssElementDescriptorProvider" order="first" />
<css.cssInspectionFilter language="USS" implementationClass="com.jetbrains.rider.plugins.unity.ideaInterop.fileTypes.uss.codeInsight.css.inspections.UssCssInspectionFilter"/>
<css.cssIntentionFilter language="USS" implementationClass="com.jetbrains.rider.plugins.unity.ideaInterop.fileTypes.uss.codeInsight.css.inspections.UssCssIntentionFilter"/>
<!-- Override the CSS documentation for USS files -->
<lang.documentationProvider language="CSS" implementationClass="com.jetbrains.rider.plugins.unity.ideaInterop.fileTypes.uss.UssDocumentationProvider" order="first"/>

<applicationService serviceImplementation="com.jetbrains.rider.plugins.unity.ideaInterop.fileTypes.uss.codeInsight.css.UssCssElementDescriptorFactory" />
</extensions>
</idea-plugin>
Loading

0 comments on commit 847aa76

Please sign in to comment.