Skip to content

Commit 185ca1a

Browse files
authored
fix: handle URIs with encoded spaces in applyEdit [IDE-1555] (#746)
* fix: handle URIs with encoded spaces in applyEdit [IDE-1555] - Replace VirtualFileManager.findFileByUrl() with toVirtualFileOrNull() which properly decodes URL-encoded characters (e.g., %20 to spaces) - Add debug logging to applyEdit and DocumentChanger to trace URI handling - Fixes issue where applyEdit failed for paths containing spaces, dots, and underscores The issue was that findFileByUrl() doesn't handle URL-encoded URIs. Using toVirtualFileOrNull() converts the URI to a path first, which automatically decodes %20 to spaces, then finds the file using the decoded path. * refactor: use modern logger pattern in DocumentChanger Replace Logger.getInstance() with logger<DocumentChanger>() to match the pattern used throughout the codebase
1 parent c75fffd commit 185ca1a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/main/kotlin/snyk/common/editor/DocumentChanger.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
package snyk.common.editor
22

3-
import com.intellij.openapi.vfs.VirtualFileManager
3+
import com.intellij.openapi.diagnostic.logger
44
import io.snyk.plugin.getDocument
5+
import io.snyk.plugin.toVirtualFileOrNull
56
import org.eclipse.lsp4j.TextEdit
67

78
object DocumentChanger {
9+
private val logger = logger<DocumentChanger>()
10+
811
fun applyChange(change: Map.Entry<String, List<TextEdit>>?) {
9-
if (change == null) return //TODO add log
12+
if (change == null) {
13+
logger.warn("applyChange called with null change")
14+
return
15+
}
1016
val fileURI = change.key
11-
val virtualFile = VirtualFileManager.getInstance().findFileByUrl(fileURI) ?: return
17+
logger.debug("applyChange: Attempting to find file by URI: $fileURI (length: ${fileURI.length})")
18+
19+
// Use toVirtualFileOrNull() which properly handles URI decoding (e.g., %20 to spaces)
20+
// This converts the URI to a path first, which automatically decodes URL-encoded characters
21+
val virtualFile = fileURI.toVirtualFileOrNull()
22+
if (virtualFile == null) {
23+
return
24+
}
25+
1226
val document = virtualFile.getDocument() ?: return
1327
// Our LS is coded to give us the TextEdits in ascending order, but we must apply them in descending order.
1428
// Imagine we had an edit that added 10 lines to the start of the file followed by an edit that added a line to the 4th line of the file,

0 commit comments

Comments
 (0)