Skip to content

Commit

Permalink
Implement name validators for validating identifiers and keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
waleedyaseen committed Oct 9, 2024
1 parent bedc50e commit 81f5fe9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
### Fixed

- Fix project opening not working as expected in IntelliJ 2023 builds.
- Fix name validation when renaming symbols.

## Changed

- Do not apply spell checking inspection for RuneScript keywords.

## [1.6.0] - 2024-08-30

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.runescript.plugin.ide.refactoring

import com.intellij.lang.refactoring.NamesValidator
import com.intellij.openapi.project.Project
import io.runescript.plugin.ide.config.RsConfig

class RsNamesValidator : NamesValidator {
private val keywords = hashSetOf<String>(
"if",
"else",
"while",
"case",
"default",
"return",
"calc",
"return",
"true",
"false",
"null",
*RsConfig.getPrimitiveTypes().map { "def_$it" }.toTypedArray(),
*RsConfig.getPrimitiveTypes().map { "switch_$it" }.toTypedArray(),
*RsConfig.getPrimitiveTypes().map { "${it}array" }.toTypedArray(),
)

override fun isKeyword(name: String, project: Project?): Boolean {
return keywords.contains(name)
}

override fun isIdentifier(name: String, project: Project?): Boolean {
return name.matches(Regex("[a-zA-Z0-9_+.:]+"))
}
}
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@
<lang.findUsagesProvider language="RuneScriptSymbol" implementationClass="io.runescript.plugin.ide.usages.RsFindUsagesProvider"/>
<readWriteAccessDetector id="runescript" implementation="io.runescript.plugin.ide.usages.RsReadWriteAccessDetector"/>
<lang.refactoringSupport language="RuneScript" implementationClass="io.runescript.plugin.ide.refactoring.RsRefactoringSupportProvider"/>

<!-- Rename Handler -->
<renameHandler implementation="io.runescript.plugin.ide.refactoring.RsMemberInplaceRenameHandler"/>
<lang.namesValidator language="RuneScript" implementationClass="io.runescript.plugin.ide.refactoring.RsNamesValidator"/>
<lang.namesValidator language="RuneScriptSymbol" implementationClass="io.runescript.plugin.ide.refactoring.RsNamesValidator"/>

<lang.quoteHandler language="RuneScript" implementationClass="io.runescript.plugin.ide.RsQuoteHandler"/>
<lang.braceMatcher language="RuneScript" implementationClass="io.runescript.plugin.ide.RsBraceMatcher"/>
<lang.commenter language="RuneScript" implementationClass="io.runescript.plugin.ide.RsCommenter"/>
Expand Down

0 comments on commit 81f5fe9

Please sign in to comment.