Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11800 for branches


Ignore:
Timestamp:
01/20/15 12:16:25 (10 years ago)
Author:
jkarder
Message:

#2077:

  • added background parser to provide code completion for the scripted code
  • minor code changes
Location:
branches/CodeEditor/HeuristicLab.CodeEditor/3.4
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/CodeEditor/HeuristicLab.CodeEditor/3.4/HeuristicLab.CodeEditor-3.4.csproj

    r11785 r11800  
    150150    <Compile Include="LanguageFeatures\CodeCompletion\CSharp\CSharpCodeCompletionContext.cs" />
    151151    <Compile Include="LanguageFeatures\CodeCompletion\CSharp\CSharpCodeCompletionDataFactory.cs" />
     152    <Compile Include="LanguageFeatures\CodeCompletion\CSharp\CSharpCodeCompletionHelpers.cs" />
    152153    <Compile Include="LanguageFeatures\CodeCompletion\CSharp\CompletionData\EntityCompletionData.cs" />
    153154    <Compile Include="LanguageFeatures\CodeCompletion\CSharp\CompletionData\ImportCompletionData.cs" />
  • branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CSharpCodeCompletionContext.cs

    r11700 r11800  
    2020#endregion
    2121
    22 using ICSharpCode.NRefactory.CSharp;
    2322using ICSharpCode.NRefactory.CSharp.Completion;
    24 using ICSharpCode.NRefactory.CSharp.Resolver;
    2523using ICSharpCode.NRefactory.CSharp.TypeSystem;
    2624using ICSharpCode.NRefactory.Editor;
     
    2927namespace HeuristicLab.CodeEditor {
    3028  internal class CSharpCodeCompletionContext {
    31     public readonly IDocument Document;
    32     public readonly int Offset;
    33     public readonly IProjectContent ProjectContent;
    34     public readonly ICompilation Compilation;
    35     public readonly CSharpResolver Resolver;
    36     public readonly CSharpTypeResolveContext TypeResolveContextAtCaret;
    37     public readonly ICompletionContextProvider CompletionContextProvider;
     29    private readonly IDocument document;
     30    public IDocument Document { get { return document; } }
     31
     32    private readonly int offset;
     33    public int Offset { get { return offset; } }
     34
     35    private readonly IProjectContent projectContent;
     36    public IProjectContent ProjectContent { get { return projectContent; } }
     37
     38    private readonly CSharpTypeResolveContext typeResolveContextAtCaret;
     39    public CSharpTypeResolveContext TypeResolveContextAtCaret { get { return typeResolveContextAtCaret; } }
     40
     41    private readonly ICompletionContextProvider completionContextProvider;
     42    public ICompletionContextProvider CompletionContextProvider { get { return completionContextProvider; } }
    3843
    3944    public CSharpCodeCompletionContext(IDocument document, int offset, IProjectContent projectContent) {
    40       Document = new ReadOnlyDocument(document, document.FileName);
    41       Offset = offset;
     45      this.document = new ReadOnlyDocument(document, document.FileName);
     46      this.offset = offset;
    4247
    43       var parser = new CSharpParser();
    44       var syntaxTree = parser.Parse(document, document.FileName);
    45       syntaxTree.Freeze();
    46       var unresolvedFile = syntaxTree.ToTypeSystem();
     48      var unresolvedFile = CSharpCodeCompletionHelpers.CreateCSharpUnresolvedFile(this.document);
     49      this.projectContent = projectContent.AddOrUpdateFiles(unresolvedFile);
    4750
    48       ProjectContent = projectContent.AddOrUpdateFiles(unresolvedFile);
    49       Compilation = projectContent.CreateCompilation();
     51      completionContextProvider = new DefaultCompletionContextProvider(this.document, unresolvedFile);
    5052
    51       var location = document.GetLocation(offset);
    52       Resolver = unresolvedFile.GetResolver(Compilation, location);
    53       TypeResolveContextAtCaret = unresolvedFile.GetTypeResolveContext(Compilation, location);
    54       CompletionContextProvider = new DefaultCompletionContextProvider(document, unresolvedFile);
     53      var compilation = this.projectContent.CreateCompilation();
     54      var location = this.document.GetLocation(this.offset);
     55      typeResolveContextAtCaret = unresolvedFile.GetTypeResolveContext(compilation, location);
    5556    }
    5657  }
  • branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CSharpCodeCompletionStrategy.cs

    r11738 r11800  
    2626using ICSharpCode.NRefactory.CSharp;
    2727using ICSharpCode.NRefactory.CSharp.Completion;
     28using ICSharpCode.NRefactory.Editor;
    2829using ICSharpCode.NRefactory.TypeSystem;
    2930
     
    9293          }
    9394        }
     95      }
    9496
    95         if (!controlSpace) {
    96           var pce = new CSharpParameterCompletionEngine(
    97             completionContext.Document,
    98             completionContext.CompletionContextProvider,
    99             completionFactory,
    100             completionContext.ProjectContent,
    101             completionContext.TypeResolveContextAtCaret
    102           );
     97      if (!controlSpace) {
     98        var pce = new CSharpParameterCompletionEngine(
     99          completionContext.Document,
     100          completionContext.CompletionContextProvider,
     101          completionFactory,
     102          completionContext.ProjectContent,
     103          completionContext.TypeResolveContextAtCaret
     104        );
    103105
    104           var parameterDataProvider = pce.GetParameterDataProvider(completionContext.Offset, completionChar);
    105           result.OverloadProvider = parameterDataProvider as IUpdatableOverloadProvider;
    106         }
     106        var parameterDataProvider = pce.GetParameterDataProvider(completionContext.Offset, completionChar);
     107        result.OverloadProvider = parameterDataProvider as IUpdatableOverloadProvider;
    107108      }
    108109
    109110      return result;
    110111    }
     112
     113    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
     121      var unresolvedFile = CSharpCodeCompletionHelpers.CreateCSharpUnresolvedFile(document);
     122      projectContent = projectContent.AddOrUpdateFiles(unresolvedFile);
     123    }
    111124  }
    112125}
  • branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CodeCompletionResult.cs

    r11700 r11800  
    2525namespace HeuristicLab.CodeEditor {
    2626  internal class CodeCompletionResult {
    27     public List<ICompletionData> CompletionData = new List<ICompletionData>();
    28     public int TriggerWordLength;
    29     public string TriggerWord;
     27    public IList<ICompletionData> CompletionData { get; set; }
     28    public int TriggerWordLength { get; set; }
     29    public string TriggerWord { get; set; }
     30    public IOverloadProvider OverloadProvider { get; set; }
    3031
    31     public IOverloadProvider OverloadProvider;
     32    public CodeCompletionResult() {
     33      CompletionData = new List<ICompletionData>();
     34    }
    3235  }
    3336}
  • branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CodeCompletionStrategy.cs

    r11700 r11800  
    2121
    2222using System.Linq;
     23using System.Threading;
     24using System.Threading.Tasks;
    2325using ICSharpCode.AvalonEdit.CodeCompletion;
    2426
     
    2628  internal abstract class CodeCompletionStrategy : ICodeCompletionStrategy {
    2729    protected readonly CodeEditor codeEditor;
     30    protected readonly Task backgroundParser;
    2831
    2932    protected CodeCompletionStrategy(CodeEditor codeEditor) {
    3033      this.codeEditor = codeEditor;
     34      backgroundParser = new Task(DoBackgroundParsing);
    3135    }
    3236
     
    3640    }
    3741
     42    public virtual void RunBackgroundParser() {
     43      backgroundParser.Start();
     44    }
     45
    3846    protected abstract CodeCompletionResult GetCodeCompletionResult(bool controlSpace);
     47    protected abstract void DoParseStep();
    3948
    4049    protected virtual void ApplyCodeCompletionData(CodeCompletionResult codeCompletionResult) {
     
    5766
    5867        var data = cw.CompletionList.CompletionData;
    59         foreach (var completion in codeCompletionResult.CompletionData.OrderBy(x => x.Text))
     68        var newData = codeCompletionResult.CompletionData.OrderBy(x => x.Text).ToArray();
     69        foreach (var completion in newData)
    6070          data.Add(completion);
    6171
     
    7787      }
    7888    }
     89
     90    protected virtual void DoBackgroundParsing() {
     91      while (!codeEditor.IsDisposed) {
     92        DoParseStep();
     93        Thread.Sleep(1000);
     94      }
     95    }
    7996  }
    8097}
  • branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/Interfaces/ICodeCompletionStrategy.cs

    r11700 r11800  
    2323  internal interface ICodeCompletionStrategy {
    2424    void DoCodeCompletion(bool controlSpace);
     25    void RunBackgroundParser();
    2526  }
    2627}
  • branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/LanguageFeatures.cs

    r11700 r11800  
    5656    #region CodeCompletionStrategy
    5757    protected virtual void AddCodeComplectionStrategy() {
     58      codeEditor.Load += LoadedHandler;
    5859      codeEditor.TextEditor.TextArea.TextEntered += CodeCompletionHandler;
    5960      codeEditor.TextEditor.TextArea.TextEntering += InsertionRequestedHandler;
    6061      codeEditor.TextEditor.CommandBindings.Add(commandBinding);
     62    }
     63
     64    private void LoadedHandler(object sender, EventArgs e) {
     65      codeCompletionStrategy.RunBackgroundParser();
    6166    }
    6267
Note: See TracChangeset for help on using the changeset viewer.