Changeset 14029 for branches/crossvalidation-2434/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp
- Timestamp:
- 07/08/16 14:40:02 (8 years ago)
- Location:
- branches/crossvalidation-2434
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/crossvalidation-2434
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CSharpCodeCompletionStrategy.cs
r12646 r14029 44 44 var document = codeEditor.TextEditor.Document; 45 45 int offset = codeEditor.TextEditor.CaretOffset; 46 var result = new CodeCompletionResult(); 46 47 47 var result = new CodeCompletionResult(); 48 var completionContext = new CSharpCodeCompletionContext(document, offset, projectContent); 49 var completionFactory = new CSharpCodeCompletionDataFactory(completionContext); 50 var cce = new CSharpCompletionEngine( 51 completionContext.Document, 52 completionContext.CompletionContextProvider, 53 completionFactory, 54 completionContext.ProjectContent, 55 completionContext.TypeResolveContextAtCaret 56 ); 57 58 char completionChar = completionContext.Document.GetCharAt(completionContext.Offset - 1); 59 int startPos, triggerWordLength; 60 IEnumerable<ICompletionData> completionData; 61 62 if (controlSpace) { 63 if (!cce.TryGetCompletionWord(completionContext.Offset, out startPos, out triggerWordLength)) { 64 startPos = completionContext.Offset; 65 triggerWordLength = 0; 66 } 67 completionData = cce.GetCompletionData(startPos, true); 68 } else { 69 startPos = completionContext.Offset; 70 if (char.IsLetterOrDigit(completionChar) || completionChar == '_') { 71 if (startPos > 1 && char.IsLetterOrDigit(completionContext.Document.GetCharAt((startPos - 2)))) 72 return result; 73 completionData = cce.GetCompletionData(startPos, false); 74 triggerWordLength = 1; 75 } else { 76 completionData = cce.GetCompletionData(startPos, false); 77 triggerWordLength = 0; 78 } 79 } 80 81 result.TriggerWordLength = triggerWordLength; 82 result.TriggerWord = completionContext.Document.GetText(completionContext.Offset - triggerWordLength, triggerWordLength); 83 84 if (completionData.Any() && cce.AutoCompleteEmptyMatch) { 85 foreach (var completion in completionData) { 86 var cast = completion as CompletionData; 87 if (cast != null) { 88 cast.TriggerWord = result.TriggerWord; 89 cast.TriggerWordLength = result.TriggerWordLength; 90 result.CompletionData.Add(cast); 91 } 92 } 93 } 94 95 if (!controlSpace) { 96 var pce = new CSharpParameterCompletionEngine( 48 try { 49 var completionContext = new CSharpCodeCompletionContext(document, offset, projectContent); 50 var completionFactory = new CSharpCodeCompletionDataFactory(completionContext); 51 var cce = new CSharpCompletionEngine( 97 52 completionContext.Document, 98 53 completionContext.CompletionContextProvider, … … 100 55 completionContext.ProjectContent, 101 56 completionContext.TypeResolveContextAtCaret 102 );57 ); 103 58 104 var parameterDataProvider = pce.GetParameterDataProvider(completionContext.Offset, completionChar); 105 result.OverloadProvider = parameterDataProvider as IUpdatableOverloadProvider; 59 char completionChar = completionContext.Document.GetCharAt(completionContext.Offset - 1); 60 int startPos, triggerWordLength; 61 IEnumerable<ICompletionData> completionData; 62 63 if (controlSpace) { 64 if (!cce.TryGetCompletionWord(completionContext.Offset, out startPos, out triggerWordLength)) { 65 startPos = completionContext.Offset; 66 triggerWordLength = 0; 67 } 68 completionData = cce.GetCompletionData(startPos, true); 69 } else { 70 startPos = completionContext.Offset; 71 if (char.IsLetterOrDigit(completionChar) || completionChar == '_') { 72 if (startPos > 1 && char.IsLetterOrDigit(completionContext.Document.GetCharAt((startPos - 2)))) 73 return result; 74 completionData = cce.GetCompletionData(startPos, false); 75 triggerWordLength = 1; 76 } else { 77 completionData = cce.GetCompletionData(startPos, false); 78 triggerWordLength = 0; 79 } 80 } 81 82 result.TriggerWordLength = triggerWordLength; 83 result.TriggerWord = completionContext.Document.GetText(completionContext.Offset - triggerWordLength, triggerWordLength); 84 85 if (completionData.Any() && cce.AutoCompleteEmptyMatch) { 86 foreach (var completion in completionData) { 87 var cast = completion as CompletionData; 88 if (cast != null) { 89 cast.TriggerWord = result.TriggerWord; 90 cast.TriggerWordLength = result.TriggerWordLength; 91 result.CompletionData.Add(cast); 92 } 93 } 94 } 95 96 if (!controlSpace) { 97 var pce = new CSharpParameterCompletionEngine( 98 completionContext.Document, 99 completionContext.CompletionContextProvider, 100 completionFactory, 101 completionContext.ProjectContent, 102 completionContext.TypeResolveContextAtCaret 103 ); 104 105 var parameterDataProvider = pce.GetParameterDataProvider(completionContext.Offset, completionChar); 106 result.OverloadProvider = parameterDataProvider as IUpdatableOverloadProvider; 107 } 108 } catch { 109 // ignore exceptions thrown during code completion 106 110 } 107 111
Note: See TracChangeset
for help on using the changeset viewer.