Browse Source

Remove code completion sample.

Add readme that links to two third party code completion samples
that use AvalonEdit and SharpDevelop DOM and NRefactory.
pull/39/merge
Matt Ward 12 years ago
parent
commit
0463ff4a40
  1. 33
      samples/CSharpCodeCompletion/AssemblyInfo.cs
  2. 85
      samples/CSharpCodeCompletion/CSharpCodeCompletion.csproj
  3. 18
      samples/CSharpCodeCompletion/CSharpCodeCompletion.sln
  4. 167
      samples/CSharpCodeCompletion/CodeCompletionData.cs
  5. 103
      samples/CSharpCodeCompletion/CodeCompletionKeyHandler.cs
  6. 166
      samples/CSharpCodeCompletion/CodeCompletionProvider.cs
  7. 65
      samples/CSharpCodeCompletion/HostCallbackImplementation.cs
  8. 101
      samples/CSharpCodeCompletion/MainForm.Designer.cs
  9. 203
      samples/CSharpCodeCompletion/MainForm.cs
  10. 191
      samples/CSharpCodeCompletion/MainForm.resx
  11. 150
      samples/CSharpCodeCompletion/ToolTipProvider.cs
  12. BIN
      samples/CSharpCodeCompletion/readme.rtf

33
samples/CSharpCodeCompletion/AssemblyInfo.cs

@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Information about this assembly is defined by the following
// attributes.
//
// change them to the information which is associated with the assembly
// you compile.
[assembly: AssemblyTitle("CSharpEditor")]
[assembly: AssemblyDescription("A small C# editor demonstrating code-completion" +
" using ICSharpCode.SharpDevelop.Dom and " +
"ICSharpCode.TextEditor")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ICSharpCode")]
[assembly: AssemblyProduct("CSharpEditor")]
[assembly: AssemblyCopyright("2006, Daniel Grunwald")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]
// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all values by your own or you can build default build and revision
// numbers with the '*' character (the default):
[assembly: AssemblyVersion("1.0.*")]

85
samples/CSharpCodeCompletion/CSharpCodeCompletion.csproj

@ -1,85 +0,0 @@ @@ -1,85 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<RootNamespace>CSharpEditor</RootNamespace>
<AssemblyName>CSharpCodeCompletion</AssemblyName>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}</ProjectGuid>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<Optimize>False</Optimize>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<Optimize>True</Optimize>
<DefineConstants>TRACE</DefineConstants>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>x86</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="ICSharpCode.NRefactory">
<HintPath>..\..\bin\ICSharpCode.NRefactory.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="ICSharpCode.SharpDevelop.Dom">
<HintPath>..\..\bin\ICSharpCode.SharpDevelop.Dom.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="ICSharpCode.TextEditor">
<HintPath>..\..\bin\ICSharpCode.TextEditor.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="log4net">
<HintPath>..\..\bin\log4net.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Mono.Cecil">
<HintPath>..\..\bin\Mono.Cecil.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CodeCompletionData.cs" />
<Compile Include="MainForm.cs" />
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="AssemblyInfo.cs" />
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<Compile Include="CodeCompletionProvider.cs" />
<Compile Include="CodeCompletionKeyHandler.cs" />
<Compile Include="HostCallbackImplementation.cs" />
<Compile Include="ToolTipProvider.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

18
samples/CSharpCodeCompletion/CSharpCodeCompletion.sln

