@@ -45,7 +45,7 @@ public class Workspace
4545
4646        internal  CompilationProject  CompilationProject  {  get ;  private  set ;  } 
4747
48-         private  List < FileCompiler >  _fileCompilerWaittingForNodePhase ; 
48+         private  List < FileCompiler >  _fileCompilerWaitingForNodePhase ; 
4949        public  TypeCobolConfiguration  Configuration  {  get ;  private  set ;  } 
5050        public  event  EventHandler < DiagnosticEvent >  DiagnosticsEvent ; 
5151        public  event  EventHandler < EventArgs >  DocumentModifiedEvent ; 
@@ -162,7 +162,7 @@ public Workspace(string rootDirectoryFullName, string workspaceName, Queue<Messa
162162            MessagesActionsQueue  =  messagesActionsQueue ; 
163163            Configuration  =  new  TypeCobolConfiguration ( ) ; 
164164            _openedDocuments  =  new  Dictionary < Uri ,  DocumentContext > ( ) ; 
165-             _fileCompilerWaittingForNodePhase  =  new  List < FileCompiler > ( ) ; 
165+             _fileCompilerWaitingForNodePhase  =  new  List < FileCompiler > ( ) ; 
166166            _Logger  =  logger ; 
167167
168168            this . _rootDirectoryFullName  =  rootDirectoryFullName ; 
@@ -234,22 +234,22 @@ private FileCompiler OpenTextDocument(DocumentContext docContext, string sourceT
234234#else
235235            fileCompiler  =  new  FileCompiler ( initialTextDocumentLines ,  CompilationProject . SourceFileProvider ,  CompilationProject ,  CompilationProject . CompilationOptions ,  _customSymbols ,  CompilationProject ) ; 
236236#endif
237-             //Set Any Language Server Connection Options. 
238-             docContext . FileCompiler  =  fileCompiler ; 
239-             docContext . LanguageServerConnection ( true ) ; 
240- 
241-             fileCompiler . CompilationResultsForProgram . UpdateTokensLines ( ) ; 
242237
243238            lock  ( _lockForOpenedDocuments ) 
244239            { 
245240                if  ( _openedDocuments . ContainsKey ( docContext . Uri ) ) 
246241                    CloseSourceFile ( docContext . Uri ) ;  //Close and remove the previous opened file. 
247242
248243                _openedDocuments . Add ( docContext . Uri ,  docContext ) ; 
249-                 fileCompiler . CompilationResultsForProgram . CodeAnalysisCompleted  +=  FinalCompilationStepCompleted ; 
250244            } 
251245
246+             //Set Any Language Server Connection Options. 
247+             docContext . FileCompiler  =  fileCompiler ; 
248+             docContext . LanguageServerConnection ( true ) ; 
249+ 
252250            fileCompiler . CompilationResultsForProgram . SetOwnerThread ( Thread . CurrentThread ) ; 
251+             fileCompiler . CompilationResultsForProgram . CodeAnalysisCompleted  +=  FinalCompilationStepCompleted ; 
252+             fileCompiler . CompilationResultsForProgram . UpdateTokensLines ( ) ; 
253253
254254            if  ( lsrOptions  !=  LsrTestingOptions . LsrSourceDocumentTesting ) 
255255            { 
@@ -325,14 +325,14 @@ public void UpdateSourceFile(Uri fileUri, TextChangedEvent textChangedEvent)
325325                { 
326326                    if  ( ! _timerDisabled )  //If TimerDisabled is false, create a timer to automatically launch Node phase 
327327                    { 
328-                         lock  ( _fileCompilerWaittingForNodePhase ) 
328+                         lock  ( _fileCompilerWaitingForNodePhase ) 
329329                        { 
330-                             if  ( ! _fileCompilerWaittingForNodePhase . Contains ( fileCompilerToUpdate ) ) 
331-                                 _fileCompilerWaittingForNodePhase . Add ( fileCompilerToUpdate ) ;  //Store that this fileCompiler will soon need a Node Phase 
330+                             if  ( ! _fileCompilerWaitingForNodePhase . Contains ( fileCompilerToUpdate ) ) 
331+                                 _fileCompilerWaitingForNodePhase . Add ( fileCompilerToUpdate ) ;  //Store that this fileCompiler will soon need a Node Phase 
332332                        } 
333333
334334                        _semanticUpdaterTimer  =  new  System . Timers . Timer ( 750 ) ; 
335-                         _semanticUpdaterTimer . Elapsed  +=  ( sender ,  e )  =>  TimerEvent ( sender ,   e ,   fileCompilerToUpdate ) ; 
335+                         _semanticUpdaterTimer . Elapsed  +=  ( sender ,  e )  =>  TimerEvent ( fileUri ) ; 
336336                        _semanticUpdaterTimer . Start ( ) ; 
337337                    } 
338338                } 
@@ -392,23 +392,29 @@ private void ExecutionStepEventHandler(object oFileCompiler, ExecutionStepEventA
392392        /// <param name="sender"></param> 
393393        /// <param name="eventArgs"></param> 
394394        /// <param name="fileCompiler"></param> 
395-         private  void  TimerEvent ( object   sender ,   ElapsedEventArgs   eventArgs ,   FileCompiler   fileCompiler ) 
395+         private  void  TimerEvent ( Uri   fileUri ) 
396396        { 
397397            try 
398398            { 
399399                _semanticUpdaterTimer . Stop ( ) ; 
400-                 Action  nodeRefreshAction  =  ( )  =>  {  RefreshSyntaxTree ( fileCompiler ,  SyntaxTreeRefreshLevel . RebuildNodesAndPerformQualityCheck ) ;  } ; 
401400                lock  ( MessagesActionsQueue ) 
402401                { 
403-                     MessagesActionsQueue . Enqueue ( new  MessageActionWrapper ( nodeRefreshAction ) ) ; 
402+                     MessagesActionsQueue . Enqueue ( new  MessageActionWrapper ( Refresh ) ) ; 
404403                } 
405404            } 
406405            catch  ( Exception  e ) 
407406            { 
408407                //In case Timer Thread crash 
409408                ExceptionTriggered ( null ,  new  ThreadExceptionEventArgs ( e ) ) ; 
410409            } 
411-            
410+ 
411+             void  Refresh ( ) 
412+             { 
413+                 if  ( TryGetOpenedDocumentContext ( fileUri ,  out  var  docContext ) ) 
414+                 { 
415+                     RefreshSyntaxTree ( docContext . FileCompiler ,  SyntaxTreeRefreshLevel . RebuildNodesAndPerformQualityCheck ) ; 
416+                 } 
417+             } 
412418        } 
413419
414420        /// <summary> 
@@ -446,12 +452,12 @@ public void RefreshSyntaxTree(FileCompiler fileCompiler, SyntaxTreeRefreshLevel
446452        { 
447453            if  ( refreshLevel  ==  SyntaxTreeRefreshLevel . NoRefresh )  return ;  //nothing to do 
448454
449-             lock  ( _fileCompilerWaittingForNodePhase ) 
455+             lock  ( _fileCompilerWaitingForNodePhase ) 
450456            { 
451-                 var  fileCompilerNeedsRefresh  =  _fileCompilerWaittingForNodePhase . Contains ( fileCompiler ) ; 
457+                 var  fileCompilerNeedsRefresh  =  _fileCompilerWaitingForNodePhase . Contains ( fileCompiler ) ; 
452458                if  ( fileCompilerNeedsRefresh ) 
453459                { 
454-                     _fileCompilerWaittingForNodePhase . Remove ( fileCompiler ) ; 
460+                     _fileCompilerWaitingForNodePhase . Remove ( fileCompiler ) ; 
455461                } 
456462                else 
457463                { 
@@ -495,16 +501,27 @@ void RefreshCodeAnalysisResults()
495501        /// </summary> 
496502        public  void  CloseSourceFile ( Uri  fileUri ) 
497503        { 
504+             FileCompiler  fileCompilerToClose  =  null ; 
505+ 
506+             //Remove from opened documents dictionary 
498507            lock  ( _lockForOpenedDocuments ) 
499508            { 
500-                 if  ( _openedDocuments . ContainsKey ( fileUri ) ) 
509+                 if  ( _openedDocuments . TryGetValue ( fileUri ,   out   var   contextToClose ) ) 
501510                { 
502-                     var  contextToClose  =  _openedDocuments [ fileUri ] ; 
503-                     FileCompiler  fileCompilerToClose  =  contextToClose . FileCompiler ; 
511+                     fileCompilerToClose  =  contextToClose . FileCompiler ; 
504512                    _openedDocuments . Remove ( fileUri ) ; 
505513                    fileCompilerToClose . CompilationResultsForProgram . CodeAnalysisCompleted  -=  FinalCompilationStepCompleted ; 
506514                } 
507-             }             
515+             } 
516+ 
517+             //Remove from pending semantic analysis list 
518+             if  ( fileCompilerToClose  !=  null ) 
519+             { 
520+                 lock  ( _fileCompilerWaitingForNodePhase ) 
521+                 { 
522+                     _fileCompilerWaitingForNodePhase . Remove ( fileCompilerToClose ) ; 
523+                 } 
524+             } 
508525        } 
509526
510527        /// <summary> 
0 commit comments