Browse Source

C# code completion

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
adda0ee18d
  1. 2
      SharpDevelop.sln
  2. 4
      src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin
  3. 10
      src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj
  4. 33
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs
  5. 14
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighter.cs
  6. 72
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs
  7. 107
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionDataFactory.cs
  8. 67
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CompletionData.cs
  9. 44
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EntityCompletionData.cs
  10. 2
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/BuildOptions.cs
  11. 43
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpFullParseInformation.cs
  12. 9
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs
  13. 25
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs
  14. 12
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
  15. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  16. 2
      src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionBinding.cs
  17. 9
      src/Main/Base/Project/Src/Editor/CodeCompletion/ICompletionItemList.cs
  18. 26
      src/Main/Base/Project/Src/Editor/CodeCompletion/NRefactoryCompletionItemList.cs
  19. 14
      src/Main/Base/Project/Src/Services/ParserService/ParseInformation.cs

2
SharpDevelop.sln

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 11.00 Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010 # Visual Studio 2010
# SharpDevelop 4.1.0.7887-beta # SharpDevelop 4.2.0.8528-beta
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Main", "Main", "{256F5C28-532C-44C0-8AB8-D8EC5E492E01}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Main", "Main", "{256F5C28-532C-44C0-8AB8-D8EC5E492E01}"
ProjectSection(SolutionItems) = postProject ProjectSection(SolutionItems) = postProject
EndProjectSection EndProjectSection

4
src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin

@ -55,7 +55,7 @@
</Path> </Path>
<Path name = "/SharpDevelop/ViewContent/TextEditor/CodeCompletion"> <Path name = "/SharpDevelop/ViewContent/TextEditor/CodeCompletion">
<CodeCompletionBinding id = "CSharp" extensions = ".cs" class = "CSharpBinding.CSharpCompletionBinding"/> <CodeCompletionBinding id = "CSharp" extensions = ".cs" class = "CSharpBinding.Completion.CSharpCompletionBinding"/>
</Path> </Path>
<Path name="/SharpDevelop/Workbench/LanguageBindings"> <Path name="/SharpDevelop/Workbench/LanguageBindings">
@ -66,7 +66,7 @@
</Path> </Path>
<Path name = "/SharpDevelop/ViewContent/AvalonEdit/SyntaxModes"> <Path name = "/SharpDevelop/ViewContent/AvalonEdit/SyntaxModes">
<SyntaxMode id="C#" name="C#" extensions=".cs" resource="Resources.CSharp-Semantic.xshd" /> <SyntaxMode id="C#" name="C#" extensions=".cs" resource="CSharpBinding.Resources.CSharp-Semantic.xshd" />
</Path> </Path>
<Path path = "/SharpDevelop/BackendBindings/ProjectOptions/C#"> <Path path = "/SharpDevelop/BackendBindings/ProjectOptions/C#">

10
src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj

@ -24,6 +24,7 @@
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TargetFrameworkProfile> <TargetFrameworkProfile>
</TargetFrameworkProfile> </TargetFrameworkProfile>
<RootNamespace>CSharpBinding</RootNamespace>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@ -68,6 +69,10 @@
<EmbeddedResource Include="Resources\BuildOptions.xfrm" /> <EmbeddedResource Include="Resources\BuildOptions.xfrm" />
<EmbeddedResource Include="Resources\MyNamespaceSupportForCSharp.cs" /> <EmbeddedResource Include="Resources\MyNamespaceSupportForCSharp.cs" />
<Compile Include="Src\CodeManipulation.cs" /> <Compile Include="Src\CodeManipulation.cs" />
<Compile Include="Src\Completion\CompletionData.cs" />
<Compile Include="Src\Completion\CSharpCompletionBinding.cs" />
<Compile Include="Src\Completion\CSharpCompletionDataFactory.cs" />
<Compile Include="Src\Completion\EntityCompletionData.cs" />
<Compile Include="Src\CSharpBracketSearcher.cs" /> <Compile Include="Src\CSharpBracketSearcher.cs" />
<Compile Include="Src\CSharpLanguageBinding.cs" /> <Compile Include="Src\CSharpLanguageBinding.cs" />
<Compile Include="Src\CSharpProjectBinding.cs" /> <Compile Include="Src\CSharpProjectBinding.cs" />
@ -77,6 +82,7 @@
<Compile Include="Src\OptionPanels\BuildOptions.cs"> <Compile Include="Src\OptionPanels\BuildOptions.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="Src\Parser\CSharpFullParseInformation.cs" />
<Compile Include="Src\Parser\CSharpSymbolSearch.cs" /> <Compile Include="Src\Parser\CSharpSymbolSearch.cs" />
<Compile Include="Src\Parser\Parser.cs" /> <Compile Include="Src\Parser\Parser.cs" />
<Compile Include="Src\Project\VBNetToCSharpConvertVisitorWithMyFormsSupport.cs" /> <Compile Include="Src\Project\VBNetToCSharpConvertVisitorWithMyFormsSupport.cs" />
@ -85,7 +91,6 @@
<None Include="CSharpBinding.addin"> <None Include="CSharpBinding.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
<Compile Include="Src\CSharpCompletionBinding.cs" />
<Compile Include="Src\Project\VBNetToCSharpConverter.cs" /> <Compile Include="Src\Project\VBNetToCSharpConverter.cs" />
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs"> <Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link> <Link>Configuration\GlobalAssemblyInfo.cs</Link>
@ -124,5 +129,8 @@
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Src\Completion" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project> </Project>

33
src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs

@ -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;
}
}
}

14
src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighter.cs

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using CSharpBinding.Parser;
using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.NRefactory; using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.CSharp;
@ -192,7 +193,7 @@ namespace CSharpBinding
return cachedLine.HighlightedLine; return cachedLine.HighlightedLine;
} }
ParseInformation parseInfo = ParserService.GetCachedParseInformation(textEditor.FileName, textEditor.Document.Version); var parseInfo = ParserService.GetCachedParseInformation(textEditor.FileName, textEditor.Document.Version) as CSharpFullParseInformation;
if (parseInfo == null) { if (parseInfo == null) {
if (!invalidLines.Contains(documentLine)) if (!invalidLines.Contains(documentLine))
invalidLines.Add(documentLine); invalidLines.Add(documentLine);
@ -208,20 +209,13 @@ namespace CSharpBinding
} }
} }
CSharpParsedFile parsedFile = parseInfo.ParsedFile as CSharpParsedFile;
CompilationUnit cu = parseInfo.Annotation<CompilationUnit>();
if (cu == null || parsedFile == null) {
Debug.WriteLine("Semantic highlighting for line {0} - not a C# file?", lineNumber);
return null;
}
var compilation = ParserService.GetCompilationForFile(parseInfo.FileName); var compilation = ParserService.GetCompilationForFile(parseInfo.FileName);
resolver = new CSharpAstResolver(compilation, cu, parsedFile); this.resolver = parseInfo.GetResolver(compilation);
HighlightedLine line = new HighlightedLine(textEditor.Document, documentLine); HighlightedLine line = new HighlightedLine(textEditor.Document, documentLine);
this.line = line; this.line = line;
this.lineNumber = lineNumber; this.lineNumber = lineNumber;
cu.AcceptVisitor(this); parseInfo.CompilationUnit.AcceptVisitor(this);
this.line = null; this.line = null;
this.resolver = null; this.resolver = null;
Debug.WriteLine("Semantic highlighting for line {0} - added {1} sections", lineNumber, line.Sections.Count); Debug.WriteLine("Semantic highlighting for line {0} - added {1} sections", lineNumber, line.Sections.Count);

72
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs

@ -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;
}
}
}

107
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionDataFactory.cs

@ -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;
}
}
}

67
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CompletionData.cs

@ -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; }
}
}
}

44
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EntityCompletionData.cs

@ -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; }
}
}
}

2
src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/BuildOptions.cs

@ -12,7 +12,7 @@ namespace CSharpBinding.OptionPanels
{ {
public override void LoadPanelContents() public override void LoadPanelContents()
{ {
SetupFromXmlResource("BuildOptions.xfrm"); SetupFromXmlResource("CSharpBinding.BuildOptions.xfrm");
InitializeHelper(); InitializeHelper();
InitBaseIntermediateOutputPath(); InitBaseIntermediateOutputPath();

43
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpFullParseInformation.cs

@ -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)
);
}
}
}

9
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs

