@@ -10,15 +10,29 @@ import org.digma.intellij.plugin.psi.PsiUtils
1010/*
1111There is an issue with file uri when running on windows,
1212the uri has a file:// schema,
13- when calling in resharper IPsiSourceFile.GetLocation().ToUri().ToString() it will return a file schema with different
14- number of slashes then when calling in the java side to PsiFile.getVirtualFile().getUrl().
15- it causes issues when using the uri in various maps.
13+ and we use this uri in document info service as the key for a document, this is instead of using the PsiFile object
14+ because PsiFile objects are not safe to use as keys in maps in case the platform decides to reparse a file while a
15+ project is opened.
16+ when calling in resharper IPsiSourceFile.GetLocation().ToUri().ToString() it will return a file schema with 2 slashes,
17+ when calling in the java side to PsiFile.getVirtualFile().getUrl() it will return 3 slashes.
18+ when a document is loaded we use the uri from resharper as key in DocumentInfoService, if we later try to find a
19+ DocumentInfo by calling PsiFile.getVirtualFile().getUrl() the document info will not be found because that call will
20+ return a file schema with 3 slashes.
21+ Another place we use the uri is in ElementUnderCaretDetector, the MethodUnderCaretEvent.fileUri will have 2 slashes.
22+
1623the solution here is to always normalize the uri that comes from the resharper side to a uri as comes in the jvm side.
1724so actually every object that passes from resharper to the jvm and has a uri that was taken from
1825IPsiSourceFile.GetLocation().ToUri().ToString() needs to be normalized.
19- PsiUtils.uriToPsiFile(fileUri,project) will always work , with 2 or with 3 slashes.
2026not all file uri in all objects is used, the main one that causes issues if the MethodUnderCaretEvent.fileUri,
2127but we normalize all the objects.
28+
29+ Note that PsiUtils.uriToPsiFile(fileUri,project) will always work , with 2 or with 3 slashes.
30+ the issue is only when we use the uri as key in our own code, opening a file with intellij utils will
31+ work regardless of the number of slashes. so for example the uris for span navigation returned from
32+ CodeObjectHost.findWorkspaceUrisForSpanIds or CodeObjectHost.findWorkspaceUrisForCodeObjectIds will also contain
33+ 2 slashes, but we don't use these as keys or to find DocumentInfo, they are used to open files which will always work.
34+
35+
2236 */
2337fun normalizeFileUri (fileUri : String ,project : Project ): String {
2438
0 commit comments