- Timestamp:
- 01/20/15 12:16:25 (10 years ago)
- 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 150 150 <Compile Include="LanguageFeatures\CodeCompletion\CSharp\CSharpCodeCompletionContext.cs" /> 151 151 <Compile Include="LanguageFeatures\CodeCompletion\CSharp\CSharpCodeCompletionDataFactory.cs" /> 152 <Compile Include="LanguageFeatures\CodeCompletion\CSharp\CSharpCodeCompletionHelpers.cs" /> 152 153 <Compile Include="LanguageFeatures\CodeCompletion\CSharp\CompletionData\EntityCompletionData.cs" /> 153 154 <Compile Include="LanguageFeatures\CodeCompletion\CSharp\CompletionData\ImportCompletionData.cs" /> -
branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CSharpCodeCompletionContext.cs
r11700 r11800 20 20 #endregion 21 21 22 using ICSharpCode.NRefactory.CSharp;23 22 using ICSharpCode.NRefactory.CSharp.Completion; 24 using ICSharpCode.NRefactory.CSharp.Resolver;25 23 using ICSharpCode.NRefactory.CSharp.TypeSystem; 26 24 using ICSharpCode.NRefactory.Editor; … … 29 27 namespace HeuristicLab.CodeEditor { 30 28 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; } } 38 43 39 44 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; 42 47 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); 47 50 48 ProjectContent = projectContent.AddOrUpdateFiles(unresolvedFile); 49 Compilation = projectContent.CreateCompilation(); 51 completionContextProvider = new DefaultCompletionContextProvider(this.document, unresolvedFile); 50 52 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); 55 56 } 56 57 } -
branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CSharpCodeCompletionStrategy.cs
r11738 r11800 26 26 using ICSharpCode.NRefactory.CSharp; 27 27 using ICSharpCode.NRefactory.CSharp.Completion; 28 using ICSharpCode.NRefactory.Editor; 28 29 using ICSharpCode.NRefactory.TypeSystem; 29 30 … … 92 93 } 93 94 } 95 } 94 96 95 96 97 98 99 100 101 102 97 if (!controlSpace) { 98 var pce = new CSharpParameterCompletionEngine( 99 completionContext.Document, 100 completionContext.CompletionContextProvider, 101 completionFactory, 102 completionContext.ProjectContent, 103 completionContext.TypeResolveContextAtCaret 104 ); 103 105 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; 107 108 } 108 109 109 110 return result; 110 111 } 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 } 111 124 } 112 125 } -
branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CodeCompletionResult.cs
r11700 r11800 25 25 namespace HeuristicLab.CodeEditor { 26 26 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; } 30 31 31 public IOverloadProvider OverloadProvider; 32 public CodeCompletionResult() { 33 CompletionData = new List<ICompletionData>(); 34 } 32 35 } 33 36 } -
branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CodeCompletionStrategy.cs
r11700 r11800 21 21 22 22 using System.Linq; 23 using System.Threading; 24 using System.Threading.Tasks; 23 25 using ICSharpCode.AvalonEdit.CodeCompletion; 24 26 … … 26 28 internal abstract class CodeCompletionStrategy : ICodeCompletionStrategy { 27 29 protected readonly CodeEditor codeEditor; 30 protected readonly Task backgroundParser; 28 31 29 32 protected CodeCompletionStrategy(CodeEditor codeEditor) { 30 33 this.codeEditor = codeEditor; 34 backgroundParser = new Task(DoBackgroundParsing); 31 35 } 32 36 … … 36 40 } 37 41 42 public virtual void RunBackgroundParser() { 43 backgroundParser.Start(); 44 } 45 38 46 protected abstract CodeCompletionResult GetCodeCompletionResult(bool controlSpace); 47 protected abstract void DoParseStep(); 39 48 40 49 protected virtual void ApplyCodeCompletionData(CodeCompletionResult codeCompletionResult) { … … 57 66 58 67 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) 60 70 data.Add(completion); 61 71 … … 77 87 } 78 88 } 89 90 protected virtual void DoBackgroundParsing() { 91 while (!codeEditor.IsDisposed) { 92 DoParseStep(); 93 Thread.Sleep(1000); 94 } 95 } 79 96 } 80 97 } -
branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/Interfaces/ICodeCompletionStrategy.cs
r11700 r11800 23 23 internal interface ICodeCompletionStrategy { 24 24 void DoCodeCompletion(bool controlSpace); 25 void RunBackgroundParser(); 25 26 } 26 27 } -
branches/CodeEditor/HeuristicLab.CodeEditor/3.4/LanguageFeatures/LanguageFeatures.cs
r11700 r11800 56 56 #region CodeCompletionStrategy 57 57 protected virtual void AddCodeComplectionStrategy() { 58 codeEditor.Load += LoadedHandler; 58 59 codeEditor.TextEditor.TextArea.TextEntered += CodeCompletionHandler; 59 60 codeEditor.TextEditor.TextArea.TextEntering += InsertionRequestedHandler; 60 61 codeEditor.TextEditor.CommandBindings.Add(commandBinding); 62 } 63 64 private void LoadedHandler(object sender, EventArgs e) { 65 codeCompletionStrategy.RunBackgroundParser(); 61 66 } 62 67
Note: See TracChangeset
for help on using the changeset viewer.