Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12655 for stable


Ignore:
Timestamp:
07/07/15 16:26:18 (9 years ago)
Author:
jkarder
Message:

#2419: merged r12646, r12653 and r12654 into stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CSharpCodeCompletionStrategy.cs

    r12009 r12655  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
     
    2625using ICSharpCode.NRefactory.CSharp;
    2726using ICSharpCode.NRefactory.CSharp.Completion;
    28 using ICSharpCode.NRefactory.Editor;
    2927using ICSharpCode.NRefactory.TypeSystem;
    3028
     
    112110
    113111    protected override void DoParseStep() {
    114       var document = (IDocument)codeEditor.Invoke(
    115         (Func<IDocument>)(() => {
    116           var doc = codeEditor.TextEditor.Document;
    117           return new ReadOnlyDocument(doc, doc.FileName);
    118         })
    119       );
    120 
     112      if (document == null) return;
    121113      var unresolvedFile = CSharpParsingHelpers.CreateCSharpUnresolvedFile(document);
    122114      projectContent = projectContent.AddOrUpdateFiles(unresolvedFile);
  • stable/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CodeCompletionStrategy.cs

    r12009 r12655  
    2020#endregion
    2121
     22using System;
    2223using System.Linq;
    23 using System.Threading;
    2424using System.Threading.Tasks;
    2525using ICSharpCode.AvalonEdit.CodeCompletion;
     26using ICSharpCode.NRefactory.Editor;
     27using Timer = System.Timers.Timer;
    2628
    2729namespace HeuristicLab.CodeEditor {
    2830  internal abstract class CodeCompletionStrategy : ICodeCompletionStrategy {
    2931    protected readonly CodeEditor codeEditor;
    30     protected readonly Task backgroundParser;
     32    protected readonly Timer parserTimer;
     33    protected IDocument document;
    3134
    3235    protected CodeCompletionStrategy(CodeEditor codeEditor) {
    3336      this.codeEditor = codeEditor;
    34       backgroundParser = new Task(DoBackgroundParsing);
     37      this.codeEditor.TextEditorTextChanged += codeEditor_TextEditorTextChanged;
     38      parserTimer = new Timer(1000);
     39      parserTimer.Elapsed += (sender, args) => Task.Run(() => {
     40        DoParseStep();
     41        if (codeEditor.IsDisposed && parserTimer.Enabled) {
     42          parserTimer.Stop();
     43          parserTimer.Dispose();
     44        }
     45      });
    3546    }
    3647
     
    4152
    4253    public virtual void Initialize() {
    43       if (backgroundParser.Status == TaskStatus.Created)
    44         backgroundParser.Start();
     54      parserTimer.Enabled = true;
    4555    }
    4656
     
    8999    }
    90100
    91     protected virtual void DoBackgroundParsing() {
    92       while (!codeEditor.IsDisposed) {
    93         DoParseStep();
    94         Thread.Sleep(1000);
    95       }
     101    private void codeEditor_TextEditorTextChanged(object sender, EventArgs e) {
     102      var doc = codeEditor.TextEditor.Document;
     103      document = new ReadOnlyDocument(doc, doc.FileName);
    96104    }
    97105  }
Note: See TracChangeset for help on using the changeset viewer.