@ -1,18 +0,0 @@ @@ -1,18 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.0.0.5571
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpCodeCompletion", "CSharpCodeCompletion.csproj", "{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Release|Any CPU.Build.0 = Release|Any CPU
{489CFE09-FDF7-4C89-BAB5-BD09CADD61AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
EndGlobal

167
samples/CSharpCodeCompletion/CodeCompletionData.cs

@ -1,167 +0,0 @@ @@ -1,167 +0,0 @@
/*
* Erstellt mit SharpDevelop.
* Benutzer: grunwald
* Datum: 27.08.2007
* Zeit: 14:25
*
* Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
*/
using System;
using System.IO;
using System.Text;
using System.Xml;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Dom.CSharp;
using ICSharpCode.SharpDevelop.Dom.VBNet;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
namespace CSharpEditor
{
/// <summary>
/// Represents an item in the code completion window.
/// </summary>
class CodeCompletionData : DefaultCompletionData, ICompletionData
{
IMember member;
IClass c;
static VBNetAmbience vbAmbience = new VBNetAmbience();
static CSharpAmbience csharpAmbience = new CSharpAmbience();
public CodeCompletionData(IMember member)
: base(member.Name, null, GetMemberImageIndex(member))
{
this.member = member;
}
public CodeCompletionData(IClass c)
: base(c.Name, null, GetClassImageIndex(c))
{
this.c = c;
}
int overloads = 0;
public void AddOverload()
{
overloads++;
}
static int GetMemberImageIndex(IMember member)
{
// Missing: different icons for private/public member
if (member is IMethod)
return 1;
if (member is IProperty)
return 2;
if (member is IField)
return 3;
if (member is IEvent)
return 6;
return 3;
}
static int GetClassImageIndex(IClass c)
{
switch (c.ClassType) {
case ClassType.Enum:
return 4;
default:
return 0;
}
}
string description;
// DefaultCompletionData.Description is not virtual, but we can reimplement
// the interface to get the same effect as overriding.
string ICompletionData.Description {
get {
if (description == null) {
IEntity entity = (IEntity)member ?? c;
description = GetText(entity);
if (overloads > 1) {
description += " (+" + overloads + " overloads)";
}
description += Environment.NewLine + XmlDocumentationToText(entity.Documentation);
}
return description;
}
}
/// <summary>
/// Converts a member to text.
/// Returns the declaration of the member as C# or VB code, e.g.
/// "public void MemberName(string parameter)"
/// </summary>
static string GetText(IEntity entity)
{
IAmbience ambience = MainForm.IsVisualBasic ? (IAmbience)vbAmbience : csharpAmbience;
if (entity is IMethod)
return ambience.Convert(entity as IMethod);
if (entity is IProperty)
return ambience.Convert(entity as IProperty);
if (entity is IEvent)
return ambience.Convert(entity as IEvent);
if (entity is IField)
return ambience.Convert(entity as IField);
if (entity is IClass)
return ambience.Convert(entity as IClass);
// unknown entity:
return entity.ToString();
}
public static string XmlDocumentationToText(string xmlDoc)
{
System.Diagnostics.Debug.WriteLine(xmlDoc);
StringBuilder b = new StringBuilder();
try {
using (XmlTextReader reader = new XmlTextReader(new StringReader("<root>" + xmlDoc + "</root>"))) {
reader.XmlResolver = null;
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Text:
b.Append(reader.Value);
break;
case XmlNodeType.Element:
switch (reader.Name) {
case "filterpriority":
reader.Skip();
break;
case "returns":
b.AppendLine();
b.Append("Returns: ");
break;
case "param":
b.AppendLine();
b.Append(reader.GetAttribute("name") + ": ");
break;
case "remarks":
b.AppendLine();
b.Append("Remarks: ");
break;
case "see":
if (reader.IsEmptyElement) {
b.Append(reader.GetAttribute("cref"));
} else {
reader.MoveToContent();
if (reader.HasValue) {
b.Append(reader.Value);
} else {
b.Append(reader.GetAttribute("cref"));
}
}
break;
}
break;
}
}
}
return b.ToString();
} catch (XmlException) {
return xmlDoc;
}
}
}
}

103
samples/CSharpCodeCompletion/CodeCompletionKeyHandler.cs

