Skip to content

Commit fe3e3bf

Browse files
authored
Integration into the "Invalidate Caches..." dialog (#58)
1 parent d89f0e5 commit fe3e3bf

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

third_party/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Added
44

5+
- Support in the "Invalidate Caches..." dialog to remove ~/.dartServer cache
6+
57
### Removed
68

79
- "Scope analysis to the current package" feature from the Dart problem view
@@ -10,8 +12,8 @@
1012

1113
### Changed
1214

13-
- Vendor change from "JetBrains" to "Google"
14-
- Build system change from Basel to Gradle
15+
- Vendor change from "JetBrains" to "Google"
16+
- Build system change from Basel to Gradle
1517

1618

1719
## 251.27812.12
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.jetbrains.lang.dart.analyzer
2+
3+
import com.intellij.ide.caches.CachesInvalidator
4+
import com.intellij.openapi.project.ProjectManager
5+
import com.intellij.openapi.util.SystemInfoRt
6+
import com.jetbrains.lang.dart.DartBundle
7+
import java.io.File
8+
9+
/**
10+
* A CachesInvalidator for the Dart IntelliJ plugin, on the execution of this invalidator,
11+
* the `~./dartServer/` directory (or equivalent on Windows machines), is deleted.
12+
*/
13+
private class DASSCacheInvalidator : CachesInvalidator() {
14+
15+
override fun getComment(): String = DartBundle.message("analysis.server.cache.invalidate.comment")
16+
17+
override fun getDescription(): String = DartBundle.message("analysis.server.cache.invalidate.description")
18+
19+
override fun optionalCheckboxDefaultValue(): Boolean = false
20+
21+
override fun invalidateCaches() {
22+
val projects = ProjectManager.getInstance().openProjects
23+
for (project in projects) {
24+
val serverService = DartAnalysisServerService.getInstance(project)
25+
serverService.stopServer()
26+
}
27+
val dartServerCacheDirectory = getDartServerCacheDirectory()
28+
if (dartServerCacheDirectory != null && dartServerCacheDirectory.exists()) {
29+
dartServerCacheDirectory.deleteRecursively()
30+
}
31+
}
32+
33+
private fun getDartServerCacheDirectory(): File? {
34+
return if (SystemInfoRt.isWindows) {
35+
val appData = System.getenv("LOCALAPPDATA")
36+
if (appData != null) File(appData, ".dartServer") else null
37+
} else {
38+
val userHome = System.getProperty("user.home")
39+
if (userHome != null) File(userHome, ".dartServer") else null
40+
}
41+
}
42+
}

third_party/src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
<intentionAction> <className>com.jetbrains.lang.dart.assists.DartQuickAssistIntention$DartQuickAssistIntention14</className> <language/> <bundleName>messages.DartBundle</bundleName> <categoryKey>inspections.group.name</categoryKey> <descriptionDirectoryName>DartQuickAssistIntention</descriptionDirectoryName></intentionAction>
206206

207207
<projectService serviceImplementation="com.jetbrains.lang.dart.analyzer.DartAnalysisServerService"/>
208+
<cachesInvalidator implementation="com.jetbrains.lang.dart.analyzer.DASSCacheInvalidator"/>
208209

209210
<toolWindow id="Dart Analysis" anchor="bottom" icon="DartIcons.Dart_13" doNotActivateOnStart="true" canCloseContents="false"
210211
factoryClass="com.jetbrains.lang.dart.ide.errorTreeView.DartAnalysisToolWindowFactory"/>

third_party/src/main/resources/messages/DartBundle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ analysis.server.snapshot.file.does.not.exist.at.0=the Dart Analysis Server snaps
266266
dart.vm.file.is.not.executable.at.0=the Dart VM file is not executable at location: {0}
267267
analysis.server.snapshot.file.is.not.readable.at.0=the Dart Analysis Server snapshot file is not readable at location: {0}
268268
issue.occurred.with.analysis.server=an issue occurred with the analysis server
269+
analysis.server.cache.invalidate.description=Delete the local Dart analysis server cache directory
270+
analysis.server.cache.invalidate.comment=Recursively deletes .dartServer/ from the local disk
269271

270272
action.Dart.DartSortMembers.text=Sort Members in Dart File
271273
action.Dart.DartSortMembers.description=Sort members in your Dart code

0 commit comments

Comments
 (0)