Skip to content

Commit

Permalink
magic meta model
Browse files Browse the repository at this point in the history
* no targets test

* DocumentIdToTargetsIdsMapDelegate impl

* blackbox testing

* magic model -> magic meta model

* directry sources support

* test

* should map multiple files in multiple directories to multiple targets including file based targets test

* file based sources tests refactor

* directory based sources tests refactor

* file and directory based sources tests refactor

* URI toAbsolutePath extension

* targets parameter

* DocumentTargetsDetails introduction

* TargetsDetailsForDocumentProvider

* test rename

* TargetsDetailsForDocumentProvider internal

* TargetsDetailsForDocument extraction

* OverlappingTargetsGraphDelegate init

* OverlappingTargetsGraph impl

* TargetsDetailsForDocumentProviderGetTargetsDetailsForDocumentTest name update

* display names in tests

* targetsDetailsForDocumentProvider.getAllDocumentsTest() tests

* interface extraction

* code reformat

* interface update

* NonOverlappingTargetsDelegate impl

* interface update

* WorkspaceModelTestMockImpl init

* tests fix

* WorkspaceEntityStorageBuilderTestMockImpl update

* interface update

* .targets removal

* getAllLoadedTargets, getAllNotLoadedTargets, loadDefaultTargets tests

* .loadTarget

* .loadDefaultTargets update

* .getTargetsDetailsForDocument

* little up

* .create()

* visibility update

* real flow tests

* .reduceSets() extension

* javadoc

* readme

* new lines v1

* MagicMetaModel

* readme

* MagicMetaModelImpl

* NonOverlappingTargetsDelegate

* OverlappingTargetsGraph

* TargetsDetailsForDocument

* tests

* linter

* changelog update

* imports

* gradle cleanup

* linter

* fixxx

* pluginnnn

* github action update
  • Loading branch information
abrams27 committed Aug 9, 2022
1 parent 69df4dd commit f5678ed
Show file tree
Hide file tree
Showing 38 changed files with 3,049 additions and 190 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*]
indent_style=space
indent_size=2
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ jobs:
run: ./gradlew check

# Run verifyPlugin Gradle task
- name: Verify Plugin
run: ./gradlew verifyPlugin
# - name: Verify Plugin
# run: ./gradlew verifyPlugin

# Build plugin with buildPlugin Gradle task and provide the artifact for the next workflow jobs
# Requires test job to be passed
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

## [Unreleased]
### Added
- Initial scaffold created from [IntelliJ Platform Plugin Template](https://github.com/JetBrains/intellij-platform-plugin-template)
- [Magic Meta Model](https://github.com/Abrams27/intellij-bsp/pull/1)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Build Server Protocol for IntelliJ IDEA

<!-- Plugin description -->
Build Server Protocol

!! WORK IN PROGRESS !!

!! WORK IN PROGRESS !!
<!-- Plugin description end -->
189 changes: 115 additions & 74 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,110 +5,151 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
fun properties(key: String) = project.findProperty(key).toString()

plugins {
// Java support
id("java")
// Kotlin support
id("org.jetbrains.kotlin.jvm") version "1.5.10"
// gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
id("org.jetbrains.intellij") version "1.0"
// gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
id("org.jetbrains.changelog") version "1.1.2"
// detekt linter - read more: https://detekt.github.io/detekt/gradle.html
id("io.gitlab.arturbosch.detekt") version "1.17.1"
// ktlint linter - read more: https://github.com/JLLeitschuh/ktlint-gradle
id("org.jlleitschuh.gradle.ktlint") version "10.0.0"
// Java support
id("java")
// Kotlin support
id("org.jetbrains.kotlin.jvm") version "1.5.10"
// gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
id("org.jetbrains.intellij") version "1.0"
// gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
id("org.jetbrains.changelog") version "1.1.2"
// detekt linter - read more: https://detekt.github.io/detekt/gradle.html
id("io.gitlab.arturbosch.detekt") version "1.18.1"
// ktlint linter - read more: https://github.com/JLLeitschuh/ktlint-gradle
id("org.jlleitschuh.gradle.ktlint") version "10.2.0"
}

group = properties("pluginGroup")
version = properties("pluginVersion")

// Configure project's dependencies
repositories {
mavenCentral()
mavenCentral()
}
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.17.1")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.17.1")
}