@ -1,103 +0,0 @@ @@ -1,103 +0,0 @@
// CSharp Editor Example with Code Completion
// Copyright (c) 2006, Daniel Grunwald
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this list
// of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// - Neither the name of the ICSharpCode team nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &AS IS& AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Gui;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
namespace CSharpEditor
{
class CodeCompletionKeyHandler
{
MainForm mainForm;
TextEditorControl editor;
CodeCompletionWindow codeCompletionWindow;
private CodeCompletionKeyHandler(MainForm mainForm, TextEditorControl editor)
{
this.mainForm = mainForm;
this.editor = editor;
}
public static CodeCompletionKeyHandler Attach(MainForm mainForm, TextEditorControl editor)
{
CodeCompletionKeyHandler h = new CodeCompletionKeyHandler(mainForm, editor);
editor.ActiveTextAreaControl.TextArea.KeyEventHandler += h.TextAreaKeyEventHandler;
// When the editor is disposed, close the code completion window
editor.Disposed += h.CloseCodeCompletionWindow;
return h;
}
/// <summary>
/// Return true to handle the keypress, return false to let the text area handle the keypress
/// </summary>
bool TextAreaKeyEventHandler(char key)
{
if (codeCompletionWindow != null) {
// If completion window is open and wants to handle the key, don't let the text area
// handle it
if (codeCompletionWindow.ProcessKeyEvent(key))
return true;
}
if (key == '.') {
ICompletionDataProvider completionDataProvider = new CodeCompletionProvider(mainForm);
codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(
mainForm, // The parent window for the completion window
editor, // The text editor to show the window for
MainForm.DummyFileName, // Filename - will be passed back to the provider
completionDataProvider, // Provider to get the list of possible completions
key // Key pressed - will be passed to the provider
);
if (codeCompletionWindow != null) {
// ShowCompletionWindow can return null when the provider returns an empty list
codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
}
}
return false;
}
void CloseCodeCompletionWindow(object sender, EventArgs e)
{
if (codeCompletionWindow != null) {
codeCompletionWindow.Closed -= new EventHandler(CloseCodeCompletionWindow);
codeCompletionWindow.Dispose();
codeCompletionWindow = null;
}
}
}
}

166
samples/CSharpCodeCompletion/CodeCompletionProvider.cs

@ -1,166 +0,0 @@ @@ -1,166 +0,0 @@
// CSharp Editor Example with Code Completion
// Copyright (c) 2006, Daniel Grunwald
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this list
// of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// - Neither the name of the ICSharpCode team nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &AS IS& AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using Dom = ICSharpCode.SharpDevelop.Dom;
using NRefactoryResolver = ICSharpCode.SharpDevelop.Dom.NRefactoryResolver.NRefactoryResolver;
namespace CSharpEditor
{
class CodeCompletionProvider : ICompletionDataProvider
{
MainForm mainForm;
public CodeCompletionProvider(MainForm mainForm)
{
this.mainForm = mainForm;
}
public ImageList ImageList {
get {
return mainForm.imageList1;
}
}
public string PreSelection {
get {
return null;
}
}
public int DefaultIndex {
get {
return -1;
}
}
public CompletionDataProviderKeyResult ProcessKey(char key)
{
if (char.IsLetterOrDigit(key) || key == '_') {
return CompletionDataProviderKeyResult.NormalKey;
} else {
// key triggers insertion of selected items
return CompletionDataProviderKeyResult.InsertionKey;
}
}
/// <summary>
/// Called when entry should be inserted. Forward to the insertion action of the completion data.
/// </summary>
public bool InsertAction(ICompletionData data, TextArea textArea, int insertionOffset, char key)
{
textArea.Caret.Position = textArea.Document.OffsetToPosition(insertionOffset);
return data.InsertAction(textArea, key);
}
public ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
{
// We can return code-completion items like this:
//return new ICompletionData[] {
// new DefaultCompletionData("Text", "Description", 1)
//};
NRefactoryResolver resolver = new NRefactoryResolver(mainForm.myProjectContent.Language);
Dom.ResolveResult rr = resolver.Resolve(FindExpression(textArea),
mainForm.parseInformation,
textArea.MotherTextEditorControl.Text);
List<ICompletionData> resultList = new List<ICompletionData>();
if (rr != null) {
var completionData = rr.GetCompletionData(mainForm.myProjectContent);
if (completionData != null) {
AddCompletionData(resultList, completionData);
}
}
return resultList.ToArray();
}
/// <summary>
/// Find the expression the cursor is at.
/// Also determines the context (using statement, "new"-expression etc.) the
/// cursor is at.
/// </summary>
Dom.ExpressionResult FindExpression(TextArea textArea)
{
Dom.IExpressionFinder finder;
if (MainForm.IsVisualBasic) {
finder = new Dom.VBNet.VBExpressionFinder();
} else {
finder = new Dom.CSharp.CSharpExpressionFinder(mainForm.parseInformation);
}
Dom.ExpressionResult expression = finder.FindExpression(textArea.Document.TextContent, textArea.Caret.Offset);
if (expression.Region.IsEmpty) {
expression.Region = new Dom.DomRegion(textArea.Caret.Line + 1, textArea.Caret.Column + 1);
}
return expression;
}
void AddCompletionData(List<ICompletionData> resultList, IEnumerable<Dom.ICompletionEntry> completionData)
{
// used to store the method names for grouping overloads
Dictionary<string, CodeCompletionData> nameDictionary = new Dictionary<string, CodeCompletionData>();
// Add the completion data as returned by SharpDevelop.Dom to the
// list for the text editor
foreach (object obj in completionData) {
if (obj is Dom.NamespaceEntry) {
resultList.Add(new DefaultCompletionData(obj.ToString(), "namespace " + obj, 5));
} else if (obj is Dom.NRefactoryResolver.KeywordEntry) {
resultList.Add(new DefaultCompletionData(obj.ToString(), obj.ToString(), 5));
} else if (obj is Dom.IClass) {
Dom.IClass c = (Dom.IClass)obj;
resultList.Add(new CodeCompletionData(c));
} else if (obj is Dom.IMember) {
Dom.IMember m = (Dom.IMember)obj;
if (m is Dom.IMethod && ((m as Dom.IMethod).IsConstructor)) {
// Skip constructors
continue;
}
// Group results by name and add "(x Overloads)" to the
// description if there are multiple results with the same name.
CodeCompletionData data;
if (nameDictionary.TryGetValue(m.Name, out data)) {
data.AddOverload();
} else {
nameDictionary[m.Name] = data = new CodeCompletionData(m);
resultList.Add(data);
}
} else {
// Current ICSharpCode.SharpDevelop.Dom should never return anything else
throw new NotSupportedException();
}
}
}
}
}

