Skip to content

Commit

Permalink
WI #1119 Show documentation on hover for type and procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
BALLMA authored and BALLMA committed Feb 6, 2019
1 parent aecf114 commit 23165eb
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 4 deletions.
21 changes: 17 additions & 4 deletions TypeCobol.LanguageServer/TypeCobolServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,28 @@ public override Hover OnHover(TextDocumentPosition parameters)
if (matchingNode == null)
return null;

//OnHover for data declared with a type
var dataDefinition = matchingNode as DataDefinition;
if (dataDefinition?.TypeDefinition != null)
string message = string.Empty;

switch (matchingNode)
{
case DataDefinition data:
message = data.TypeDefinition.ToString();
break;
case ProcedureStyleCall call:
if (lastSignificantToken.TokenType != TokenType.INPUT && lastSignificantToken.TokenType != TokenType.IN_OUT && lastSignificantToken.TokenType != TokenType.OUTPUT)
{
message = call.ToString();
}
break;
}

if (message != string.Empty)
{
resultHover.range = new Range(matchingCodeElement.Line, matchingCodeElement.StartIndex,
matchingCodeElement.Line,
matchingCodeElement.StopIndex + 1);
resultHover.contents =
new MarkedString[] { new MarkedString() { language = "Cobol", value = string.Join("", dataDefinition.TypeDefinition.SelfAndChildrenLines.Select(e => e.Text + "\r\n")) } };
new MarkedString[] { new MarkedString() { language = "Cobol", value = message } };
return resultHover;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,69 @@ public void Add(Fields parameter, KeyValuePair<string, string> item)
{
Add(parameter, item.Key, item.Value);
}

public override string ToString()
{
StringBuilder sb = new StringBuilder();

if (Description != null)
sb.AppendLine(Description);

if (Restriction != null)
sb.AppendLine("Restriction: " + Restriction);

if (Deprecated != null)
{
if (sb.Length != 0)
sb.AppendLine();
sb.AppendLine(Deprecated != string.Empty ? "Deprecated: " + Deprecated : "Deprecated");
}

if (ReplacedBy != null)
sb.AppendLine("Replaced By: " + ReplacedBy);

if (See != null)
{
if (sb.Length != 0)
sb.AppendLine();
sb.AppendLine("See: " + See);
}


if (Parameters.Count > 0)
{
if (sb.Length != 0)
sb.AppendLine();
sb.AppendLine("Parameters:");
foreach (var parameter in Parameters)
{
sb.AppendLine("\t-\t" + parameter.Key + ": " + parameter.Value);
}
}

if (Needs.Count > 0)
{
if (sb.Length != 0)
sb.AppendLine();
sb.AppendLine("Needs:");
foreach (var need in Needs)
{
sb.AppendLine("\t-\t" + need);
}
}

if (ToDo.Count > 0)
{
if (sb.Length != 0)
sb.AppendLine();
sb.AppendLine("To do:");
foreach (var todo in ToDo)
{
sb.AppendLine("\t-\t" + todo);
}
}

return sb.ToString();
}
}
}
35 changes: 35 additions & 0 deletions TypeCobol/Compiler/Nodes/Data.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using JetBrains.Annotations;
using TypeCobol.Compiler.Parser;
using TypeCobol.Compiler.Text;

namespace TypeCobol.Compiler.Nodes {
Expand Down Expand Up @@ -469,6 +471,39 @@ public override bool Equals(object obj)
}
return false;
}

public override string ToString()
{
StringBuilder sb = new StringBuilder();
FormalizedCommentDocumentation doc = this.CodeElement().FormalizedCommentDocumentation;

int i = 0;

while (i < SelfAndChildrenLines.Count())
{
if (SelfAndChildrenLines.ElementAt(i) is CodeElementsLine line)
{
if (line.Text.Contains("*<<<"))
{
while (!SelfAndChildrenLines.ElementAt(i).Text.Contains("*>>>"))
i++;
}
else if (line.IndicatorChar != '*')
{
sb.AppendLine(line.Text);
}
}
i++;
}

if (doc != null)
{
sb.AppendLine();
sb.Append(doc);
}

return sb.ToString();
}
}
// [/COBOL 2002]

Expand Down
9 changes: 9 additions & 0 deletions TypeCobol/Compiler/Nodes/Statement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public override bool VisitNode(IASTVisitor astVisitor)
{
return astVisitor.Visit(this);
}

public override string ToString()
{
var doc = FunctionDeclaration.CodeElement().FormalizedCommentDocumentation;
if (doc != null)
return doc.ToString();

return string.Empty;
}
}

public class Cancel: Node, CodeElementHolder<CancelStatement>, Statement {
Expand Down

0 comments on commit 23165eb

Please sign in to comment.