Skip to content

Commit c93034e

Browse files
vepanimasintellij-monorepo-bot
authored andcommitted
Reapply "[graphql] WEB-64772 migrate libraries to a new project model"
This reverts commit f33998d664b2725d1e0890a21e6d90fac96e2645. GitOrigin-RevId: 98c7320d856ac3eabf0ed839305e7e710a057b7c
1 parent 356c50b commit c93034e

File tree

40 files changed

+932
-431
lines changed

40 files changed

+932
-431
lines changed

intellij.graphql.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
77
<sourceFolder url="file://$MODULE_DIR$/src/main" isTestSource="false" />
88
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/gen" isTestSource="false" generated="true" />
910
<excludeFolder url="file://$MODULE_DIR$/build" />
1011
</content>
1112
<orderEntry type="inheritedJdk" />

javascript/src/com/intellij/graphql/javascript/workspace/GraphQLNodeModulesIndexContributor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class GraphQLNodeModulesIndexContributor : WorkspaceFileIndexContributor<GraphQL
1111

1212
override fun registerFileSets(entity: GraphQLNodeModulesEntity, registrar: WorkspaceFileSetRegistrar, storage: EntityStorage) {
1313
entity.roots.forEach {
14-
registrar.registerFileSet(it, WorkspaceFileKind.EXTERNAL_SOURCE, entity, GraphQLSourceRootFileSetData())
14+
registrar.registerFileSet(it, WorkspaceFileKind.EXTERNAL_SOURCE, entity, GraphQLNodeModulesSourceRootData())
1515
}
1616
}
1717
}