65
samples/CSharpCodeCompletion/HostCallbackImplementation.cs

@ -1,65 +0,0 @@ @@ -1,65 +0,0 @@
// CSharp Editor Example with Code Completion
// Copyright (c) 2006, Daniel Grunwald
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this list
// of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// - Neither the name of the ICSharpCode team nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &AS IS& AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop.Dom;
namespace CSharpEditor
{
/// <summary>
/// ICSharpCode.SharpDevelop.Dom was created by extracting code from ICSharpCode.SharpDevelop.dll.
/// There are a few static method calls that refer to GUI code or the code for keeping the parse
/// information. These calls have to be implemented by the application hosting
/// ICSharpCode.SharpDevelop.Dom by settings static fields with a delegate to their method
/// implementation.
/// </summary>
static class HostCallbackImplementation
{
public static void Register(MainForm mainForm)
{
// Must be implemented. Gets the project content of the active project.
HostCallback.GetCurrentProjectContent = delegate {
return mainForm.myProjectContent;
};
// The default implementation just logs to Log4Net. We want to display a MessageBox.
// Note that we use += here - in this case, we want to keep the default Log4Net implementation.
HostCallback.ShowError += delegate(string message, Exception ex) {
MessageBox.Show(message + Environment.NewLine + ex.ToString());
};
HostCallback.ShowMessage += delegate(string message) {
MessageBox.Show(message);
};
HostCallback.ShowAssemblyLoadError += delegate(string fileName, string include, string message) {
MessageBox.Show("Error loading code-completion information for "
+ include + " from " + fileName
+ ":\r\n" + message + "\r\n");
};
}
}
}

101
samples/CSharpCodeCompletion/MainForm.Designer.cs generated

