Browse Source

[Completion] Improved xml document completion.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
e058d6103b
  1. 48
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  2. 74
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/DocumentationContextTests.cs
  3. 1
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

48
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs

@ -2853,9 +2853,54 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -2853,9 +2853,54 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
"value"
}
);
string GetLastClosingXmlCommentTag ()
{
var line = document.GetLineByNumber(location.Line);
restart:
string lineText = document.GetText(line);
if (!lineText.Trim ().StartsWith ("///"))
return null;
int startIndex = Math.Min(location.Column - 1, lineText.Length - 1) - 1;
while (startIndex > 0 && lineText [startIndex] != '<') {
--startIndex;
if (lineText [startIndex] == '/') {
// already closed.
startIndex = -1;
break;
}
}
if (startIndex < 0 && line.PreviousLine != null) {
line = line.PreviousLine;
goto restart;
}
if (startIndex >= 0) {
int endIndex = startIndex;
while (endIndex + 1 < lineText.Length && lineText [endIndex] != '>' && !Char.IsWhiteSpace (lineText [endIndex + 1])) {
endIndex++;
}
string tag = endIndex - startIndex - 1 > 0 ? lineText.Substring(
startIndex + 1,
endIndex - startIndex - 1
) : null;
if (!string.IsNullOrEmpty(tag) && commentTags.IndexOf(tag) >= 0) {
return tag;
}
}
return null;
}
IEnumerable<ICompletionData> GetXmlDocumentationCompletionData()
{
var closingTag = GetLastClosingXmlCommentTag ();
if (closingTag != null) {
yield return factory.CreateLiteralCompletionData(
"/" + closingTag + ">"
);
}
yield return factory.CreateLiteralCompletionData(
"c",
"Set text in a code-like font"
@ -2952,6 +2997,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -2952,6 +2997,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
"value",
"Describe a property"
);
}
#endregion

74
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/DocumentationContextTests.cs

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
//
// DocumentationContextTests.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
{
[TestFixture()]
public class DocumentationContextTests
{
[Test()]
public void TestClosingTag()
{
CodeCompletionBugTests.CombinedProviderTest(
@"using System;
public class Test
{
///<summary>Foo$<$
void TestFoo()
{
}
}
", provider => {
Assert.IsNotNull(provider.Find("/summary>"));
});
}
[Test()]
public void TestClosingTagMultiLine()
{
CodeCompletionBugTests.CombinedProviderTest(
@"using System;
public class Test
{
///<summary>
///Foo
///$<$
void TestFoo()
{
}
}
", provider => {
Assert.IsNotNull(provider.Find("/summary>"));
});
}
}
}

1
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -270,6 +270,7 @@ @@ -270,6 +270,7 @@
<Compile Include="CSharp\CodeActions\ImplementInterfaceExplicitTests.cs" />
<Compile Include="CSharp\CodeActions\ImplementAbstractMembersTest.cs" />
<Compile Include="CSharp\CodeActions\ExtractFieldTests.cs" />
<Compile Include="CSharp\CodeCompletion\DocumentationContextTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Mono.Cecil\Mono.Cecil.csproj">

Loading…
Cancel
Save