@@ -97,7 +97,7 @@ class EditorDocumentService(private val project: Project, private val cs: Corout
9797 try {
9898 doOnFileOpened(file)
9999 } catch (e: Throwable ) {
100- Log .warnWithException(logger, e, " Exception in fileOpened {}" , e)
100+ Log .warnWithException(logger, project, e, " Exception in fileOpened {}" , e)
101101 ErrorReporter .getInstance().reportError(project, " EditorDocumentService.fileOpened" , e)
102102 }
103103 }
@@ -114,10 +114,7 @@ class EditorDocumentService(private val project: Project, private val cs: Corout
114114 // Note: I tried to use EditorFactory.getInstance().eventMulticaster but it will fire hundreds of events for every file open file also for non-writable
115115 // files. Don't use it!
116116 if (isRelevantLanguageFileNoSlowOperations(file)) {
117-
118- if (logger.isTraceEnabled) {
119- Log .log(logger::trace, " fileOpened: processing {}" , file)
120- }
117+ Log .trace(logger, project, " fileOpened: processing {}" , file)
121118
122119 // this is protection against dev error, it should never happen. we should catch it in development.
123120 if (documentChangeListenerDisposables.contains(file)) {
@@ -127,20 +124,14 @@ class EditorDocumentService(private val project: Project, private val cs: Corout
127124
128125 val document = FileDocumentManager .getInstance().getDocument(file)
129126 if (document != null ) {
130- if (logger.isTraceEnabled) {
131- Log .log(logger::trace, " fileOpened: adding document listener for {}" , file)
132- }
127+ Log .trace(logger, project, " fileOpened: adding document listener for {}" , file)
133128 val disposable = Disposer .newDisposable()
134129 document.addDocumentListener(myDocumentListener, disposable)
135130 documentChangeListenerDisposables[file] = disposable
136- if (logger.isTraceEnabled) {
137- Log .log(logger::trace, " fileOpened: starting build document info job for {}" , file)
138- }
131+ Log .trace(logger, project, " fileOpened: starting build document info job for {}" , file)
139132 launchBuildDocumentInfoJob(file)
140133 } else {
141- if (logger.isTraceEnabled) {
142- Log .log(logger::warn, " fileOpened: file is relevant but document is null for {}" , file)
143- }
134+ Log .warn(logger, project, " fileOpened: file is relevant but document is null for {}" , file)
144135 }
145136 }
146137 }
@@ -150,7 +141,7 @@ class EditorDocumentService(private val project: Project, private val cs: Corout
150141 try {
151142 doOnFileClosed(file)
152143 } catch (e: Throwable ) {
153- Log .warnWithException(logger, e, " Exception in fileClosed {}" , e)
144+ Log .warnWithException(logger, project, e, " Exception in fileClosed {}" , e)
154145 ErrorReporter .getInstance().reportError(project, " EditorDocumentService.fileClosed" , e)
155146 }
156147 }
@@ -168,15 +159,11 @@ class EditorDocumentService(private val project: Project, private val cs: Corout
168159 return
169160 }
170161
171- if (logger.isTraceEnabled) {
172- Log .log(logger::trace, " fileClosed: processing {}" , file)
173- }
162+ Log .trace(logger, project, " fileClosed: processing {}" , file)
174163
175164 val disposable = documentChangeListenerDisposables.remove(file)
176165 disposable?.let {
177- if (logger.isTraceEnabled) {
178- Log .log(logger::trace, " fileClosed: removing document listener for {}" , file)
179- }
166+ Log .trace(logger, project, " fileClosed: removing document listener for {}" , file)
180167 Disposer .dispose(it)
181168 }
182169
@@ -186,7 +173,7 @@ class EditorDocumentService(private val project: Project, private val cs: Corout
186173 removeDocumentFromChangedDocuments(file)
187174 filesToUpdate.remove(file)
188175 runningJobs[file]?.cancel(CancellationException (" File was closed" ))
189- }finally {
176+ } finally {
190177 putRemoveLock.withLock {
191178 DocumentInfoStorage .getInstance(project).removeDocumentInfo(file)
192179 }
@@ -220,8 +207,8 @@ class EditorDocumentService(private val project: Project, private val cs: Corout
220207 while (document != null ) {
221208 if (document.isWritable) {
222209 val file = FileDocumentManager .getInstance().getFile(document)
223- file?.let {
224- filesToUpdate.add(file )
210+ file?.takeIf { isValidVirtualFile(it) }?. let {
211+ filesToUpdate.add(it )
225212 }
226213 }
227214 document = changedDocuments.poll()
@@ -241,20 +228,15 @@ class EditorDocumentService(private val project: Project, private val cs: Corout
241228 // This method is invoked after the quite period has passed.
242229 // While waiting for quite period we didn't run anything on EDT or read access.
243230 private fun updateDocumentInfo (virtualFile : VirtualFile ) {
244- if (logger.isTraceEnabled) {
245- Log .log(logger::trace, " updateDocumentInfo: {}" , virtualFile)
246- }
247-
231+ Log .trace(logger, project, " updateDocumentInfo: {}" , virtualFile)
248232 launchBuildDocumentInfoJob(virtualFile)
249233 }
250234
251235
252236 // this method will be called on EDT from fileOpened, and in a coroutine for updates, it should run fast and not take read access.
253237 private fun launchBuildDocumentInfoJob (file : VirtualFile ) {
254238
255- if (logger.isTraceEnabled) {
256- Log .log(logger::trace, " starting buildDocumentInfo job for {}" , file)
257- }
239+ Log .trace(logger, project, " starting buildDocumentInfo job for {}" , file)
258240
259241 runningJobs[file]?.cancel(CancellationException (" New job started" ))
260242 val job = cs.launchWithErrorReporting(" EditorDocumentService.launchBuildDocumentInfoJob" , logger) {
@@ -275,40 +257,40 @@ class EditorDocumentService(private val project: Project, private val cs: Corout
275257 // building DocumentInfo finished and just before putting it in the storage, that is handled by putRemoveLock.
276258 // Exceptions are caught in the coroutine exception handler and reported in invokeOnCompletion.
277259
278- Log .log (logger::trace , " buildDocumentInfo: {}" , file)
260+ Log .trace (logger, project , " buildDocumentInfo: {}" , file)
279261
280262 val isRelevant = readAction {
281263 isRelevantFile(file)
282264 }
283265 coroutineContext.ensureActive()
284266 if (! isRelevant) {
285- Log .log (logger::trace , " buildDocumentInfo: file is not relevant {}" , file)
267+ Log .trace (logger, project , " buildDocumentInfo: file is not relevant {}" , file)
286268 return
287269 }
288270
289271 if (! isSupportedLanguageFile(project, file)) {
290- Log .log (logger::trace , " buildDocumentInfo: file is not a supported language {}" , file)
272+ Log .trace (logger, project , " buildDocumentInfo: file is not a supported language {}" , file)
291273 return
292274 }
293275 coroutineContext.ensureActive()
294276
295277 val languageService = LanguageServiceProvider .getInstance(project).getLanguageService(file)
296278 if (languageService == null ) {
297- Log .log (logger::warn , " buildDocumentInfo: could not find language service for {}" , file)
279+ Log .warn (logger, project , " buildDocumentInfo: could not find language service for {}" , file)
298280 return
299281 }
300282
301283 if (! languageService.isSupportedFile(file)) {
302- Log .log (logger::trace , " buildDocumentInfo: file is not supported by language service {}" , file)
284+ Log .trace (logger, project , " buildDocumentInfo: file is not supported by language service {}" , file)
303285 return
304286 }
305287
306288 coroutineContext.ensureActive()
307289 val documentInfo = languageService.buildDocumentInfo(file)
308290 if (documentInfo == null ) {
309- Log .log (logger::warn , " buildDocumentInfo: could not build document info for {}" , file)
291+ Log .warn (logger, project , " buildDocumentInfo: could not build document info for {}" , file)
310292 } else {
311- Log .log (logger::trace , " buildDocumentInfo: done building document info for {}" , file)
293+ Log .trace (logger, project , " buildDocumentInfo: done building document info for {}" , file)
312294 coroutineContext.ensureActive()
313295 putRemoveLock.withLock {
314296 coroutineContext.ensureActive()
0 commit comments