Skip to content

Commit bcbe07a

Browse files
Potential Working Synchronization
With this commit I locally tested the sync between Neovim and Intellij successfully.
1 parent d2c91fd commit bcbe07a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/main/kotlin/io/github/ethersync/EthersyncServiceImpl.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import com.intellij.openapi.project.Project
1616
import com.intellij.openapi.project.ProjectManager
1717
import com.intellij.openapi.project.ProjectManagerListener
1818
import com.intellij.openapi.vfs.VirtualFile
19-
import com.intellij.refactoring.suggested.newRange
19+
import com.intellij.refactoring.suggested.oldRange
2020
import com.intellij.ui.JBColor
2121
import com.intellij.util.io.await
2222
import com.intellij.util.io.awaitExit
@@ -65,17 +65,17 @@ class EthersyncServiceImpl(
6565
val bus = project.messageBus.connect()
6666
bus.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, object : FileEditorManagerListener {
6767
override fun fileOpened(source: FileEditorManager, file: VirtualFile) {
68-
launchDocumentOpenRequest(file.url)
68+
launchDocumentOpenRequest(file.canonicalFile!!.url)
6969
}
7070

7171
override fun fileClosed(source: FileEditorManager, file: VirtualFile) {
72-
launchDocumentCloseNotification(file.url)
72+
launchDocumentCloseNotification(file.canonicalFile!!.url)
7373
}
7474
})
7575

7676
val caretListener = object : CaretListener {
7777
override fun caretPositionChanged(event: CaretEvent) {
78-
val uri = event.editor.virtualFile.url
78+
val uri = event.editor.virtualFile.canonicalFile!!.url
7979
val pos = Position(event.newPosition.line, event.newPosition.column)
8080
val range = Range(pos, pos)
8181
launchCursorRequest(CursorRequest(uri, Collections.singletonList(range)))
@@ -95,14 +95,14 @@ class EthersyncServiceImpl(
9595

9696
val editor = fileEditor.editor
9797

98-
val uri = file.url
98+
val uri = file.canonicalFile!!.url
9999

100100
val rev = revisions[uri]!!
101101
rev.editor += 1u
102102

103103
// TODO: this calc doesn't seem right because there are some odd changes on the Neovim instance
104-
val start = editor.offsetToLogicalPosition(event.newRange.startOffset)
105-
val end = editor.offsetToLogicalPosition(event.newRange.endOffset)
104+
val start = editor.offsetToLogicalPosition(event.oldRange.startOffset)
105+
val end = editor.offsetToLogicalPosition(event.oldRange.endOffset)
106106

107107
launchEditRequest(
108108
EditRequest(
@@ -246,7 +246,7 @@ class EthersyncServiceImpl(
246246
val fileEditorManager = FileEditorManager.getInstance(project)
247247

248248
val fileEditor = fileEditorManager.allEditors
249-
.firstOrNull { editor -> editor.file.url == cursorEvent.documentUri } ?: return
249+
.firstOrNull { editor -> editor.file.canonicalFile!!.url == cursorEvent.documentUri } ?: return
250250

251251
if (fileEditor is TextEditor) {
252252
val editor = fileEditor.editor
@@ -307,7 +307,7 @@ class EthersyncServiceImpl(
307307
val fileEditorManager = FileEditorManager.getInstance(project)
308308

309309
val fileEditor = fileEditorManager.allEditors
310-
.first { editor -> editor.file.url == editEvent.documentUri } ?: return
310+
.first { editor -> editor.file.canonicalFile!!.url == editEvent.documentUri } ?: return
311311

312312
if (fileEditor is TextEditor) {
313313
val editor = fileEditor.editor
@@ -357,7 +357,7 @@ class EthersyncServiceImpl(
357357

358358
val fileEditorManager = FileEditorManager.getInstance(project)
359359
for (file in fileEditorManager.openFiles) {
360-
launchDocumentOpenRequest(file.url)
360+
launchDocumentOpenRequest(file.canonicalFile!!.url)
361361
}
362362

363363
clientProcess.awaitExit()

0 commit comments

Comments
 (0)