8 changed files with 268 additions and 101 deletions
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using CSharpBinding.Parser; |
||||
using ICSharpCode.NRefactory.CSharp.Completion; |
||||
using ICSharpCode.NRefactory.CSharp.TypeSystem; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace CSharpBinding.Completion |
||||
{ |
||||
sealed class CSharpCompletionContext |
||||
{ |
||||
public readonly ITextEditor Editor; |
||||
public readonly CSharpFullParseInformation ParseInformation; |
||||
public readonly ICompilation Compilation; |
||||
public readonly IProjectContent ProjectContent; |
||||
public readonly CSharpTypeResolveContext TypeResolveContextAtCaret; |
||||
public readonly ICompletionContextProvider CompletionContextProvider; |
||||
|
||||
public static CSharpCompletionContext Get(ITextEditor editor) |
||||
{ |
||||
// Don't require the very latest parse information, an older cached version is OK.
|
||||
var parseInfo = SD.ParserService.GetCachedParseInformation(editor.FileName) as CSharpFullParseInformation; |
||||
if (parseInfo == null) { |
||||
parseInfo = SD.ParserService.Parse(editor.FileName, editor.Document) as CSharpFullParseInformation; |
||||
} |
||||
if (parseInfo == null) |
||||
return null; |
||||
|
||||
ICompilation compilation = SD.ParserService.GetCompilationForFile(editor.FileName); |
||||
var projectContent = compilation.MainAssembly.UnresolvedAssembly as IProjectContent; |
||||
if (projectContent == null) |
||||
return null; |
||||
|
||||
return new CSharpCompletionContext(editor, parseInfo, compilation, projectContent); |
||||
} |
||||
|
||||
private CSharpCompletionContext(ITextEditor editor, CSharpFullParseInformation parseInfo, ICompilation compilation, IProjectContent projectContent) |
||||
{ |
||||
Debug.Assert(editor != null); |
||||
Debug.Assert(parseInfo != null); |
||||
Debug.Assert(compilation != null); |
||||
Debug.Assert(projectContent != null); |
||||
this.Editor = editor; |
||||
this.ParseInformation = parseInfo; |
||||
this.Compilation = compilation; |
||||
this.ProjectContent = projectContent; |
||||
this.TypeResolveContextAtCaret = parseInfo.ParsedFile.GetTypeResolveContext(compilation, editor.Caret.Location); |
||||
this.CompletionContextProvider = new DefaultCompletionContextProvider(editor.Document, parseInfo.ParsedFile); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,110 @@
@@ -0,0 +1,110 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.NRefactory.Completion; |
||||
using ICSharpCode.NRefactory.CSharp.Completion; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
|
||||
namespace CSharpBinding.Completion |
||||
{ |
||||
sealed class CSharpMethodInsight : IParameterDataProvider |
||||
{ |
||||
readonly int startOffset; |
||||
internal readonly IReadOnlyList<CSharpInsightItem> items; |
||||
readonly CSharpCompletionBinding binding; |
||||
readonly ITextEditor editor; |
||||
IInsightWindow window; |
||||
|
||||
public CSharpMethodInsight(CSharpCompletionBinding binding, ITextEditor editor, int startOffset, IEnumerable<CSharpInsightItem> items) |
||||
{ |
||||
Debug.Assert(binding != null); |
||||
Debug.Assert(editor != null); |
||||
Debug.Assert(items != null); |
||||
this.binding = binding; |
||||
this.editor = editor; |
||||
this.startOffset = startOffset; |
||||
this.items = items.ToList(); |
||||
} |
||||
|
||||
public void Show() |
||||
{ |
||||
window = editor.ShowInsightWindow(items); |
||||
window.StartOffset = startOffset; |
||||
// closing the window at the end of the parameter list is handled by the CaretPositionChanged event
|
||||
window.EndOffset = editor.Document.TextLength; |
||||
window.CaretPositionChanged += window_CaretPositionChanged; |
||||
} |
||||
|
||||
void window_CaretPositionChanged(object sender, EventArgs e) |
||||
{ |
||||
var completionContext = CSharpCompletionContext.Get(editor); |
||||
if (completionContext == null) { |
||||
window.Close(); |
||||
return; |
||||
} |
||||
var completionFactory = new CSharpCompletionDataFactory(binding, editor, completionContext.TypeResolveContextAtCaret); |
||||
var pce = new CSharpParameterCompletionEngine( |
||||
editor.Document, |
||||
completionContext.CompletionContextProvider, |
||||
completionFactory, |
||||
completionContext.ProjectContent, |
||||
completionContext.TypeResolveContextAtCaret |
||||
); |
||||
UpdateHighlightedParameter(pce); |
||||
} |
||||
|
||||
public void UpdateHighlightedParameter(CSharpParameterCompletionEngine pce) |
||||
{ |
||||
int parameterIndex = pce.GetCurrentParameterIndex(window != null ? window.StartOffset : startOffset, editor.Caret.Offset); |
||||
if (parameterIndex < 0 && window != null) { |
||||
window.Close(); |
||||
} else { |
||||
if (parameterIndex > 0) |
||||
parameterIndex--; // NR returns 1-based parameter index
|
||||
foreach (var item in items) |
||||
item.HighlightParameter(parameterIndex); |
||||
} |
||||
} |
||||
|
||||
#region IParameterDataProvider implementation
|
||||
int IParameterDataProvider.Count { |
||||
get { return items.Count; } |
||||
} |
||||
|
||||
int IParameterDataProvider.StartOffset { |
||||
get { return startOffset; } |
||||
} |
||||
|
||||
string IParameterDataProvider.GetHeading(int overload, string[] parameterDescription, int currentParameter) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
string IParameterDataProvider.GetDescription(int overload, int currentParameter) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
string IParameterDataProvider.GetParameterDescription(int overload, int paramIndex) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
int IParameterDataProvider.GetParameterCount(int overload) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
bool IParameterDataProvider.AllowParameterList(int overload) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -1,14 +0,0 @@
@@ -1,14 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion |
||||
{ |
||||
public interface IInsightWindowHandler |
||||
{ |
||||
void InitializeOpenedInsightWindow(ITextEditor editor, IInsightWindow insightWindow); |
||||
bool InsightRefreshOnComma(ITextEditor editor, char ch, out IInsightWindow insightWindow); |
||||
void HighlightParameter(IInsightWindow window, int index); |
||||
} |
||||
} |
Loading…
Reference in new issue