Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added attribute span property for fileMemberElement #1075

Merged
merged 2 commits into from Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -9,6 +9,10 @@ public class FileMemberElement : IComparable<FileMemberElement>

public QuickFix Location { get; set; }

public int AttributeSpanStart { get; set; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make these some kind of range or span type?

Copy link
Contributor Author

@akshita31 akshita31 Jan 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rchande We could pass both AttributeSpanStart and AttributeSpanEnd in a Span type class. But in that case we will also have to define this class in protocol.ts in omnisharp-vscode. Should that be done ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rchande Yes it does, but the range has the start and end as Point type. And I couldn't spot a function in omnisharp-roslyn that converts from a span to range


public int AttributeSpanEnd { get; set; }

public string Kind { get; set; }

public ICollection<SyntaxFeature> Features { get; } = new List<SyntaxFeature>();
Expand Down
35 changes: 19 additions & 16 deletions src/OmniSharp.Roslyn.CSharp/Workers/StructureComputer.cs
Expand Up @@ -5,6 +5,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using OmniSharp.Abstractions.Services;
using OmniSharp.Models;
using OmniSharp.Models.MembersTree;
Expand Down Expand Up @@ -55,13 +56,15 @@ private async Task Process(Document document)
(syntaxRoot as CSharpSyntaxNode)?.Accept(this);
}

private FileMemberElement AsNode(SyntaxNode node, string text, Location location)
private FileMemberElement AsNode(SyntaxNode node, string text, Location location, TextSpan attributeSpan)
{
var ret = new FileMemberElement();
var lineSpan = location.GetLineSpan();
ret.Projects = new List<string>();
ret.ChildNodes = new List<FileMemberElement>();
ret.Kind = node.Kind().ToString();
ret.AttributeSpanStart = attributeSpan.Start;
ret.AttributeSpanEnd = attributeSpan.End;
ret.Location = new QuickFix()
{
Text = text,
Expand All @@ -83,9 +86,9 @@ private FileMemberElement AsNode(SyntaxNode node, string text, Location location
return ret;
}

private FileMemberElement AsChild(SyntaxNode node, string text, Location location)
private FileMemberElement AsChild(SyntaxNode node, string text, Location location, TextSpan attributeSpan)
{
var child = AsNode(node, text, location);
var child = AsNode(node, text, location, attributeSpan);
var childNodes = ((List<FileMemberElement>)_roots.Peek().ChildNodes);

// Prevent inserting the same node multiple times
Expand All @@ -104,9 +107,9 @@ private FileMemberElement AsChild(SyntaxNode node, string text, Location locatio
}
}

private FileMemberElement AsParent(SyntaxNode node, string text, Action fn, Location location)
private FileMemberElement AsParent(SyntaxNode node, string text, Action fn, Location location, TextSpan attributeSpan)
{
var child = AsChild(node, text, location);
var child = AsChild(node, text, location, attributeSpan);
_roots.Push(child);
fn();
_roots.Pop();
Expand All @@ -115,52 +118,52 @@ private FileMemberElement AsParent(SyntaxNode node, string text, Action fn, Loca

public override void VisitClassDeclaration(ClassDeclarationSyntax node)
{
AsParent(node, node.Identifier.Text, () => base.VisitClassDeclaration(node), node.Identifier.GetLocation());
AsParent(node, node.Identifier.Text, () => base.VisitClassDeclaration(node), node.Identifier.GetLocation(), node.AttributeLists.Span);
}

public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node)
{
AsParent(node, node.Identifier.Text, () => base.VisitInterfaceDeclaration(node), node.Identifier.GetLocation());
AsParent(node, node.Identifier.Text, () => base.VisitInterfaceDeclaration(node), node.Identifier.GetLocation(), node.AttributeLists.Span);
}

public override void VisitEnumDeclaration(EnumDeclarationSyntax node)
{
AsParent(node, node.Identifier.Text, () => base.VisitEnumDeclaration(node), node.Identifier.GetLocation());
AsParent(node, node.Identifier.Text, () => base.VisitEnumDeclaration(node), node.Identifier.GetLocation(), node.AttributeLists.Span);
}

public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
{
AsChild(node, node.Identifier.Text, node.Identifier.GetLocation());
AsChild(node, node.Identifier.Text, node.Identifier.GetLocation(), node.AttributeLists.Span);
}

public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node)
{
AsChild(node, node.Identifier.Text, node.Identifier.GetLocation());
AsChild(node, node.Identifier.Text, node.Identifier.GetLocation(), node.AttributeLists.Span);
}

public override void VisitMethodDeclaration(MethodDeclarationSyntax node)
{
AsChild(node, node.Identifier.Text, node.Identifier.GetLocation());
AsChild(node, node.Identifier.Text, node.Identifier.GetLocation(), node.AttributeLists.Span);
}

public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
{
AsChild(node, node.Declaration.Variables.First().Identifier.Text, node.Declaration.Variables.First().Identifier.GetLocation());
AsChild(node, node.Declaration.Variables.First().Identifier.Text, node.Declaration.Variables.First().Identifier.GetLocation(), node.AttributeLists.Span);
}

public override void VisitEventFieldDeclaration(EventFieldDeclarationSyntax node)
{
AsChild(node, node.Declaration.Variables.First().Identifier.Text, node.Declaration.Variables.First().Identifier.GetLocation());
AsChild(node, node.Declaration.Variables.First().Identifier.Text, node.Declaration.Variables.First().Identifier.GetLocation(), node.AttributeLists.Span);
}

public override void VisitStructDeclaration(StructDeclarationSyntax node)
{
AsParent(node, node.Identifier.Text, () => base.VisitStructDeclaration(node), node.Identifier.GetLocation());
AsParent(node, node.Identifier.Text, () => base.VisitStructDeclaration(node), node.Identifier.GetLocation(), node.AttributeLists.Span);
}

public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
{
AsChild(node, node.Identifier.Text, node.Identifier.GetLocation());
AsChild(node, node.Identifier.Text, node.Identifier.GetLocation(), node.AttributeLists.Span);
}
}
}
}