Skip to content

Commit

Permalink
Merge pull request #4 from Q-Peppa/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Q-Peppa authored Sep 22, 2024
2 parents 309102f + bc4a013 commit bf8e902
Show file tree
Hide file tree
Showing 40 changed files with 1,253 additions and 797 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# react-css-modules-all

## [0.0.11] - 2024-09-22

1. temporary close SimpleDocumentationProvider function cause not test
2. add code test for parse css/scss
3. re-write plugin code use kotlin


## [0.0.10] - 2024-09-19

1. fix fetal error : TypeScript type miss
Expand Down
43 changes: 0 additions & 43 deletions README-zh_CN.md

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ This plugin not guaranteed all function work

### Already Issue

1. can't identify .foo > &-bar#id , "&-bar#id" with another id selector
1. can't identify .foo > &-bar#id , "&-bar#id" with another id selector'
2. com.example.ide.css.QCssModuleParseUtil.parseCssSelectorFormFile use too long time and may cause StandaloneCoroutine error
15 changes: 9 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ plugins {
group = providers.gradleProperty("pluginGroup").get()
version = providers.gradleProperty("pluginVersion").get()

kotlin {
jvmToolchain(21)
java {
sourceCompatibility = JavaVersion.VERSION_17
}


repositories {
mavenCentral()
maven("https://cache-redirector.jetbrains.com/intellij-dependencies")
maven("https://www.jetbrains.com/intellij-repository/snapshots")
maven("https://packages.jetbrains.team/maven/p/grazi/grazie-platform-public")
maven("https://download.jetbrains.com/teamcity-repository")
maven { setUrl("https://maven.aliyun.com/repository/central") }
maven { setUrl("https://maven.aliyun.com/repository/jcenter") }
maven { setUrl("https://maven.aliyun.com/repository/google") }
Expand All @@ -41,6 +47,7 @@ dependencies {
webstorm("2024.2")
bundledPlugin("JavaScript")
instrumentationTools()
bundledPlugin("org.jetbrains.plugins.sass")
testFramework(TestFrameworkType.Platform)
}
}
Expand All @@ -66,9 +73,6 @@ intellijPlatform {
sinceBuild = providers.gradleProperty("pluginSinceBuild")
untilBuild = providers.gradleProperty("pluginUntilBuild")
}



}

publishing {
Expand All @@ -88,4 +92,3 @@ changelog {
groups.empty()
repositoryUrl = providers.gradleProperty("pluginRepositoryUrl")
}

4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pluginGroup = com.example.css
pluginName = React Css Modules All
pluginRepositoryUrl = https://github.com/Q-Peppa/react-css-modules-all
# SemVer format -> https://semver.org
pluginVersion = 0.0.10
version = 0.0.10
pluginVersion = 0.0.11
version = 0.0.11


# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.ide.annotator

import com.example.ide.message.QCssMessageBundle
import com.example.ide.psi.CssModulesUnknownClassPsiReference
import com.example.ide.psi.isStyleIndex
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.Annotator
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.lang.javascript.psi.JSLiteralExpression
import com.intellij.psi.PsiElement
import org.jetbrains.annotations.NotNull

class CssModulesClassAnnotator : Annotator {
override fun annotate(@NotNull psiElement: PsiElement, @NotNull holder: AnnotationHolder) {
if (psiElement is JSLiteralExpression && isStyleIndex(psiElement)) {
val cssSelectorName = psiElement.stringValue?.trim().orEmpty()
val reference = psiElement.reference
if (reference is CssModulesUnknownClassPsiReference) {
val message = "${QCssMessageBundle.message("UnknownClassName")} \"$cssSelectorName\""
holder.newAnnotation(HighlightSeverity.WEAK_WARNING, message)
.range(psiElement)
.withFix(SimpleCssSelectorFix(cssSelectorName, reference.stylesheetFile))
.create()
}
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/com/example/ide/annotator/SimpleCssSelectorFix.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.ide.annotator

import com.example.ide.message.QCssMessageBundle
import com.intellij.codeInsight.intention.impl.BaseIntentionAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.TextEditor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile
import com.intellij.psi.css.CssElementFactory
import com.intellij.psi.css.StylesheetFile
import org.jetbrains.annotations.NotNull

class SimpleCssSelectorFix(private val key: String, private val stylesheetFile: StylesheetFile) :
BaseIntentionAction() {

override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?): Boolean = true

override fun getText(): String = "$familyName .$key"

override fun getFamilyName(): String = QCssMessageBundle.message("familyName")

override fun invoke(@NotNull project: Project, editor: Editor?, file: PsiFile?) {
if (editor == null || file == null) return
val ruleset = CssElementFactory.getInstance(project).createRuleset(
"\n.$key {\n\n}",
stylesheetFile.language
)
val afterRuleSet = stylesheetFile.add(ruleset)!!
stylesheetFile.navigate(true)
val offset = afterRuleSet.textOffset + ruleset.text.indexOf("{") + 2
FileEditorManager.getInstance(project).getEditors(stylesheetFile.virtualFile).forEach {
if (it is TextEditor) {
it.editor.caretModel.moveToOffset(offset)
}
}
}
}
Loading

0 comments on commit bf8e902

Please sign in to comment.