Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jetbrains): jetbrains implementation #119

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion jetbrains/.run/Run Plugin.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="scriptParameters" value="--stacktrace" />
<option name="taskDescriptions">
<list />
</option>
Expand All @@ -19,6 +19,7 @@
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
3 changes: 2 additions & 1 deletion jetbrains/.run/Run Verifications.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="scriptParameters" value="--stacktrace" />
<option name="taskDescriptions">
<list />
</option>
Expand All @@ -19,6 +19,7 @@
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2">
<option name="Gradle.BeforeRunTask" enabled="true" tasks="clean" externalProjectPath="$PROJECT_DIR$" vmOptions="" scriptParameters="" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion jetbrains/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ fun environment(key: String) = providers.environmentVariable(key)
plugins {
id("java") // Java support
alias(libs.plugins.kotlin) // Kotlin support
alias(libs.plugins.gradleIntelliJPlugin) // Gradle IntelliJ Plugin
alias(libs.plugins.changelog) // Gradle Changelog Plugin
alias(libs.plugins.qodana) // Gradle Qodana Plugin
alias(libs.plugins.kover) // Gradle Kover Plugin
id("org.jetbrains.intellij") version "1.16.1"
}

group = properties("pluginGroup").get()
Expand Down
5 changes: 4 additions & 1 deletion jetbrains/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ pluginVersion=0.4.0
pluginSinceBuild=223
pluginUntilBuild=223.*
platformType=IU
platformVersion=2023.3
platformVersion=2023.3.2
platformPlugins=JavaScript
pluginVerifierIdeVersions=IU-2022.3
gradleVersion=7.5.1
kotlin.stdlib.default.dependency = false
jvmVersion=17

# Enable Gradle Kotlin DSL Lazy Property Assignment -> https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:assignment
systemProp.org.gradle.unsafe.kotlin.assignment = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.michaelangeloio.plugins.dit

import com.intellij.DynamicBundle
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.PropertyKey

@NonNls
private const val BUNDLE = "messages.DoesItThrowBundle"