@ -1,101 +0,0 @@ @@ -1,101 +0,0 @@
namespace CSharpEditor
{
partial class MainForm : System.Windows.Forms.Form
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Disposes resources used by the form.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.textEditorControl1 = new ICSharpCode.TextEditor.TextEditorControl();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.parserThreadLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// textEditorControl1
//
this.textEditorControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.textEditorControl1.IsIconBarVisible = false;
this.textEditorControl1.Location = new System.Drawing.Point(0, 0);
this.textEditorControl1.Name = "textEditorControl1";
this.textEditorControl1.ShowEOLMarkers = true;
this.textEditorControl1.ShowInvalidLines = false;
this.textEditorControl1.ShowSpaces = true;
this.textEditorControl1.ShowTabs = true;
this.textEditorControl1.ShowVRuler = true;
this.textEditorControl1.Size = new System.Drawing.Size(556, 248);
this.textEditorControl1.TabIndex = 0;
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.parserThreadLabel});
this.statusStrip1.Location = new System.Drawing.Point(0, 248);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(556, 22);
this.statusStrip1.TabIndex = 1;
this.statusStrip1.Text = "statusStrip1";
//
// parserThreadLabel
//
this.parserThreadLabel.Name = "parserThreadLabel";
this.parserThreadLabel.Size = new System.Drawing.Size(109, 17);
this.parserThreadLabel.Text = "toolStripStatusLabel1";
//
// imageList1
//
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
this.imageList1.Images.SetKeyName(0, "Icons.16x16.Class.png");
this.imageList1.Images.SetKeyName(1, "Icons.16x16.Method.png");
this.imageList1.Images.SetKeyName(2, "Icons.16x16.Property.png");
this.imageList1.Images.SetKeyName(3, "Icons.16x16.Field.png");
this.imageList1.Images.SetKeyName(4, "Icons.16x16.Enum.png");
this.imageList1.Images.SetKeyName(5, "Icons.16x16.NameSpace.png");
this.imageList1.Images.SetKeyName(6, "Icons.16x16.Event.png");
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(556, 270);
this.Controls.Add(this.textEditorControl1);
this.Controls.Add(this.statusStrip1);
this.Name = "MainForm";
this.Text = "CSharpEditor";
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
internal System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ToolStripStatusLabel parserThreadLabel;
private System.Windows.Forms.StatusStrip statusStrip1;
private ICSharpCode.TextEditor.TextEditorControl textEditorControl1;
}
}

203
samples/CSharpCodeCompletion/MainForm.cs

