19 changed files with 380 additions and 116 deletions
@ -1,33 +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; |
|
||||||
using ICSharpCode.NRefactory.Completion; |
|
||||||
using ICSharpCode.NRefactory.CSharp.Completion; |
|
||||||
using ICSharpCode.SharpDevelop.Editor; |
|
||||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
|
||||||
|
|
||||||
namespace CSharpBinding |
|
||||||
{ |
|
||||||
public class CSharpCompletionBinding : ICodeCompletionBinding |
|
||||||
{ |
|
||||||
public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch) |
|
||||||
{ |
|
||||||
return CodeCompletionKeyPressResult.None; |
|
||||||
} |
|
||||||
|
|
||||||
public bool HandleKeyPressed(ITextEditor editor, char ch) |
|
||||||
{ |
|
||||||
if (ch == '.') |
|
||||||
return CtrlSpace(editor); |
|
||||||
else |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
public bool CtrlSpace(ITextEditor editor) |
|
||||||
{ |
|
||||||
return false; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
@ -0,0 +1,72 @@ |
|||||||
|
// 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.Linq; |
||||||
|
using CSharpBinding.Parser; |
||||||
|
using ICSharpCode.NRefactory.Completion; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Completion; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||||
|
using ICSharpCode.SharpDevelop.Parser; |
||||||
|
|
||||||
|
namespace CSharpBinding.Completion |
||||||
|
{ |
||||||
|
public class CSharpCompletionBinding : ICodeCompletionBinding |
||||||
|
{ |
||||||
|
public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch) |
||||||
|
{ |
||||||
|
// We use HandleKeyPressed instead.
|
||||||
|
return CodeCompletionKeyPressResult.None; |
||||||
|
} |
||||||
|
|
||||||
|
public bool HandleKeyPressed(ITextEditor editor, char ch) |
||||||
|
{ |
||||||
|
// Don't require the very latest parse information, an older cached version is OK.
|
||||||
|
var parseInfo = ParserService.GetCachedParseInformation(editor.FileName) as CSharpFullParseInformation; |
||||||
|
if (parseInfo == null) { |
||||||
|
parseInfo = ParserService.Parse(editor.FileName, editor.Document) as CSharpFullParseInformation; |
||||||
|
if (parseInfo == null) |
||||||
|
return false; |
||||||
|
} |
||||||
|
ICompilation compilation = ParserService.GetCompilationForFile(editor.FileName); |
||||||
|
var pc = compilation.MainAssembly.UnresolvedAssembly as IProjectContent; |
||||||
|
if (pc == null) |
||||||
|
return false; |
||||||
|
|
||||||
|
CSharpCompletionEngine cc = new CSharpCompletionEngine( |
||||||
|
editor.Document, |
||||||
|
new CSharpCompletionDataFactory(), |
||||||
|
pc, |
||||||
|
parseInfo.ParsedFile.GetTypeResolveContext(compilation, editor.Caret.Location), |
||||||
|
parseInfo.CompilationUnit, |
||||||
|
parseInfo.ParsedFile |
||||||
|
); |
||||||
|
//cc.FormattingPolicy = ?
|
||||||
|
cc.EolMarker = DocumentUtilitites.GetLineTerminator(editor.Document, editor.Caret.Line); |
||||||
|
//cc.IndentString = ?
|
||||||
|
DefaultCompletionItemList list = new DefaultCompletionItemList(); |
||||||
|
|
||||||
|
if (char.IsLetterOrDigit (ch) || ch == '_') { |
||||||
|
//if (completionContext.TriggerOffset > 1 && char.IsLetterOrDigit (document.Editor.GetCharAt (completionContext.TriggerOffset - 2)))
|
||||||
|
// return null;
|
||||||
|
list.PreselectionLength = 1; |
||||||
|
} |
||||||
|
list.Items.AddRange(cc.GetCompletionData(editor.Caret.Offset, false).Cast<ICompletionItem>()); |
||||||
|
if (list.Items.Count > 0) { |
||||||
|
list.SortItems(); |
||||||
|
list.SuggestedItem = list.Items.FirstOrDefault(i => i.Text == cc.DefaultCompletionString); |
||||||
|
editor.ShowCompletionWindow(list); |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public bool CtrlSpace(ITextEditor editor) |
||||||
|
{ |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,107 @@ |
|||||||
|
// 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 ICSharpCode.NRefactory.Completion; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Completion; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
|
||||||
|
namespace CSharpBinding.Completion |
||||||
|
{ |
||||||
|
class CSharpCompletionDataFactory : ICompletionDataFactory |
||||||
|
{ |
||||||
|
public ICompletionData CreateEntityCompletionData(IUnresolvedEntity entity) |
||||||
|
{ |
||||||
|
return new CompletionData(entity.Name) { |
||||||
|
Image = ClassBrowserIconService.GetIcon(entity) |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
public ICompletionData CreateEntityCompletionData(IUnresolvedEntity entity, string text) |
||||||
|
{ |
||||||
|
return new CompletionData(text) { |
||||||
|
Image = ClassBrowserIconService.GetIcon(entity) |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
public ICompletionData CreateEntityCompletionData(IEntity entity) |
||||||
|
{ |
||||||
|
return new EntityCompletionData(entity); |
||||||
|
} |
||||||
|
|
||||||
|
public ICompletionData CreateEntityCompletionData(IEntity entity, string text) |
||||||
|
{ |
||||||
|
return new EntityCompletionData(entity) { |
||||||
|
CompletionText = text, |
||||||
|
DisplayText = text |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
public ICompletionData CreateTypeCompletionData(IType type, string shortType) |
||||||
|
{ |
||||||
|
return new CompletionData(shortType); |
||||||
|
} |
||||||
|
|
||||||
|
public ICompletionData CreateTypeCompletionData(IUnresolvedTypeDefinition type, string shortType) |
||||||
|
{ |
||||||
|
return new CompletionData(shortType) { |
||||||
|
Image = ClassBrowserIconService.GetIcon(type) |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
public ICompletionData CreateLiteralCompletionData(string title, string description, string insertText) |
||||||
|
{ |
||||||
|
return new CompletionData(title) { |
||||||
|
Description = description, |
||||||
|
CompletionText = insertText ?? title, |
||||||
|
Image = ClassBrowserIconService.Keyword |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
public ICompletionData CreateNamespaceCompletionData(string name) |
||||||
|
{ |
||||||
|
return new CompletionData(name) { |
||||||
|
Image = ClassBrowserIconService.Namespace |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
public ICompletionData CreateVariableCompletionData(IVariable variable) |
||||||
|
{ |
||||||
|
return new CompletionData(variable.Name) { |
||||||
|
Image = ClassBrowserIconService.LocalVariable |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
public ICompletionData CreateVariableCompletionData(IUnresolvedTypeParameter parameter) |
||||||
|
{ |
||||||
|
return new CompletionData(parameter.Name); |
||||||
|
} |
||||||
|
|
||||||
|
public ICompletionData CreateEventCreationCompletionData(string varName, IType delegateType, IEvent evt, string parameterDefinition, IUnresolvedMember currentMember, IUnresolvedTypeDefinition currentType) |
||||||
|
{ |
||||||
|
throw new NotImplementedException(); |
||||||
|
} |
||||||
|
|
||||||
|
public ICompletionData CreateNewOverrideCompletionData(int declarationBegin, IUnresolvedTypeDefinition type, IMember m) |
||||||
|
{ |
||||||
|
throw new NotImplementedException(); |
||||||
|
} |
||||||
|
|
||||||
|
public ICompletionData CreateNewPartialCompletionData(int declarationBegin, IUnresolvedTypeDefinition type, IUnresolvedMember m) |
||||||
|
{ |
||||||
|
throw new NotImplementedException(); |
||||||
|
} |
||||||
|
|
||||||
|
public IEnumerable<ICompletionData> CreateCodeTemplateCompletionData() |
||||||
|
{ |
||||||
|
yield break; |
||||||
|
} |
||||||
|
|
||||||
|
public IEnumerable<ICompletionData> CreatePreProcessorDefinesCompletionData() |
||||||
|
{ |
||||||
|
yield break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,67 @@ |
|||||||
|
// 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 ICSharpCode.NRefactory; |
||||||
|
using ICSharpCode.NRefactory.Completion; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||||
|
|
||||||
|
namespace CSharpBinding.Completion |
||||||
|
{ |
||||||
|
class CompletionData : ICompletionData, ICompletionItem, IFancyCompletionItem |
||||||
|
{ |
||||||
|
public CompletionData(string text = "") |
||||||
|
{ |
||||||
|
this.DisplayText = text; |
||||||
|
this.CompletionText = text; |
||||||
|
} |
||||||
|
|
||||||
|
public CompletionCategory CompletionCategory { get; set; } |
||||||
|
public string DisplayText { get; set; } |
||||||
|
public string Description { get; set; } |
||||||
|
public string CompletionText { get; set; } |
||||||
|
|
||||||
|
DisplayFlags displayFlags; |
||||||
|
DisplayFlags ICompletionData.DisplayFlags { |
||||||
|
get { return displayFlags; } |
||||||
|
set { displayFlags = value; } |
||||||
|
} |
||||||
|
|
||||||
|
public virtual bool HasOverloads { get { return false; } } |
||||||
|
|
||||||
|
public virtual IEnumerable<ICompletionData> OverloadedData { |
||||||
|
get { return EmptyList<ICompletionData>.Instance; } |
||||||
|
} |
||||||
|
|
||||||
|
public virtual void AddOverload(ICompletionData data) |
||||||
|
{ |
||||||
|
throw new InvalidOperationException(); |
||||||
|
} |
||||||
|
|
||||||
|
string ICompletionItem.Text { |
||||||
|
get { return this.CompletionText; } |
||||||
|
} |
||||||
|
|
||||||
|
public IImage Image { get; set; } |
||||||
|
|
||||||
|
public virtual double Priority { |
||||||
|
get { return 0; } |
||||||
|
} |
||||||
|
|
||||||
|
public virtual void Complete(CompletionContext context) |
||||||
|
{ |
||||||
|
context.Editor.Document.Replace(context.StartOffset, context.Length, this.CompletionText); |
||||||
|
context.EndOffset = context.StartOffset + this.CompletionText.Length; |
||||||
|
} |
||||||
|
|
||||||
|
object IFancyCompletionItem.Content { |
||||||
|
get { return this.DisplayText; } |
||||||
|
} |
||||||
|
|
||||||
|
object IFancyCompletionItem.Description { |
||||||
|
get { return this.Description; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
// 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 ICSharpCode.NRefactory.Completion; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
|
||||||
|
namespace CSharpBinding.Completion |
||||||
|
{ |
||||||
|
class EntityCompletionData : CompletionData, IEntityCompletionData |
||||||
|
{ |
||||||
|
readonly IEntity entity; |
||||||
|
|
||||||
|
public IEntity Entity { |
||||||
|
get { return entity; } |
||||||
|
} |
||||||
|
|
||||||
|
public EntityCompletionData(IEntity entity) |
||||||
|
{ |
||||||
|
this.entity = entity; |
||||||
|
this.CompletionText = entity.Name; |
||||||
|
this.DisplayText = entity.Name; |
||||||
|
this.Description = entity.Documentation; |
||||||
|
this.Image = ClassBrowserIconService.GetIcon(entity); |
||||||
|
} |
||||||
|
|
||||||
|
List<ICompletionData> overloads = new List<ICompletionData>(); |
||||||
|
|
||||||
|
public override void AddOverload(ICompletionData data) |
||||||
|
{ |
||||||
|
overloads.Add(data); |
||||||
|
} |
||||||
|
|
||||||
|
public override bool HasOverloads { |
||||||
|
get { return overloads.Count > 0; } |
||||||
|
} |
||||||
|
|
||||||
|
public override IEnumerable<ICompletionData> OverloadedData { |
||||||
|
get { return overloads; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
// 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.Threading; |
||||||
|
using ICSharpCode.NRefactory.CSharp; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||||
|
using ICSharpCode.NRefactory.CSharp.TypeSystem; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.SharpDevelop.Parser; |
||||||
|
|
||||||
|
namespace CSharpBinding.Parser |
||||||
|
{ |
||||||
|
public class CSharpFullParseInformation : ParseInformation |
||||||
|
{ |
||||||
|
readonly CompilationUnit compilationUnit; |
||||||
|
|
||||||
|
public CSharpFullParseInformation(CSharpParsedFile parsedFile, CompilationUnit compilationUnit) |
||||||
|
: base(parsedFile, isFullParseInformation: true) |
||||||
|
{ |
||||||
|
if (parsedFile == null) |
||||||
|
throw new ArgumentNullException("parsedFile"); |
||||||
|
if (compilationUnit == null) |
||||||
|
throw new ArgumentNullException("compilationUnit"); |
||||||
|
this.compilationUnit = compilationUnit; |
||||||
|
} |
||||||
|
|
||||||
|
public new CSharpParsedFile ParsedFile { |
||||||
|
get { return (CSharpParsedFile)base.ParsedFile; } |
||||||
|
} |
||||||
|
|
||||||
|
public CompilationUnit CompilationUnit { |
||||||
|
get { return compilationUnit; } |
||||||
|
} |
||||||
|
|
||||||
|
public CSharpAstResolver GetResolver(ICompilation compilation) |
||||||
|
{ |
||||||
|
return (CSharpAstResolver)compilation.CacheManager.GetOrAddShared( |
||||||
|
this, _ => new CSharpAstResolver(compilation, compilationUnit, ParsedFile) |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,26 +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; |
|
||||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// <see cref="ICompletionItemList" /> created by <see cref="NRefactoryCtrlSpaceCompletionItemProvider" />.
|
|
||||||
/// </summary>
|
|
||||||
public class NRefactoryCompletionItemList : DefaultCompletionItemList |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// <see cref="NRefactoryCtrlSpaceCompletionItemProvider" /> sets this to true if this list contains items
|
|
||||||
/// from all namespaces, regardless of current imports.
|
|
||||||
/// </summary>
|
|
||||||
public bool ContainsItemsFromAllNamespaces { get; set; } |
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool ContainsAllAvailableItems |
|
||||||
{ |
|
||||||
get { return ContainsItemsFromAllNamespaces; } |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue