Skip to content

Commit 7a03d6a

Browse files
authored
fix: automatically invalidate moved/deleted entries from the ResourceForUriCache (#1235)
If a resource is moved or deleted, it's possible that the resource stored for its URI in the ResourceForUriCache stops being `accessible`. This commit changes `ResourceForUriCache.get(URI)` so that, if a resource is present in the cache but is no longer accessible, the corresponding cache entry is invalidated. In this case, `.get(URI)` then tries to determine the up-to-date IResource again. Fixes a regression introduced in #1208. Specifically, this commit addresses the concern raised in #1208 (comment)
1 parent 61b3da3 commit 7a03d6a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

org.eclipse.lsp4e/src/org/eclipse/lsp4e/internal/ResourceForUriCache.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ private ResourceForUriCache() {
4646
* if it's not already in the cache. Returns NULL if the IResource could not be determined,
4747
* e.g. the URI points to a file outside the workspace.
4848
*
49-
* <p>NOTE: In case a resource has been moved or deleted the entry will not be removed automatically.
50-
* It's up to the caller to check if the resource is accessible.
49+
* <p>In case a resource has been moved or deleted, the cache entry will be invalidated,
50+
* and this method will re-attempt to find the IResource.
5151
* @param uri
5252
* @return IResource or NULL
5353
*/
@@ -61,7 +61,10 @@ public static IResource get(@Nullable URI uri) {
6161
if (localURI != null) {
6262
resource = cache.getIfPresent(localURI);
6363
if (resource != null) {
64-
return resource;
64+
if (resource.isAccessible()) {
65+
return resource;
66+
}
67+
cache.invalidate(localURI);
6568
}
6669
resource = findResourceFor(localURI);
6770
if (resource != null) {

0 commit comments

Comments
 (0)