@ -1,203 +0,0 @@ @@ -1,203 +0,0 @@
// CSharp Editor Example with Code Completion
// Copyright (c) 2006, Daniel Grunwald
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this list
// of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// - Neither the name of the ICSharpCode team nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &AS IS& AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using NRefactory = ICSharpCode.NRefactory;
using Dom = ICSharpCode.SharpDevelop.Dom;
namespace CSharpEditor
{
partial class MainForm
{
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
internal Dom.ProjectContentRegistry pcRegistry;
internal Dom.DefaultProjectContent myProjectContent;
internal Dom.ParseInformation parseInformation;
Dom.ICompilationUnit lastCompilationUnit;
Thread parserThread;
public static bool IsVisualBasic = false;
/// <summary>
/// Many SharpDevelop.Dom methods take a file name, which is really just a unique identifier
/// for a file - Dom methods don't try to access code files on disk, so the file does not have
/// to exist.
/// SharpDevelop itself uses internal names of the kind "[randomId]/Class1.cs" to support
/// code-completion in unsaved files.
/// </summary>
public const string DummyFileName = "edited.cs";
static readonly Dom.LanguageProperties CurrentLanguageProperties = IsVisualBasic ? Dom.LanguageProperties.VBNet : Dom.LanguageProperties.CSharp;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
if (IsVisualBasic) {
textEditorControl1.Text = @"
Class A
Sub B
Dim xx As String
End Sub
End Class
";
textEditorControl1.SetHighlighting("VBNET");
} else {
textEditorControl1.Text = @"using System;
class A
{
void B()
{
string x;
}
}
";
textEditorControl1.SetHighlighting("C#");
}
textEditorControl1.ShowEOLMarkers = false;
textEditorControl1.ShowInvalidLines = false;
HostCallbackImplementation.Register(this);
CodeCompletionKeyHandler.Attach(this, textEditorControl1);
ToolTipProvider.Attach(this, textEditorControl1);
pcRegistry = new Dom.ProjectContentRegistry(); // Default .NET 2.0 registry
// Persistence lets SharpDevelop.Dom create a cache file on disk so that
// future starts are faster.
// It also caches XML documentation files in an on-disk hash table, thus
// reducing memory usage.
pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(),
"CSharpCodeCompletion"));
myProjectContent = new Dom.DefaultProjectContent();
myProjectContent.Language = CurrentLanguageProperties;
// create dummy parseInformation to prevent NullReferenceException when using CC before parsing
// for the first time
parseInformation = new Dom.ParseInformation(new Dom.DefaultCompilationUnit(myProjectContent));
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
parserThread = new Thread(ParserThread);
parserThread.IsBackground = true;
parserThread.Start();
}
void ParserThread()
{
BeginInvoke(new MethodInvoker(delegate { parserThreadLabel.Text = "Loading mscorlib..."; }));
myProjectContent.AddReferencedContent(pcRegistry.Mscorlib);
// do one initial parser step to enable code-completion while other
// references are loading
ParseStep();
string[] referencedAssemblies = {
"System", "System.Data", "System.Drawing", "System.Xml", "System.Windows.Forms", "Microsoft.VisualBasic"
};
foreach (string assemblyName in referencedAssemblies) {
string assemblyNameCopy = assemblyName; // copy for anonymous method
BeginInvoke(new MethodInvoker(delegate { parserThreadLabel.Text = "Loading " + assemblyNameCopy + "..."; }));
Dom.IProjectContent referenceProjectContent = pcRegistry.GetProjectContentForReference(assemblyName, assemblyName);
myProjectContent.AddReferencedContent(referenceProjectContent);
if (referenceProjectContent is Dom.ReflectionProjectContent) {
(referenceProjectContent as Dom.ReflectionProjectContent).InitializeReferences();
}
}
if (IsVisualBasic) {
myProjectContent.DefaultImports = new Dom.DefaultUsing(myProjectContent);
myProjectContent.DefaultImports.Usings.Add("System");
myProjectContent.DefaultImports.Usings.Add("System.Text");
myProjectContent.DefaultImports.Usings.Add("Microsoft.VisualBasic");
}
BeginInvoke(new MethodInvoker(delegate { parserThreadLabel.Text = "Ready"; }));
// Parse the current file every 2 seconds
while (!IsDisposed) {
ParseStep();
Thread.Sleep(2000);
}
}
void ParseStep()
{
string code = null;
Invoke(new MethodInvoker(delegate {
code = textEditorControl1.Text;
}));
TextReader textReader = new StringReader(code);
Dom.ICompilationUnit newCompilationUnit;
NRefactory.SupportedLanguage supportedLanguage;
if (IsVisualBasic)
supportedLanguage = NRefactory.SupportedLanguage.VBNet;
else
supportedLanguage = NRefactory.SupportedLanguage.CSharp;
using (NRefactory.IParser p = NRefactory.ParserFactory.CreateParser(supportedLanguage, textReader)) {
// we only need to parse types and method definitions, no method bodies
// so speed up the parser and make it more resistent to syntax
// errors in methods
p.ParseMethodBodies = false;
p.Parse();
newCompilationUnit = ConvertCompilationUnit(p.CompilationUnit);
}
// Remove information from lastCompilationUnit and add information from newCompilationUnit.
myProjectContent.UpdateCompilationUnit(lastCompilationUnit, newCompilationUnit, DummyFileName);
lastCompilationUnit = newCompilationUnit;
parseInformation = new Dom.ParseInformation(newCompilationUnit);
}
Dom.ICompilationUnit ConvertCompilationUnit(NRefactory.Ast.CompilationUnit cu)
{
Dom.NRefactoryResolver.NRefactoryASTConvertVisitor converter;
converter = new Dom.NRefactoryResolver.NRefactoryASTConvertVisitor(myProjectContent);
cu.AcceptVisitor(converter, null);
return converter.Cu;
}
}
}