object DoesItThrowBundle : DynamicBundle(BUNDLE) {

@Suppress("SpreadOperator")
@JvmStatic
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getMessage(key, *params)

@Suppress("SpreadOperator", "unused")
@JvmStatic
fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getLazyMessage(key, *params)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,48 @@ import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterManager
import com.intellij.javascript.nodejs.interpreter.local.NodeJsLocalInterpreter
import com.intellij.javascript.nodejs.interpreter.wsl.WslNodeInterpreter
import com.intellij.lang.javascript.service.JSLanguageServiceUtil
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.platform.lsp.api.ProjectWideLspServerDescriptor
import org.eclipse.lsp4j.*
import org.michaelangeloio.plugins.dit.DoesItThrowUtils
import org.michaelangeloio.plugins.dit.settings.DoesItThrowSettings

private val LOG = logger<DoesItThrowLspServerDescriptor>()

class DoesItThrowLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(project, "Does it Throw?") {
override val clientCapabilities: ClientCapabilities = super.clientCapabilities.apply {
textDocument = TextDocumentClientCapabilities().apply {
publishDiagnostics = PublishDiagnosticsCapabilities().apply {
versionSupport = true
}
hover = HoverCapabilities().apply {
contentFormat = listOf(MarkupKind.MARKDOWN, MarkupKind.PLAINTEXT)
}
}
workspace = workspace?.apply {
configuration = true
workspaceFolders = true
didChangeWatchedFiles = DidChangeWatchedFilesCapabilities().apply {
relativePatternSupport = true
}
}
}

override fun getWorkspaceConfiguration(item: ConfigurationItem): Any {
LOG.info(item.scopeUri)
return mapOf(
"throwStatementSeverity" to DoesItThrowSettings.getInstance(project).throwStatementSeverity,
"functionThrowSeverity" to DoesItThrowSettings.getInstance(project).functionThrowSeverity,
"callToThrowSeverity" to DoesItThrowSettings.getInstance(project).callToThrowSeverity,
"callToImportedThrowSeverity" to DoesItThrowSettings.getInstance(project).callToImportedThrowSeverity,
"includeTryStatementThrows" to DoesItThrowSettings.getInstance(project).includeTryStatementThrows,
"maxNumberOfProblems" to DoesItThrowSettings.getInstance(project).maxNumberOfProblems,
"ignoreStatements" to DoesItThrowSettings.getInstance(project).ignoreStatements
)
}
override fun isSupportedFile(file: VirtualFile) = DoesItThrowUtils.isSupportedFileType(file)

override fun createCommandLine(): GeneralCommandLine {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.michaelangeloio.plugins.dit.services

import com.intellij.notification.NotificationGroupManager
import com.intellij.notification.NotificationType
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import com.intellij.platform.lsp.api.LspServerManager
import org.michaelangeloio.plugins.dit.DoesItThrowBundle
import org.michaelangeloio.plugins.dit.lsp.DoesItThrowLspServerSupportProvider

@Service(Service.Level.PROJECT)
class DoesItThrowServerService(private val project: Project) {

fun restartDoesItThrowServer() {
LspServerManager.getInstance(project).stopAndRestartIfNeeded(DoesItThrowLspServerSupportProvider::class.java)
}

fun notifyRestart() {
NotificationGroupManager.getInstance()
.getNotificationGroup("DoesItThrow")
.createNotification(
DoesItThrowBundle.message("does-it-throw.language.server.restarted"),
"",
NotificationType.INFORMATION
)
.notify(project)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.michaelangeloio.plugins.dit.settings

import com.intellij.openapi.components.service
import com.intellij.openapi.options.BoundSearchableConfigurable
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.dsl.builder.*
import org.michaelangeloio.plugins.dit.DoesItThrowBundle
import org.michaelangeloio.plugins.dit.services.DoesItThrowServerService

class DoesItThrowSettingsConfigurable(private val project: Project) :
BoundSearchableConfigurable(
DoesItThrowBundle.message("does-it-throw.settings.name"),
DoesItThrowBundle.message("does-it-throw.settings.name")
) {
private val settings: DoesItThrowSettings = DoesItThrowSettings.getInstance(project)
private val doesItThrowServerService = project.service<DoesItThrowServerService>()

override fun createPanel(): DialogPanel = panel {


row(DoesItThrowBundle.message("does-it-throw.settings.includeTryStatementThrows.label")) {
checkBox("").bindSelected(settings::includeTryStatementThrows)
}

row(DoesItThrowBundle.message("does-it-throw.settings.maxNumberOfProblems.label")) {
textField().bindIntText(settings::maxNumberOfProblems)
}

row("Ignore Statements:") {
val textArea = textArea().bindText(
getter = { settings.ignoreStatements.joinToString("\n") },
setter = { text -> settings.ignoreStatements = text.split("\n").filter { it.isNotBlank() } }
)
textArea.rows(10) // Sets the number of visible rows in the text area.
}

group("Severity Configuration") {
row{
label("Allowed Values: Information, Hint, Warning, Error")
}
row(DoesItThrowBundle.message("does-it-throw.settings.throwStatementSeverity.label")) {
textField().bindText(settings::throwStatementSeverity)
}
row (DoesItThrowBundle.message("does-it-throw.settings.functionThrowSeverity.label")) {
textField().bindText(settings::functionThrowSeverity)
}
row (DoesItThrowBundle.message("does-it-throw.settings.callToThrowSeverity.label")) {
textField().bindText(settings::callToThrowSeverity)
}
row (DoesItThrowBundle.message("does-it-throw.settings.callToImportedThrowSeverity.label")) {
textField().bindText(settings::callToImportedThrowSeverity)
}
}

onApply {
doesItThrowServerService.restartDoesItThrowServer()
doesItThrowServerService.notifyRestart()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.michaelangeloio.plugins.dit.settings

import com.intellij.openapi.components.*
import com.intellij.openapi.project.Project

@Service(Service.Level.PROJECT)
@State(name = "DoesItThrowSettings", storages = [(Storage("does-it-throw.xml"))])
class DoesItThrowSettings :
SimplePersistentStateComponent<DoesItThrowSettingsState>(DoesItThrowSettingsState()) {

var throwStatementSeverity: String
get() = state.throwStatementSeverity ?: "Hint"
set(value) {
state.throwStatementSeverity = value
}

var functionThrowSeverity: String
get() = state.functionThrowSeverity ?: "Hint"
set(value) {
state.functionThrowSeverity = value
}
var callToThrowSeverity: String
get() = state.callToThrowSeverity ?: "Hint"
set(value) {
state.callToThrowSeverity = value
}
var callToImportedThrowSeverity: String
get() = state.callToImportedThrowSeverity ?: "Hint"
set(value) {
state.callToImportedThrowSeverity = value
}
var includeTryStatementThrows: Boolean
get() = state.includeTryStatementThrows ?: false
set(value) {
state.includeTryStatementThrows = value
}
var maxNumberOfProblems: Int
get() = state.maxNumberOfProblems ?: 1000
set(value) {
state.maxNumberOfProblems = value
}
var ignoreStatements: List<String>
get() = state.ignoreStatements ?: listOf(
"@it-throws",
"@does-it-throw-ignore"
)
set(value) {
state.ignoreStatements = value
}

companion object {
@JvmStatic
fun getInstance(project: Project): DoesItThrowSettings = project.service()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.michaelangeloio.plugins.dit.settings

import com.intellij.openapi.components.BaseState
import com.intellij.openapi.components.Service
import org.jetbrains.annotations.ApiStatus

@Service
@ApiStatus.Internal
class DoesItThrowSettingsState : BaseState() {
var throwStatementSeverity by string("Hint")
var functionThrowSeverity by string("Hint")
var callToThrowSeverity by string("Hint")
var callToImportedThrowSeverity by string("Hint")
var includeTryStatementThrows by property(false)
var maxNumberOfProblems by property(1000)
var ignoreStatements = listOf(
"@it-throws",
"@does-it-throw-ignore"
)
}
13 changes: 11 additions & 2 deletions jetbrains/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.ultimate</depends>
<depends>JavaScript</depends>


<resource-bundle>messages.DoesItThrowBundle</resource-bundle>

<id>org.michaelangeloio.plugins.dit</id>
<name>Does it Throw?</name>
<vendor>michaelangeloio</vendor>

<resource-bundle>messages.MyBundle</resource-bundle>

<extensions defaultExtensionNs="com.intellij">
<notificationGroup id="DoesItThrow" displayType="BALLOON"/>
<!-- LSP -->
<platform.lsp.serverSupportProvider implementation="org.michaelangeloio.plugins.dit.lsp.DoesItThrowLspServerSupportProvider"/>

<projectConfigurable id="Settings.DoesItThrowB"
bundle="messages.DoesItThrowBundle"
groupId="language"
nonDefaultProject="false"
key="does-it-throw.settings.name"
instance="org.michaelangeloio.plugins.dit.settings.DoesItThrowSettingsConfigurable"/>
</extensions>

</idea-plugin>
11 changes: 11 additions & 0 deletions jetbrains/src/main/resources/messages/DoesItThrowBundle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name=Does It Throw?
does-it-throw.settings.name = Does It Throw Settings

does-it-throw.settings.throwStatementSeverity.label = Throw Statement Severity
does-it-throw.settings.functionThrowSeverity.label = Function Throw Severity
does-it-throw.settings.callToThrowSeverity.label = Call to Throw Severity
does-it-throw.settings.callToImportedThrowSeverity.label = Call to Imported Throw Severity
does-it-throw.settings.includeTryStatementThrows.label = Include Try Statement Throws
does-it-throw.settings.maxNumberOfProblems.label = Max Number of Problems
does-it-throw.settings.ignoreStatements.label = Ignore Statements
does-it-throw.language.server.restarted=Does it Throw? server restarted
Loading