// Configure gradle-intellij-plugin plugin.
// Read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij {
pluginName.set(properties("pluginName"))
version.set(properties("platformVersion"))
type.set(properties("platformType"))
downloadSources.set(properties("platformDownloadSources").toBoolean())
updateSinceUntilBuild.set(true)

// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
pluginName.set(properties("pluginName"))
version.set(properties("platformVersion"))
type.set(properties("platformType"))
downloadSources.set(properties("platformDownloadSources").toBoolean())
updateSinceUntilBuild.set(true)

// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
}

// Configure gradle-changelog-plugin plugin.
// Read more: https://github.com/JetBrains/gradle-changelog-plugin
changelog {
version = properties("pluginVersion")
groups = emptyList()
version = properties("pluginVersion")
groups = emptyList()
}

// Configure detekt plugin.
// Read more: https://detekt.github.io/detekt/kotlindsl.html
detekt {
config = files("./detekt-config.yml")
buildUponDefaultConfig = true

reports {
html.enabled = false
xml.enabled = false
txt.enabled = false
}
config = files("./detekt-config.yml")
buildUponDefaultConfig = true

reports {
html.enabled = false
xml.enabled = false
txt.enabled = false
}
}

tasks {
// Set the compatibility versions to 1.8
withType<JavaCompile> {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
// Set the compatibility versions to 1.8
withType<JavaCompile> {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

withType<Detekt> {
jvmTarget = "1.8"
}

patchPluginXml {
version.set(properties("pluginVersion"))
sinceBuild.set(properties("pluginSinceBuild"))
untilBuild.set(properties("pluginUntilBuild"))

// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
pluginDescription.set(
File(projectDir, "README.md").readText().lines().run {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"

if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
subList(indexOf(start) + 1, indexOf(end))
}.joinToString("\n").run { markdownToHTML(this) }
)

// Get the latest available change notes from the changelog file
changeNotes.set(provider { changelog.getLatest().toHTML() })
}

runPluginVerifier {
ideVersions.set(properties("pluginVerifierIdeVersions").split(',').map(String::trim).filter(String::isNotEmpty))
}

publishPlugin {
dependsOn("patchChangelog")
token.set(System.getenv("PUBLISH_TOKEN"))
// pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
// Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
// https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel
channels.set(listOf(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').first()))
}
}

withType<Detekt> {
jvmTarget = "1.8"
}
val projectRoot = projectDir

patchPluginXml {
version.set(properties("pluginVersion"))
sinceBuild.set(properties("pluginSinceBuild"))
untilBuild.set(properties("pluginUntilBuild"))

// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
pluginDescription.set(
File(projectDir, "README.md").readText().lines().run {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"

if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
subList(indexOf(start) + 1, indexOf(end))
}.joinToString("\n").run { markdownToHTML(this) }
)

// Get the latest available change notes from the changelog file
changeNotes.set(provider { changelog.getLatest().toHTML() })
}
subprojects {

runPluginVerifier {
ideVersions.set(properties("pluginVerifierIdeVersions").split(',').map(String::trim).filter(String::isNotEmpty))
}
apply(plugin = "java")
apply(plugin = "org.jetbrains.intellij")
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "io.gitlab.arturbosch.detekt")
apply(plugin = "org.jlleitschuh.gradle.ktlint")

group = properties("pluginGroup")
version = properties("pluginVersion")

repositories {
mavenCentral()
}

tasks.test {
useJUnitPlatform()
}

publishPlugin {
dependsOn("patchChangelog")
token.set(System.getenv("PUBLISH_TOKEN"))
// pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
// Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
// https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel
channels.set(listOf(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').first()))
detekt {
config = files("$projectRoot/detekt-config.yml")
buildUponDefaultConfig = true

reports {
html.enabled = false
xml.enabled = false
txt.enabled = false
}
}

dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.17.1")
implementation("ch.epfl.scala:bsp4j:2.0.0-M15")

testImplementation(kotlin("test"))
testImplementation("io.kotest:kotest-assertions-core:4.6.2")
}
}
4 changes: 1 addition & 3 deletions detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
# https://github.com/detekt/detekt/blob/master/detekt-core/src/main/resources/default-detekt-config.yml

formatting:
Indentation:
continuationIndentSize: 8
ParameterListWrapping:
indentSize: 8
indentSize: 2
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# IntelliJ Platform Artifacts Repositories
# -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html

pluginGroup = com.github.abrams27.intellijbsp
pluginGroup = org.jetbrains
pluginName = intellij-bsp
pluginVersion = 0.0.1

Expand Down
3 changes: 3 additions & 0 deletions magicmetamodel/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kotlin {
explicitApi()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.jetbrains.magicmetamodel

import ch.epfl.scala.bsp4j.BuildTarget
import ch.epfl.scala.bsp4j.BuildTargetIdentifier
import ch.epfl.scala.bsp4j.SourcesItem
import ch.epfl.scala.bsp4j.TextDocumentIdentifier
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.diagnostic.logger
import com.intellij.workspaceModel.ide.WorkspaceModel
import org.jetbrains.magicmetamodel.impl.MagicMetaModelImpl

/**
* Contains information about loaded target and not loaded targets for given document.
*
* @see [MagicMetaModel.getTargetsDetailsForDocument]
*/
public data class DocumentTargetsDetails(
public val loadedTargetId: BuildTargetIdentifier?,
public val notLoadedTargetsIds: List<BuildTargetIdentifier>,
)

/**
* Provides operations on model entries.
*
* The main reason for its existence is the integration of the model obtained from
* the BSP containing shared sources and [WorkspaceModel].
*/
public interface MagicMetaModel {

/**
* Loads default targets to the model - can be all targets, can be subset of them.
*
* If the project contains shared sources, the loaded targets should not share sources.
* For example, if there are :target1 and :target2 that have the same sources, *only one of them* could be loaded.
*
* Requires write action if used with [WorkspaceModel].
*/
public fun loadDefaultTargets()

/**
* Loads given target.
*
* If the project contains shared sources, all "overlapping" targets should be unloaded.
* For example, if there are :target1 and :target2 that have the same sources,
* and :target1 is currently loaded and :target2 is loaded then after this call *:target1 should no longer be loaded*.
*
* Requires write action if used with [WorkspaceModel].
*/
public fun loadTarget(targetId: BuildTargetIdentifier)

/**
* Get targets details for given document.
*
* The response contains a loaded target that contains the document,
* or null if no loaded target contains the document.
* The response also contains unloaded targets that contain the document.
*/
public fun getTargetsDetailsForDocument(documentId: TextDocumentIdentifier): DocumentTargetsDetails

/**
* Get all currently loaded targets.
*/
public fun getAllLoadedTargets(): List<BuildTarget>

/**
* Get all currently not loaded targets.
*/
public fun getAllNotLoadedTargets(): List<BuildTarget>

public companion object {
private val LOGGER = logger<MagicMetaModel>()

/**
* Create instance of [MagicMetaModelImpl] which supports shared sources
* provided by the BSP and works on top of [WorkspaceModel].
*/
public fun create(
workspaceModel: WorkspaceModel,
targets: List<BuildTarget>,
sources: List<SourcesItem>,
): MagicMetaModel {
LOGGER.debug { "Creating MagicMetaModelImpl for $workspaceModel, $targets. $sources..." }
return MagicMetaModelImpl(workspaceModel, targets, sources)
}
}
}
Loading

0 comments on commit f5678ed

Please sign in to comment.