191
samples/CSharpCodeCompletion/MainForm.resx

@ -1,191 +0,0 @@ @@ -1,191 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="imageList1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>128, 17</value>
</metadata>
<data name="imageList1.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABk
DQAAAk1TRnQBSQFMAgEBBwEAAQkBAAEEAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAASADAAEBAQABCAYAAQgYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
AWYDAAGZAwABzAIAATMDAAIzAgABMwFmAgABMwGZAgABMwHMAgABMwH/AgABZgMAAWYBMwIAAmYCAAFm
AZkCAAFmAcwCAAFmAf8CAAGZAwABmQEzAgABmQFmAgACmQIAAZkBzAIAAZkB/wIAAcwDAAHMATMCAAHM
AWYCAAHMAZkCAALMAgABzAH/AgAB/wFmAgAB/wGZAgAB/wHMAQABMwH/AgAB/wEAATMBAAEzAQABZgEA
ATMBAAGZAQABMwEAAcwBAAEzAQAB/wEAAf8BMwIAAzMBAAIzAWYBAAIzAZkBAAIzAcwBAAIzAf8BAAEz
AWYCAAEzAWYBMwEAATMCZgEAATMBZgGZAQABMwFmAcwBAAEzAWYB/wEAATMBmQIAATMBmQEzAQABMwGZ
AWYBAAEzApkBAAEzAZkBzAEAATMBmQH/AQABMwHMAgABMwHMATMBAAEzA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BoAN6AlkBjAHPCQABkAG5AbgBgQEGBQABUQH7AVETAAEMAaUBgwkAAfQBHAF6AqACegF5AewB7wG1
CgABBgG4AQYHAAFRFQABYQsAAfQDHAPsAbwB9wHvCwABBgQAAUIBTQE+BwABPgMAASgDAAFAAwABIAMA
AQEBAAEBBgABARYAA/8BAAb/AgAG/wIABv8CAAL/AfMBnwHxAf8CAAGAAT8B5wHPAfAB/wMAAT8B5wHP
AfgBfwMAAT8B5wHPAfgBPwMAAT8B5wHPAfwBHwQAAc8B5wHwAQ8EAAHnAc8B+AEPBAAB5wHPAfgBHwQA
AecBzwH4AQ8CAAH8AQAB5wHPAfwBBwIAAfwBAAHzAZ8B/AEDAgAB/AEAAv8B/gEDAgAB/AEBBP8CAAH/
AfMH/wHhAv8BgAEHA/8BwAL/AQABBwP/AYAC/wEAAQcD/wEAAv8BAAEHA/8BMQL/AQABBwH/Ac8B/wEz
Af8B5wEAAQcBwQGHAecBIQHBAcMBAAEHAf8BAwHDAQAB/wGBAQABBgECAQEBgQEAAQMDAAH8AwAB/gMA
AUQCAAFxAUQBAQIAAf4BAAGAAfsB/gEDAgAB/wEBAcEC/wEHAfABAAH/AYMB4wL/AY8B+AEAAf8BxwH3
Av8B3wH8AQAB/wHvCw==
</value>
</data>
</root>

150
samples/CSharpCodeCompletion/ToolTipProvider.cs