@ -7,6 +7,7 @@ using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using CSharpBinding.Parser;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Resolver; using ICSharpCode.NRefactory.CSharp.Resolver;
@ -85,15 +86,11 @@ namespace CSharpBinding
return; return;
} }
ParseInformation parseInfo = ParserService.Parse(fileName, textSource); var parseInfo = ParserService.Parse(fileName, textSource) as CSharpFullParseInformation;
if (parseInfo == null) if (parseInfo == null)
return; return;
CSharpParsedFile parsedFile = parseInfo.ParsedFile as CSharpParsedFile;
CompilationUnit cu = parseInfo.Annotation<CompilationUnit>();
if (parsedFile == null || cu == null)
return;
fr.FindReferencesInFile( fr.FindReferencesInFile(
searchScope, parsedFile, cu, compilation, searchScope, parseInfo.ParsedFile, parseInfo.CompilationUnit, compilation,
delegate (AstNode node, ResolveResult result) { delegate (AstNode node, ResolveResult result) {
var region = new DomRegion(fileName, node.StartLocation, node.EndLocation); var region = new DomRegion(fileName, node.StartLocation, node.EndLocation);
callback(new Reference(region, result)); callback(new Reference(region, result));

25
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs

@ -84,10 +84,10 @@ namespace CSharpBinding.Parser
CSharpParsedFile file = cu.ToTypeSystem(); CSharpParsedFile file = cu.ToTypeSystem();
ParseInformation info = new ParseInformation(file, fullParseInformationRequested);
if (fullParseInformationRequested) if (fullParseInformationRequested)
info.AddAnnotation(cu); return new CSharpFullParseInformation(file, cu);
return info; else
return new ParseInformation(file, fullParseInformationRequested);
} }
/*void AddCommentTags(ICompilationUnit cu, System.Collections.Generic.List<ICSharpCode.NRefactory.Parser.TagComment> tagComments) /*void AddCommentTags(ICompilationUnit cu, System.Collections.Generic.List<ICSharpCode.NRefactory.Parser.TagComment> tagComments)
@ -102,28 +102,21 @@ namespace CSharpBinding.Parser
public ResolveResult Resolve(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken) public ResolveResult Resolve(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
{ {
CompilationUnit cu = parseInfo.Annotation<CompilationUnit>(); var csParseInfo = parseInfo as CSharpFullParseInformation;
if (cu == null) if (csParseInfo == null)
throw new ArgumentException("Parse info does not have CompilationUnit"); throw new ArgumentException("Parse info does not have CompilationUnit");
CSharpParsedFile parsedFile = parseInfo.ParsedFile as CSharpParsedFile;
if (parsedFile == null)
throw new ArgumentException("Parse info does not have a C# ParsedFile");
return ResolveAtLocation.Resolve(compilation, parsedFile, cu, location, cancellationToken); return ResolveAtLocation.Resolve(compilation, csParseInfo.ParsedFile, csParseInfo.CompilationUnit, location, cancellationToken);
} }
public void FindLocalReferences(ParseInformation parseInfo, IVariable variable, ICompilation compilation, Action<Reference> callback, CancellationToken cancellationToken) public void FindLocalReferences(ParseInformation parseInfo, IVariable variable, ICompilation compilation, Action<Reference> callback, CancellationToken cancellationToken)
{ {
CompilationUnit cu = parseInfo.Annotation<CompilationUnit>(); var csParseInfo = parseInfo as CSharpFullParseInformation;
if (cu == null) if (csParseInfo == null)
throw new ArgumentException("Parse info does not have CompilationUnit"); throw new ArgumentException("Parse info does not have CompilationUnit");
CSharpParsedFile parsedFile = parseInfo.ParsedFile as CSharpParsedFile;
if (parsedFile == null)
throw new ArgumentException("Parse info does not have a C# ParsedFile");
new FindReferences().FindLocalReferences( new FindReferences().FindLocalReferences(
variable, parsedFile, cu, compilation, variable, csParseInfo.ParsedFile, csParseInfo.CompilationUnit, compilation,
delegate (AstNode node, ResolveResult result) { delegate (AstNode node, ResolveResult result) {
var region = new DomRegion(parseInfo.FileName, node.StartLocation, node.EndLocation); var region = new DomRegion(parseInfo.FileName, node.StartLocation, node.EndLocation);
callback(new Reference(region, result)); callback(new Reference(region, result));

12
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs

@ -461,7 +461,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
void TextAreaTextEntered(object sender, TextCompositionEventArgs e) void TextAreaTextEntered(object sender, TextCompositionEventArgs e)
{ {
if (e.Text.Length > 0 && !e.Handled) { if (e.Text.Length > 0 && !e.Handled) {
ILanguageBinding languageBinding = GetAdapterFromSender(sender).Language; var adapter = GetAdapterFromSender(sender);
ILanguageBinding languageBinding = adapter.Language;
if (languageBinding != null && languageBinding.FormattingStrategy != null) { if (languageBinding != null && languageBinding.FormattingStrategy != null) {
char c = e.Text[0]; char c = e.Text[0];
// When entering a newline, AvalonEdit might use either "\r\n" or "\n", depending on // When entering a newline, AvalonEdit might use either "\r\n" or "\n", depending on
@ -469,13 +470,20 @@ namespace ICSharpCode.AvalonEdit.AddIn
// so that formatting strategies don't have to handle both cases. // so that formatting strategies don't have to handle both cases.
if (c == '\r') if (c == '\r')
c = '\n'; c = '\n';
languageBinding.FormattingStrategy.FormatLine(GetAdapterFromSender(sender), c); languageBinding.FormattingStrategy.FormatLine(adapter, c);
if (c == '\n') { if (c == '\n') {
// Immediately parse on enter. // Immediately parse on enter.
// This ensures we have up-to-date CC info about the method boundary when a user // This ensures we have up-to-date CC info about the method boundary when a user
// types near the end of a method. // types near the end of a method.
ParserService.ParseAsync(this.FileName, this.Document.CreateSnapshot()).FireAndForget(); ParserService.ParseAsync(this.FileName, this.Document.CreateSnapshot()).FireAndForget();
} else {
if (e.Text.Length == 1) {
foreach (ICodeCompletionBinding cc in CodeCompletionBindings) {
if (cc.HandleKeyPressed(adapter, c))
break;
}
}
} }
} }
} }

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -113,7 +113,6 @@
<Compile Include="Src\Editor\CodeCompletion\ICompletionItemHandler.cs" /> <Compile Include="Src\Editor\CodeCompletion\ICompletionItemHandler.cs" />
<Compile Include="Src\Editor\CodeCompletion\IInsightWindowHandler.cs" /> <Compile Include="Src\Editor\CodeCompletion\IInsightWindowHandler.cs" />
<Compile Include="Src\Editor\CodeCompletion\NRefactoryInsightWindowHandler.cs" /> <Compile Include="Src\Editor\CodeCompletion\NRefactoryInsightWindowHandler.cs" />
<Compile Include="Src\Editor\CodeCompletion\NRefactoryCompletionItemList.cs" />
<Compile Include="Src\Editor\Commands\ClassBookmarkSubmenuBuilder.cs" /> <Compile Include="Src\Editor\Commands\ClassBookmarkSubmenuBuilder.cs" />
<Compile Include="Src\Editor\Commands\ClassMemberMenuBuilder.cs" /> <Compile Include="Src\Editor\Commands\ClassMemberMenuBuilder.cs" />
<Compile Include="Src\Editor\Commands\FindBaseClasses.cs" /> <Compile Include="Src\Editor\Commands\FindBaseClasses.cs" />

2
src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionBinding.cs

@ -138,7 +138,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
public bool HandleKeyPressed(ITextEditor editor, char ch) public bool HandleKeyPressed(ITextEditor editor, char ch)
{ {
if (MatchesExtension(editor)) if (MatchesExtension(editor))
return binding.CtrlSpace(editor); return binding.HandleKeyPressed(editor, ch);
else else
return false; return false;
} }

9
src/Main/Base/Project/Src/Editor/CodeCompletion/ICompletionItemList.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
/// <summary> /// <summary>
/// True if this list contains all items that were available. /// True if this list contains all items that were available.
/// False if this list could contain even more items /// False if this list could contain even more items
/// (e.g. by including items from all referenced projects, regardless of imports). /// (e.g. by including items from all referenced projects, regardless of imports).
/// </summary> /// </summary>
bool ContainsAllAvailableItems { get; } bool ContainsAllAvailableItems { get; }
@ -71,9 +71,12 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
get { return items; } get { return items; }
} }
bool containsAllAvailableItems = true;
/// <inheritdoc /> /// <inheritdoc />
public virtual bool ContainsAllAvailableItems { public bool ContainsAllAvailableItems {
get { return true; } get { return containsAllAvailableItems; }
set { containsAllAvailableItems = value; }
} }
/// <summary> /// <summary>

26
src/Main/Base/Project/Src/Editor/CodeCompletion/NRefactoryCompletionItemList.cs

@ -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; }
}
}
}

14
src/Main/Base/Project/Src/Services/ParserService/ParseInformation.cs

@ -15,7 +15,7 @@ namespace ICSharpCode.SharpDevelop.Parser
/// The extra information is only provided to listeners of the ParseInformationUpdated event. /// The extra information is only provided to listeners of the ParseInformationUpdated event.
/// Those listeners may then decide to store the extra information (e.g. the TaskService stores TagComments). /// Those listeners may then decide to store the extra information (e.g. the TaskService stores TagComments).
/// </summary> /// </summary>
public class ParseInformation : AbstractAnnotatable, IFreezable public class ParseInformation
{ {
readonly IParsedFile parsedFile; readonly IParsedFile parsedFile;
IList<TagComment> tagComments = new List<TagComment>(); IList<TagComment> tagComments = new List<TagComment>();
@ -30,18 +30,6 @@ namespace ICSharpCode.SharpDevelop.Parser
this.isFullParseInformation = isFullParseInformation; this.isFullParseInformation = isFullParseInformation;
} }
public bool IsFrozen {
get { return isFrozen; }
}
public void Freeze()
{
if (!isFrozen) {
isFrozen = true;
}
}
/// <summary> /// <summary>
/// Gets whether this parse information contains 'extra' data. /// Gets whether this parse information contains 'extra' data.
/// True = extra data is provided (e.g. folding information). /// True = extra data is provided (e.g. folding information).

Loading…
Cancel
Save