Skip to content

Commit

Permalink
WI #1119 Modify how to get the node on procedure declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
BALLMA authored and BALLMA committed Feb 12, 2019
1 parent 0b760a9 commit b99c6ad
Showing 1 changed file with 12 additions and 45 deletions.
57 changes: 12 additions & 45 deletions TypeCobol.LanguageServer/TypeCobolServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,18 @@ public override Hover OnHover(TextDocumentPosition parameters)
//only for params of a function declaration
if (userFilterToken != null && (lastSignificantToken.TokenType == TokenType.QualifiedNameSeparator || lastSignificantToken.TokenType == TokenType.TYPE))
{
//get the node of the param
var param = fun.Profile.Parameters.FirstOrDefault(p =>
p.TypeDefinition != null && p.TypeDefinition.QualifiedName.ToString() ==
GetFullQualifiedName(matchingCodeElement.ConsumedTokens, userFilterToken));

if(param?.TypeDefinition != null)
message = param.TypeDefinition.ToString();
foreach (var param in fun.Profile.Parameters)
{
//if the hovered position is inside this parameter
//line + 1 : because start index is 0
if (param.CodeElement.Line == parameters.position.line + 1 &&
param.CodeElement.StartIndex < parameters.position.character &&
param.CodeElement.StopIndex > parameters.position.character)
{
if (param.TypeDefinition != null)
message = param.TypeDefinition.ToString();
}
}
}
break;
}
Expand Down Expand Up @@ -982,44 +987,6 @@ private DocumentContext GetDocumentContextFromStringUri(string uri, bool acceptN
return null;
}

/// <summary>
/// Get the qualified name out of a hovered UserDefinedWord
/// </summary>
/// <param name="consumedToken"> he list of all consumed token in the CodeElement</param>
/// <param name="currentToken"> The hovered word</param>
/// <returns></returns>
private string GetFullQualifiedName(IList<Token> consumedToken, Token currentToken)
{
StringBuilder sb = new StringBuilder();

for (int i = 0; i < consumedToken.Count; i++)
{
if (consumedToken[i].Equals(currentToken))
{
int j = i;
//get the tail
while (j >= 0 && consumedToken[j - 1].TokenType == TokenType.QualifiedNameSeparator)
{
sb.Append(consumedToken[j - 2].Text + '.');
j = j - 2;
}

sb.Append(currentToken.Text + '.');
j = i;

//get the head
while (j < consumedToken.Count && consumedToken[j + 1].TokenType == TokenType.QualifiedNameSeparator)
{
sb.Append(consumedToken[j + 2].Text + '.');
j = j + 2;
}
}
}

sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}

}
public class CodeElementWrapper : CodeElement
{
Expand Down

0 comments on commit b99c6ad

Please sign in to comment.