@@ -144,17 +144,6 @@ internal class KtSymbolIndex(
144144 indexWorker.submitCommand(IndexCommand .RemoveFromIndex (path))
145145 }
146146
147- suspend fun onFileMoved (from : Path , to : Path ) {
148- // always remove the source file from index
149- indexWorker.submitCommand(IndexCommand .RemoveFromIndex (from))
150-
151- val toVf = getVirtualFileOrWarn(to) ? : return
152- indexWorker.apply {
153- submitCommand(IndexCommand .ScanSourceFile (toVf))
154- submitCommand(IndexCommand .IndexSourceFile (toVf))
155- }
156- }
157-
158147 fun queueOnFileChangedAsync (ktFile : KtFile ) {
159148 scope.launch {
160149 queueOnFileChanged(ktFile)
@@ -165,8 +154,8 @@ internal class KtSymbolIndex(
165154 indexWorker.submitCommand(IndexCommand .IndexModifiedFile (ktFile))
166155 }
167156
168- fun openKtFile (path : Path , ktFile : KtFile ) {
169- openedFiles[ path] = ktFile
157+ fun openKtFile (path : Path , ktFile : KtFile ): KtFile ? {
158+ return openedFiles.put( path, ktFile)
170159 }
171160
172161 fun closeKtFile (path : Path ) {
@@ -175,15 +164,30 @@ internal class KtSymbolIndex(
175164
176165 fun getOpenedKtFile (path : Path ) = openedFiles[path]
177166
178- fun getKtFile (vf : VirtualFile ): KtFile ? {
179- val path = vf.toNioPath()
167+ fun getKtFile (vf : VirtualFile ): KtFile ? =
168+ getKtFile(vf.toNioPath(), vf)
169+
170+ fun getKtFile (path : Path , virtualFile : VirtualFile ? = null): KtFile ? {
180171 if (! DocumentUtils .isKotlinFile(path)) return null
181172
182- openedFiles[path]?.also { return it }
183- ktFileCache.getIfPresent(path)?.also { return it }
173+ openedFiles[path]?.also {
174+ return it
175+ }
176+
177+ ktFileCache.getIfPresent(path)?.also {
178+ return it
179+ }
184180
185- val ktFile = loadKtFile(vf)
181+ var file = virtualFile
182+ if (file == null ) {
183+ file = path.toVirtualFileOrNull()
184+ }
185+
186+ if (file == null ) {
187+ return null
188+ }
186189
190+ val ktFile = loadKtFile(file)
187191 ktFileCache.put(path, ktFile)
188192 return ktFile
189193 }
0 commit comments