@ -1,150 +0,0 @@ @@ -1,150 +0,0 @@
// CSharp Editor Example with Code Completion
// Copyright (c) 2007, Daniel Grunwald
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this list
// of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// - Neither the name of the ICSharpCode team nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &AS IS& AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Text;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Dom.CSharp;
using ICSharpCode.SharpDevelop.Dom.VBNet;
using TextEditor = ICSharpCode.TextEditor;
using NRefactoryResolver = ICSharpCode.SharpDevelop.Dom.NRefactoryResolver.NRefactoryResolver;
namespace CSharpEditor
{
sealed class ToolTipProvider
{
MainForm mainForm;
TextEditor.TextEditorControl editor;
private ToolTipProvider(MainForm mainForm, TextEditor.TextEditorControl editor)
{
this.mainForm = mainForm;
this.editor = editor;
}
public static void Attach(MainForm mainForm, TextEditor.TextEditorControl editor)
{
ToolTipProvider tp = new ToolTipProvider(mainForm, editor);
editor.ActiveTextAreaControl.TextArea.ToolTipRequest += tp.OnToolTipRequest;
}
void OnToolTipRequest(object sender, TextEditor.ToolTipRequestEventArgs e)
{
if (e.InDocument && !e.ToolTipShown) {
IExpressionFinder expressionFinder;
if (MainForm.IsVisualBasic) {
expressionFinder = new VBExpressionFinder();
} else {
expressionFinder = new CSharpExpressionFinder(mainForm.parseInformation);
}
ExpressionResult expression = expressionFinder.FindFullExpression(
editor.Text,
editor.Document.PositionToOffset(e.LogicalPosition));
if (expression.Region.IsEmpty) {
expression.Region = new DomRegion(e.LogicalPosition.Line + 1, e.LogicalPosition.Column + 1);
}
TextEditor.TextArea textArea = editor.ActiveTextAreaControl.TextArea;
NRefactoryResolver resolver = new NRefactoryResolver(mainForm.myProjectContent.Language);
ResolveResult rr = resolver.Resolve(expression,
mainForm.parseInformation,
textArea.MotherTextEditorControl.Text);
string toolTipText = GetText(rr);
if (toolTipText != null) {
e.ShowToolTip(toolTipText);
}
}
}
static string GetText(ResolveResult result)
{
if (result == null) {
return null;
}
if (result is MixedResolveResult)
return GetText(((MixedResolveResult)result).PrimaryResult);
IAmbience ambience = MainForm.IsVisualBasic ? (IAmbience)new VBNetAmbience() : new CSharpAmbience();
ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowAccessibility;
if (result is MemberResolveResult) {
return GetMemberText(ambience, ((MemberResolveResult)result).ResolvedMember);
} else if (result is LocalResolveResult) {
LocalResolveResult rr = (LocalResolveResult)result;
ambience.ConversionFlags = ConversionFlags.UseFullyQualifiedTypeNames
| ConversionFlags.ShowReturnType;
StringBuilder b = new StringBuilder();
if (rr.IsParameter)
b.Append("parameter ");
else
b.Append("local variable ");
b.Append(ambience.Convert(rr.Field));
return b.ToString();
} else if (result is NamespaceResolveResult) {
return "namespace " + ((NamespaceResolveResult)result).Name;
} else if (result is TypeResolveResult) {
IClass c = ((TypeResolveResult)result).ResolvedClass;
if (c != null)
return GetMemberText(ambience, c);
else
return ambience.Convert(result.ResolvedType);
} else if (result is MethodGroupResolveResult) {
MethodGroupResolveResult mrr = result as MethodGroupResolveResult;
IMethod m = mrr.GetMethodIfSingleOverload();
if (m != null)
return GetMemberText(ambience, m);
else
return "Overload of " + ambience.Convert(mrr.ContainingType) + "." + mrr.Name;
} else {
return null;
}
}
static string GetMemberText(IAmbience ambience, IEntity member)
{
StringBuilder text = new StringBuilder();
if (member is IField) {
text.Append(ambience.Convert(member as IField));
} else if (member is IProperty) {
text.Append(ambience.Convert(member as IProperty));
} else if (member is IEvent) {
text.Append(ambience.Convert(member as IEvent));
} else if (member is IMethod) {
text.Append(ambience.Convert(member as IMethod));
} else if (member is IClass) {
text.Append(ambience.Convert(member as IClass));
} else {
text.Append("unknown member ");
text.Append(member.ToString());
}
string documentation = member.Documentation;
if (documentation != null && documentation.Length > 0) {
text.Append('\n');
text.Append(CodeCompletionData.XmlDocumentationToText(documentation));
}
return text.ToString();
}
}
}

BIN
samples/CSharpCodeCompletion/readme.rtf

Binary file not shown.
Loading…
Cancel
Save