javascript/src/com/intellij/graphql/javascript/workspace/GraphQLNodeModulesLibraryUpdater.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.intellij.lang.jsgraphql.ide.config.model.GraphQLSchemaPointer
66
import com.intellij.openapi.application.ApplicationManager
77
import com.intellij.openapi.components.Service
88
import com.intellij.openapi.components.service
9+
import com.intellij.openapi.components.serviceAsync
910
import com.intellij.openapi.project.Project
1011
import com.intellij.openapi.vfs.VfsUtil
1112
import com.intellij.openapi.vfs.VirtualFileManager
@@ -23,12 +24,10 @@ class GraphQLNodeModulesLibraryUpdater(private val project: Project, @VisibleFor
2324
private val lock = ReentrantLock()
2425
private val roots = mutableSetOf<String>() // lock
2526

26-
private val configProvider = GraphQLConfigProvider.getInstance(project)
27-
2827
fun updateNodeModulesEntity() {
2928
cs.launch {
3029
val prevRoots = lock.withLock { roots.toSet() }
31-
val newRoots = configProvider.getAllConfigs(true)
30+
val newRoots = GraphQLConfigProvider.getInstance(project).getAllConfigs(true)
3231
.asSequence()
3332
.flatMap { it.getProjects().values }
3433
.flatMap { config ->
@@ -58,13 +57,14 @@ class GraphQLNodeModulesLibraryUpdater(private val project: Project, @VisibleFor
5857
}
5958

6059
private suspend fun attachEntity(roots: Collection<String>) {
61-
val virtualFileUrlManager = WorkspaceModel.getInstance(project).getVirtualFileUrlManager()
60+
val workspaceModel = project.serviceAsync<WorkspaceModel>()
61+
val virtualFileUrlManager = workspaceModel.getVirtualFileUrlManager()
6262
val rootUrls = roots.mapTo(mutableSetOf()) { virtualFileUrlManager.getOrCreateFromUrl(it) }
6363
val newModulesEntity = GraphQLNodeModulesEntity(rootUrls, GraphQLNodeModulesEntitySource)
6464
val entityStorage = MutableEntityStorage.create().apply {
6565
addEntity(newModulesEntity)
6666
}
67-
WorkspaceModel.getInstance(project).update("Attach GraphQL node modules") { storage ->
67+
workspaceModel.update("Attach GraphQL node modules") { storage ->
6868
storage.replaceBySource({ it is GraphQLNodeModulesEntitySource }, entityStorage)
6969
}
7070
}

javascript/src/com/intellij/graphql/javascript/workspace/GraphQLSourceRootFileSetData.kt renamed to javascript/src/com/intellij/graphql/javascript/workspace/GraphQLNodeModulesSourceRootData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ package com.intellij.graphql.javascript.workspace
22

33
import com.intellij.workspaceModel.core.fileIndex.impl.ModuleOrLibrarySourceRootData
44

5-
internal class GraphQLSourceRootFileSetData : ModuleOrLibrarySourceRootData
5+
internal class GraphQLNodeModulesSourceRootData : ModuleOrLibrarySourceRootData

resources/META-INF/plugin.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@
105105
<fileBasedIndex implementation="com.intellij.lang.jsgraphql.ide.indexing.GraphQLFragmentNameIndex"/>
106106
<fileBasedIndex implementation="com.intellij.lang.jsgraphql.ide.indexing.GraphQLInjectionIndex"/>
107107

108+
<workspaceModel.fileIndexContributor implementation="com.intellij.lang.jsgraphql.schema.library.GraphQLLibraryIndexContributor"/>
109+
<projectView.externalLibraries.workspaceModelNodesProvider
110+
implementation="com.intellij.lang.jsgraphql.schema.library.GraphQLLibraryWorkspaceModelNodesProvider"/>
111+
108112
<indexedRootsProvider
109113
implementation="com.intellij.lang.jsgraphql.ide.introspection.indexing.GraphQLIntrospectionIndexableSetContributor"/>
110-
<additionalLibraryRootsProvider implementation="com.intellij.lang.jsgraphql.schema.library.GraphQLLibraryRootsProvider"/>
111114

112115
<!-- Startup -->
113116
<postStartupActivity implementation="com.intellij.lang.jsgraphql.ide.startup.GraphQLStartupActivity"/>

resources/messages/GraphQLBundle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ graphql.settings.introspection=Introspection
179179
graphql.settings.introspection.open.editor.label=Open introspection results in the editor
180180

181181
# Libraries
182-
graphql.library.prefix=GraphQL:
182+
graphql.library.prefix=GraphQL: {0}
183183
graphql.library.built.in=Specification
184184
graphql.library.relay=Relay
185185
graphql.library.federation=Federation
Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
package com.intellij.lang.jsgraphql.schema.library.impl
2+
3+
import com.intellij.lang.jsgraphql.schema.library.GraphQLLibraryEntity
4+
import com.intellij.platform.workspace.storage.ConnectionId
5+
import com.intellij.platform.workspace.storage.EntitySource
6+
import com.intellij.platform.workspace.storage.EntityType
7+
import com.intellij.platform.workspace.storage.GeneratedCodeApiVersion
8+
import com.intellij.platform.workspace.storage.GeneratedCodeImplVersion
9+
import com.intellij.platform.workspace.storage.MutableEntityStorage
10+
import com.intellij.platform.workspace.storage.WorkspaceEntity
11+
import com.intellij.platform.workspace.storage.WorkspaceEntityInternalApi
12+
import com.intellij.platform.workspace.storage.impl.ModifiableWorkspaceEntityBase
13+
import com.intellij.platform.workspace.storage.impl.WorkspaceEntityBase
14+
import com.intellij.platform.workspace.storage.impl.WorkspaceEntityData
15+
import com.intellij.platform.workspace.storage.impl.containers.MutableWorkspaceSet
16+
import com.intellij.platform.workspace.storage.impl.containers.toMutableWorkspaceSet
17+
import com.intellij.platform.workspace.storage.instrumentation.EntityStorageInstrumentation
18+
import com.intellij.platform.workspace.storage.instrumentation.EntityStorageInstrumentationApi
19+
import com.intellij.platform.workspace.storage.metadata.model.EntityMetadata
20+
import com.intellij.platform.workspace.storage.url.VirtualFileUrl
21+
import org.jetbrains.annotations.Nls
22+
import org.jetbrains.annotations.NonNls
23+
24+
@GeneratedCodeApiVersion(3)
25+
@GeneratedCodeImplVersion(6)
26+
@OptIn(WorkspaceEntityInternalApi::class)
27+
internal class GraphQLLibraryEntityImpl(private val dataSource: GraphQLLibraryEntityData) : GraphQLLibraryEntity, WorkspaceEntityBase(
28+
dataSource) {
29+
30+
private companion object {
31+
32+
33+
private val connections = listOf<ConnectionId>(
34+
)
35+
36+
}
37+
38+
override val identifier: String
39+
get() {
40+
readField("identifier")
41+
return dataSource.identifier
42+
}
43+
44+
override val displayName: String
45+
get() {
46+
readField("displayName")
47+
return dataSource.displayName
48+
}
49+
50+
override val description: String?
51+
get() {
52+
readField("description")
53+
return dataSource.description
54+
}
55+
56+
override val roots: Set<VirtualFileUrl>
57+
get() {
58+
readField("roots")
59+
return dataSource.roots
60+
}
61+
62+
override val entitySource: EntitySource
63+
get() {
64+
readField("entitySource")
65+
return dataSource.entitySource
66+
}
67+
68+
override fun connectionIdList(): List<ConnectionId> {
69+
return connections
70+
}
71+
72+
73+
internal class Builder(result: GraphQLLibraryEntityData?) : ModifiableWorkspaceEntityBase<GraphQLLibraryEntity, GraphQLLibraryEntityData>(
74+
result), GraphQLLibraryEntity.Builder {
75+
internal constructor() : this(GraphQLLibraryEntityData())
76+
77+
override fun applyToBuilder(builder: MutableEntityStorage) {
78+
if (this.diff != null) {
79+
if (existsInBuilder(builder)) {
80+
this.diff = builder
81+
return
82+
}
83+
else {
84+
error("Entity GraphQLLibraryEntity is already created in a different builder")
85+
}
86+
}
87+
88+
this.diff = builder
89+
addToBuilder()
90+
this.id = getEntityData().createEntityId()
91+
// After adding entity data to the builder, we need to unbind it and move the control over entity data to builder
92+
// Builder may switch to snapshot at any moment and lock entity data to modification
93+
this.currentEntityData = null
94+
95+
index(this, "roots", this.roots)
96+
// Process linked entities that are connected without a builder
97+
processLinkedEntities(builder)
98+
checkInitialization() // TODO uncomment and check failed tests
99+
}
100+
101+
private fun checkInitialization() {
102+
val _diff = diff
103+
if (!getEntityData().isEntitySourceInitialized()) {
104+
error("Field WorkspaceEntity#entitySource should be initialized")
105+
}
106+
if (!getEntityData().isIdentifierInitialized()) {
107+
error("Field GraphQLLibraryEntity#identifier should be initialized")
108+
}
109+
if (!getEntityData().isDisplayNameInitialized()) {
110+
error("Field GraphQLLibraryEntity#displayName should be initialized")
111+
}
112+
if (!getEntityData().isRootsInitialized()) {
113+
error("Field GraphQLLibraryEntity#roots should be initialized")
114+
}
115+
}
116+
117+
override fun connectionIdList(): List<ConnectionId> {
118+
return connections
119+
}
120+
121+
override fun afterModification() {
122+
val collection_roots = getEntityData().roots
123+
if (collection_roots is MutableWorkspaceSet<*>) {
124+
collection_roots.cleanModificationUpdateAction()
125+
}
126+
}
127+
128+
// Relabeling code, move information from dataSource to this builder
129+
override fun relabel(dataSource: WorkspaceEntity, parents: Set<WorkspaceEntity>?) {
130+
dataSource as GraphQLLibraryEntity
131+
if (this.entitySource != dataSource.entitySource) this.entitySource = dataSource.entitySource
132+
if (this.identifier != dataSource.identifier) this.identifier = dataSource.identifier
133+
if (this.displayName != dataSource.displayName) this.displayName = dataSource.displayName
134+
if (this.description != dataSource?.description) this.description = dataSource.description
135+
if (this.roots != dataSource.roots) this.roots = dataSource.roots.toMutableSet()
136+
updateChildToParentReferences(parents)
137+
}
138+
139+
140+
override var entitySource: EntitySource
141+
get() = getEntityData().entitySource
142+
set(value) {
143+
checkModificationAllowed()
144+
getEntityData(true).entitySource = value
145+
changedProperty.add("entitySource")
146+
147+
}
148+
149+
override var identifier: String
150+
get() = getEntityData().identifier
151+
set(value) {
152+
checkModificationAllowed()
153+
getEntityData(true).identifier = value
154+
changedProperty.add("identifier")
155+
}
156+
157+
override var displayName: String
158+
get() = getEntityData().displayName
159+
set(value) {
160+
checkModificationAllowed()
161+
getEntityData(true).displayName = value
162+
changedProperty.add("displayName")
163+
}
164+
165+
override var description: String?
166+
get() = getEntityData().description
167+
set(value) {
168+
checkModificationAllowed()
169+
getEntityData(true).description = value
170+
changedProperty.add("description")
171+
}
172+
173+
private val rootsUpdater: (value: Set<VirtualFileUrl>) -> Unit = { value ->
174+
val _diff = diff
175+
if (_diff != null) index(this, "roots", value)
176+
changedProperty.add("roots")
177+
}
178+
override var roots: MutableSet<VirtualFileUrl>
179+
get() {
180+
val collection_roots = getEntityData().roots
181+
if (collection_roots !is MutableWorkspaceSet) return collection_roots
182+
if (diff == null || modifiable.get()) {
183+
collection_roots.setModificationUpdateAction(rootsUpdater)
184+
}
185+
else {
186+
collection_roots.cleanModificationUpdateAction()
187+
}
188+
return collection_roots
189+
}
190+
set(value) {
191+
checkModificationAllowed()
192+
getEntityData(true).roots = value
193+
rootsUpdater.invoke(value)
194+
}
195+
196+
override fun getEntityClass(): Class<GraphQLLibraryEntity> = GraphQLLibraryEntity::class.java
197+
}
198+
}
199+
200+
@OptIn(WorkspaceEntityInternalApi::class)
201+
internal class GraphQLLibraryEntityData : WorkspaceEntityData<GraphQLLibraryEntity>() {
202+
lateinit var identifier: String
203+
lateinit var displayName: String
204+
var description: String? = null
205+
lateinit var roots: MutableSet<VirtualFileUrl>
206+
207+
internal fun isIdentifierInitialized(): Boolean = ::identifier.isInitialized
208+
internal fun isDisplayNameInitialized(): Boolean = ::displayName.isInitialized
209+
internal fun isRootsInitialized(): Boolean = ::roots.isInitialized
210+
211+
override fun wrapAsModifiable(diff: MutableEntityStorage): WorkspaceEntity.Builder<GraphQLLibraryEntity> {
212+
val modifiable = GraphQLLibraryEntityImpl.Builder(null)
213+
modifiable.diff = diff
214+
modifiable.id = createEntityId()
215+
return modifiable
216+
}
217+
218+
@OptIn(EntityStorageInstrumentationApi::class)
219+
override fun createEntity(snapshot: EntityStorageInstrumentation): GraphQLLibraryEntity {
220+
val entityId = createEntityId()
221+
return snapshot.initializeEntity(entityId) {
222+
val entity = GraphQLLibraryEntityImpl(this)
223+
entity.snapshot = snapshot
224+
entity.id = entityId
225+
entity
226+
}
227+
}
228+
229+
override fun getMetadata(): EntityMetadata {
230+
return MetadataStorageImpl.getMetadataByTypeFqn("com.intellij.lang.jsgraphql.schema.library.GraphQLLibraryEntity") as EntityMetadata
231+
}
232+
233+
override fun clone(): GraphQLLibraryEntityData {
234+
val clonedEntity = super.clone()
235+
clonedEntity as GraphQLLibraryEntityData
236+
clonedEntity.roots = clonedEntity.roots.toMutableWorkspaceSet()
237+
return clonedEntity
238+
}
239+
240+
override fun getEntityInterface(): Class<out WorkspaceEntity> {
241+
return GraphQLLibraryEntity::class.java
242+
}
243+
244+
override fun createDetachedEntity(parents: List<WorkspaceEntity.Builder<*>>): WorkspaceEntity.Builder<*> {
245+
return GraphQLLibraryEntity(identifier, displayName, roots, entitySource) {
246+
this.description = this@GraphQLLibraryEntityData.description
247+
}
248+
}
249+
250+
override fun getRequiredParents(): List<Class<out WorkspaceEntity>> {
251+
val res = mutableListOf<Class<out WorkspaceEntity>>()
252+
return res
253+
}
254+
255+
override fun equals(other: Any?): Boolean {
256+
if (other == null) return false
257+
if (this.javaClass != other.javaClass) return false
258+
259+
other as GraphQLLibraryEntityData
260+
261+
if (this.entitySource != other.entitySource) return false
262+
if (this.identifier != other.identifier) return false
263+
if (this.displayName != other.displayName) return false
264+
if (this.description != other.description) return false
265+
if (this.roots != other.roots) return false
266+
return true
267+
}
268+
269+
override fun equalsIgnoringEntitySource(other: Any?): Boolean {
270+
if (other == null) return false
271+
if (this.javaClass != other.javaClass) return false
272+
273+
other as GraphQLLibraryEntityData
274+
275+
if (this.identifier != other.identifier) return false
276+
if (this.displayName != other.displayName) return false
277+
if (this.description != other.description) return false
278+
if (this.roots != other.roots) return false
279+
return true
280+
}
281+
282+
override fun hashCode(): Int {
283+
var result = entitySource.hashCode()
284+
result = 31 * result + identifier.hashCode()
285+
result = 31 * result + displayName.hashCode()
286+
result = 31 * result + description.hashCode()
287+
result = 31 * result + roots.hashCode()
288+
return result
289+
}
290+
291+
override fun hashCodeIgnoringEntitySource(): Int {
292+
var result = javaClass.hashCode()
293+
result = 31 * result + identifier.hashCode()
294+
result = 31 * result + displayName.hashCode()
295+
result = 31 * result + description.hashCode()
296+
result = 31 * result + roots.hashCode()
297+
return result
298+
}
299+
}

0 commit comments

Comments
 (0)