first commit -push
This commit is contained in:
9
RobotNet.WebApp/Scripts/Monaco/Languages/Command.cs
Normal file
9
RobotNet.WebApp/Scripts/Monaco/Languages/Command.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public struct Command
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string? Tooltip { get; set; }
|
||||
public object[]? Arguments { get; set; }
|
||||
}
|
||||
248
RobotNet.WebApp/Scripts/Monaco/Languages/CompletionExtensions.cs
Normal file
248
RobotNet.WebApp/Scripts/Monaco/Languages/CompletionExtensions.cs
Normal file
@@ -0,0 +1,248 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Completion;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Options;
|
||||
using Microsoft.CodeAnalysis.Tags;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using RobotNet.WebApp.Scripts.Monaco.Editor;
|
||||
using System.Collections.Immutable;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public static class CompletionExtensions
|
||||
{
|
||||
private static readonly Dictionary<string, CompletionItemKind> s_roslynTagToCompletionItemKind = new()
|
||||
{
|
||||
{ WellKnownTags.Public, CompletionItemKind.Keyword },
|
||||
{ WellKnownTags.Protected, CompletionItemKind.Keyword },
|
||||
{ WellKnownTags.Private, CompletionItemKind.Keyword },
|
||||
{ WellKnownTags.Internal, CompletionItemKind.Keyword },
|
||||
{ WellKnownTags.File, CompletionItemKind.File },
|
||||
{ WellKnownTags.Project, CompletionItemKind.File },
|
||||
{ WellKnownTags.Folder, CompletionItemKind.Folder },
|
||||
{ WellKnownTags.Assembly, CompletionItemKind.File },
|
||||
{ WellKnownTags.Class, CompletionItemKind.Class },
|
||||
{ WellKnownTags.Constant, CompletionItemKind.Constant },
|
||||
{ WellKnownTags.Delegate, CompletionItemKind.Function },
|
||||
{ WellKnownTags.Enum, CompletionItemKind.Enum },
|
||||
{ WellKnownTags.EnumMember, CompletionItemKind.EnumMember },
|
||||
{ WellKnownTags.Event, CompletionItemKind.Event },
|
||||
{ WellKnownTags.ExtensionMethod, CompletionItemKind.Method },
|
||||
{ WellKnownTags.Field, CompletionItemKind.Field },
|
||||
{ WellKnownTags.Interface, CompletionItemKind.Interface },
|
||||
{ WellKnownTags.Intrinsic, CompletionItemKind.Text },
|
||||
{ WellKnownTags.Keyword, CompletionItemKind.Keyword },
|
||||
{ WellKnownTags.Label, CompletionItemKind.Text },
|
||||
{ WellKnownTags.Local, CompletionItemKind.Variable },
|
||||
{ WellKnownTags.Namespace, CompletionItemKind.Module },
|
||||
{ WellKnownTags.Method, CompletionItemKind.Method },
|
||||
{ WellKnownTags.Module, CompletionItemKind.Module },
|
||||
{ WellKnownTags.Operator, CompletionItemKind.Operator },
|
||||
{ WellKnownTags.Parameter, CompletionItemKind.Value },
|
||||
{ WellKnownTags.Property, CompletionItemKind.Property },
|
||||
{ WellKnownTags.RangeVariable, CompletionItemKind.Variable },
|
||||
{ WellKnownTags.Reference, CompletionItemKind.Reference },
|
||||
{ WellKnownTags.Structure, CompletionItemKind.Struct },
|
||||
{ WellKnownTags.TypeParameter, CompletionItemKind.TypeParameter },
|
||||
{ WellKnownTags.Snippet, CompletionItemKind.Snippet },
|
||||
{ WellKnownTags.Error, CompletionItemKind.Text },
|
||||
{ WellKnownTags.Warning, CompletionItemKind.Text },
|
||||
};
|
||||
|
||||
private static CompletionTrigger GetCompletionTrigger(int kind, char? triggerCharacter, bool includeTriggerCharacter)
|
||||
=> kind switch
|
||||
{
|
||||
1 => CompletionTrigger.Invoke,
|
||||
// https://github.com/dotnet/roslyn/issues/42982: Passing a trigger character
|
||||
// to GetCompletionsAsync causes a null ref currently.
|
||||
2 when includeTriggerCharacter => CompletionTrigger.CreateInsertionTrigger((char)triggerCharacter!),
|
||||
_ => CompletionTrigger.Invoke,
|
||||
};
|
||||
|
||||
//private static readonly Regex EscapeRegex = new(@"([\\\$}])", RegexOptions.Compiled);
|
||||
//private static string GetAdjustedInsertTextWithPosition(
|
||||
// CompletionChange change,
|
||||
// int originalPosition,
|
||||
// int newOffset,
|
||||
// string? prependText = null)
|
||||
//{
|
||||
// string newText = change.TextChange.NewText!;
|
||||
// if (change.NewPosition is not int newPosition
|
||||
// || newPosition >= change.TextChange.Span.Start + newText.Length)
|
||||
// {
|
||||
// return prependText + newText[newOffset..];
|
||||
// }
|
||||
// int midpoint = newPosition - change.TextChange.Span.Start;
|
||||
|
||||
// var beforeText = prependText + newText[newOffset..midpoint];
|
||||
// if (beforeText != null) beforeText = EscapeRegex.Replace(beforeText, @"\$1");
|
||||
|
||||
// var afterText = newText[midpoint..];
|
||||
// if (afterText != null) afterText = EscapeRegex.Replace(afterText, @"\$1");
|
||||
|
||||
// return beforeText + "$0" + afterText;
|
||||
//}
|
||||
|
||||
private static ImmutableArray<char> BuildCommitCharacters(Microsoft.CodeAnalysis.Completion.CompletionList completions, ImmutableArray<CharacterSetModificationRule> characterRules, ImmutableArray<char>.Builder triggerCharactersBuilder)
|
||||
{
|
||||
if (completions is null) return [];
|
||||
|
||||
triggerCharactersBuilder.AddRange(completions.Rules.DefaultCommitCharacters);
|
||||
|
||||
foreach (var modifiedRule in characterRules)
|
||||
{
|
||||
switch (modifiedRule.Kind)
|
||||
{
|
||||
case CharacterSetModificationKind.Add:
|
||||
triggerCharactersBuilder.AddRange(modifiedRule.Characters);
|
||||
break;
|
||||
|
||||
case CharacterSetModificationKind.Remove:
|
||||
for (int i = 0; i < triggerCharactersBuilder.Count; i++)
|
||||
{
|
||||
if (modifiedRule.Characters.Contains(triggerCharactersBuilder[i]))
|
||||
{
|
||||
triggerCharactersBuilder.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case CharacterSetModificationKind.Replace:
|
||||
triggerCharactersBuilder.Clear();
|
||||
triggerCharactersBuilder.AddRange(modifiedRule.Characters);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (completions.SuggestionModeItem is not null)
|
||||
{
|
||||
triggerCharactersBuilder.Remove(' ');
|
||||
}
|
||||
|
||||
if (triggerCharactersBuilder.Capacity == triggerCharactersBuilder.Count)
|
||||
{
|
||||
return triggerCharactersBuilder.MoveToImmutable();
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = triggerCharactersBuilder.ToImmutable();
|
||||
triggerCharactersBuilder.Clear();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static CompletionItemKind GetCompletionItemKind(ImmutableArray<string> tags)
|
||||
{
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
if (s_roslynTagToCompletionItemKind.TryGetValue(tag, out var itemKind))
|
||||
{
|
||||
return itemKind;
|
||||
}
|
||||
}
|
||||
|
||||
return CompletionItemKind.Text;
|
||||
}
|
||||
|
||||
public static async Task<IEnumerable<CompletionItem>> GetCompletionAsync(this AdhocWorkspace workspace, DocumentId documentId, int line, int column, int kind, char? triggerCharacter)
|
||||
{
|
||||
if (triggerCharacter == ' ') return [];
|
||||
|
||||
var document = workspace.CurrentSolution.GetDocument(documentId);
|
||||
if (document is null) return [];
|
||||
|
||||
var sourceText = await document.GetTextAsync();
|
||||
var position = sourceText.Lines.GetPosition(new LinePosition(line - 1, column - 1));
|
||||
var completionService = CompletionService.GetService(document);
|
||||
|
||||
if (completionService == null) return [];
|
||||
|
||||
if (kind == 3 && !completionService.ShouldTriggerCompletion(sourceText, position, GetCompletionTrigger(kind - 1, triggerCharacter, includeTriggerCharacter: true)))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
Microsoft.CodeAnalysis.Completion.CompletionList? completionList = null;
|
||||
try
|
||||
{
|
||||
completionList = await completionService.GetCompletionsAsync(
|
||||
document,
|
||||
position,
|
||||
GetCompletionTrigger(kind - 1, triggerCharacter, includeTriggerCharacter: false));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Log the exception or handle it as needed
|
||||
Console.WriteLine($"Error getting completions: position:{position} \n {ex}");
|
||||
}
|
||||
|
||||
if (completionList is null || completionList.ItemsList.Count <= 0) return [];
|
||||
|
||||
var typedSpan = completionService.GetDefaultCompletionListSpan(sourceText, position);
|
||||
string typedText = sourceText.GetSubText(typedSpan).ToString();
|
||||
ImmutableArray<string> filteredItems = typedText != string.Empty
|
||||
? [.. completionService.FilterItems(document, [.. completionList.ItemsList], typedText).Select(i => i.DisplayText)]
|
||||
: [];
|
||||
|
||||
bool expectingImportedItems = workspace.Options.GetOption(new PerLanguageOption<bool?>("CompletionOptions", "ShowItemsFromUnimportedNamespaces", defaultValue: null), LanguageNames.CSharp) == true;
|
||||
var syntax = await document.GetSyntaxTreeAsync();
|
||||
var replacingSpanStartPosition = sourceText.Lines.GetLinePosition(typedSpan.Start);
|
||||
var replacingSpanEndPosition = sourceText.Lines.GetLinePosition(typedSpan.End);
|
||||
var triggerCharactersBuilder = ImmutableArray.CreateBuilder<char>(completionList.Rules.DefaultCommitCharacters.Length);
|
||||
var completionsBuilder = new List<CompletionItem>();
|
||||
|
||||
foreach (var completion in completionList.ItemsList)
|
||||
{
|
||||
SingleEditOperation[]? additionalTextEdits = null;
|
||||
char sortTextPrepend = '0';
|
||||
|
||||
if (!completion.Properties.TryGetValue("InsertionText", out string? insertText))
|
||||
{
|
||||
if (GetCompletionItemKind(completion.Tags) == CompletionItemKind.Keyword)
|
||||
{
|
||||
insertText = completion.DisplayText;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(insertText)) continue;
|
||||
|
||||
var commitCharacters = BuildCommitCharacters(completionList, completion.Rules.CommitCharacterRules, triggerCharactersBuilder).Select(c => c.ToString());
|
||||
|
||||
completionsBuilder.Add(new CompletionItem
|
||||
{
|
||||
Label = completion.DisplayTextPrefix + completion.DisplayText + completion.DisplayTextSuffix,
|
||||
Kind = GetCompletionItemKind(completion.Tags),
|
||||
Documentation = "",
|
||||
InsertText = insertText,
|
||||
Range = new Range
|
||||
{
|
||||
StartLineNumber = replacingSpanStartPosition.Line + 1,
|
||||
EndLineNumber = replacingSpanEndPosition.Line + 1,
|
||||
StartColumn = replacingSpanStartPosition.Character + 1,
|
||||
EndColumn = replacingSpanEndPosition.Character + 1,
|
||||
},
|
||||
AdditionalTextEdits = additionalTextEdits,
|
||||
// Ensure that unimported items are sorted after things already imported.
|
||||
SortText = expectingImportedItems ? sortTextPrepend + completion.SortText : completion.SortText,
|
||||
FilterText = completion.FilterText,
|
||||
Detail = completion.InlineDescription,
|
||||
Preselect = completion.Rules.MatchPriority == MatchPriority.Preselect || filteredItems.Contains(completion.DisplayText),
|
||||
CommitCharacters = [.. commitCharacters],
|
||||
Tags = null,
|
||||
Command = null,
|
||||
InsertTextRules = null,
|
||||
});
|
||||
}
|
||||
|
||||
return completionsBuilder;
|
||||
}
|
||||
}
|
||||
21
RobotNet.WebApp/Scripts/Monaco/Languages/CompletionItem.cs
Normal file
21
RobotNet.WebApp/Scripts/Monaco/Languages/CompletionItem.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using RobotNet.WebApp.Scripts.Monaco.Editor;
|
||||
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public struct CompletionItem
|
||||
{
|
||||
public string Label { get; set; }
|
||||
public CompletionItemKind Kind { get; set; }
|
||||
public string? Documentation { get; set; }
|
||||
public string InsertText { get; set; }
|
||||
public Range Range { get; set; }
|
||||
public SingleEditOperation[]? AdditionalTextEdits { get; set; }
|
||||
public Command? Command { get; set; }
|
||||
public string[]? CommitCharacters { get; set; }
|
||||
public string? Detail { get; set; }
|
||||
public string? FilterText { get; set; }
|
||||
public CompletionItemInsertTextRule? InsertTextRules { get; set; }
|
||||
public bool Preselect { get; set; }
|
||||
public string? SortText { get; set; }
|
||||
public int[]? Tags { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public enum CompletionItemInsertTextRule
|
||||
{
|
||||
None = 0,
|
||||
/**
|
||||
* Adjust whitespace/indentation of multiline insert texts to
|
||||
* match the current line indentation.
|
||||
*/
|
||||
KeepWhitespace = 1,
|
||||
/**
|
||||
* `insertText` is a snippet.
|
||||
*/
|
||||
InsertAsSnippet = 4
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public enum CompletionItemKind
|
||||
{
|
||||
Method = 0,
|
||||
Function = 1,
|
||||
Constructor = 2,
|
||||
Field = 3,
|
||||
Variable = 4,
|
||||
Class = 5,
|
||||
Struct = 6,
|
||||
Interface = 7,
|
||||
Module = 8,
|
||||
Property = 9,
|
||||
Event = 10,
|
||||
Operator = 11,
|
||||
Unit = 12,
|
||||
Value = 13,
|
||||
Constant = 14,
|
||||
Enum = 15,
|
||||
EnumMember = 16,
|
||||
Keyword = 17,
|
||||
Text = 18,
|
||||
Color = 19,
|
||||
File = 20,
|
||||
Reference = 21,
|
||||
Customcolor = 22,
|
||||
Folder = 23,
|
||||
TypeParameter = 24,
|
||||
User = 25,
|
||||
Issue = 26,
|
||||
Snippet = 27
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public struct CompletionItemLabel
|
||||
{
|
||||
public string? Description { get; set; }
|
||||
public string? Detail { get; set; }
|
||||
public string Label { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using RobotNet.WebApp.Scripts.Monaco;
|
||||
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public struct CompletionItemRanges
|
||||
{
|
||||
public Range Intert { get; set; }
|
||||
public Range Replace { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public enum CompletionItemTag
|
||||
{
|
||||
Deprecated = 1
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public struct CompletionList
|
||||
{
|
||||
public bool? Incomplete { get; set; }
|
||||
public CompletionItem[] Suggestions { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public struct ParameterInformation
|
||||
{
|
||||
public string Label { get; set; }
|
||||
public MarkdownString? Documentation { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public struct SignatureHelp
|
||||
{
|
||||
public int ActiveParameter { get; set; }
|
||||
public int ActiveSignature { get; set; }
|
||||
public SignatureInformation[] Signatures { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using RobotNet.WebApp.Scripts.Monaco.Documentation;
|
||||
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public static class SignatureHelpExtensions
|
||||
{
|
||||
public static async Task<SignatureHelpResult?> GetSignatureHelpAsync(this Document document, int line, int column)
|
||||
{
|
||||
var invocation = await GetInvocation(document, line - 1, column - 1);
|
||||
if (invocation is null) return null;
|
||||
|
||||
var response = new SignatureHelp();
|
||||
foreach (var comma in invocation.Separators)
|
||||
{
|
||||
if (comma.Span.Start > invocation.Position)
|
||||
{
|
||||
break;
|
||||
}
|
||||
response.ActiveParameter += 1;
|
||||
}
|
||||
|
||||
var signaturesSet = new HashSet<SignatureInformation>();
|
||||
var bestScore = int.MinValue;
|
||||
SignatureInformation? bestScoredItem = null;
|
||||
|
||||
var types = invocation.ArgumentTypes;
|
||||
ISymbol? throughSymbol = null;
|
||||
ISymbol? throughType = null;
|
||||
var methodGroup = invocation.SemanticModel.GetMemberGroup(invocation.Receiver).OfType<IMethodSymbol>();
|
||||
if (invocation.Receiver is MemberAccessExpressionSyntax syntax)
|
||||
{
|
||||
var throughExpression = syntax.Expression;
|
||||
throughSymbol = invocation.SemanticModel.GetSpeculativeSymbolInfo(invocation.Position, throughExpression, SpeculativeBindingOption.BindAsExpression).Symbol;
|
||||
throughType = invocation.SemanticModel.GetSpeculativeTypeInfo(invocation.Position, throughExpression, SpeculativeBindingOption.BindAsTypeOrNamespace).Type;
|
||||
var includeInstance = throughSymbol != null && throughSymbol is not ITypeSymbol ||
|
||||
throughExpression is LiteralExpressionSyntax ||
|
||||
throughExpression is TypeOfExpressionSyntax;
|
||||
var includeStatic = throughSymbol is INamedTypeSymbol || throughType != null;
|
||||
methodGroup = methodGroup.Where(m => m.IsStatic && includeStatic || !m.IsStatic && includeInstance);
|
||||
}
|
||||
else if (invocation.Receiver is SimpleNameSyntax && invocation.IsInStaticContext)
|
||||
{
|
||||
methodGroup = methodGroup.Where(m => m.IsStatic || m.MethodKind == MethodKind.LocalFunction);
|
||||
}
|
||||
|
||||
foreach (var methodOverload in methodGroup)
|
||||
{
|
||||
var signature = BuildSignature(methodOverload);
|
||||
signaturesSet.Add(signature);
|
||||
|
||||
var score = InvocationScore(methodOverload, types);
|
||||
if (score > bestScore)
|
||||
{
|
||||
bestScore = score;
|
||||
bestScoredItem = signature;
|
||||
}
|
||||
}
|
||||
|
||||
var signaturesList = signaturesSet.ToList();
|
||||
response.Signatures = [.. signaturesList];
|
||||
if(bestScoredItem == null)
|
||||
{
|
||||
response.ActiveSignature = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
response.ActiveSignature = signaturesList.IndexOf((SignatureInformation)bestScoredItem);
|
||||
}
|
||||
|
||||
return new SignatureHelpResult()
|
||||
{
|
||||
Value = response,
|
||||
};
|
||||
}
|
||||
|
||||
private static async Task<InvocationContext?> GetInvocation(Document document, int line, int column)
|
||||
{
|
||||
var sourceText = await document.GetTextAsync();
|
||||
var position = sourceText.Lines.GetPosition(new LinePosition(line, column));
|
||||
var tree = await document.GetSyntaxTreeAsync();
|
||||
|
||||
if (tree is null) return null;
|
||||
|
||||
var root = await tree.GetRootAsync();
|
||||
var node = root.FindToken(position).Parent;
|
||||
|
||||
// Walk up until we find a node that we're interested in.
|
||||
while (node != null)
|
||||
{
|
||||
if (node is InvocationExpressionSyntax invocation && invocation.ArgumentList.Span.Contains(position))
|
||||
{
|
||||
var semanticModel = await document.GetSemanticModelAsync();
|
||||
return semanticModel is null ? null : new InvocationContext(semanticModel, position, invocation.Expression, invocation.ArgumentList, invocation.IsInStaticContext());
|
||||
}
|
||||
|
||||
if (node is BaseObjectCreationExpressionSyntax objectCreation && (objectCreation.ArgumentList?.Span.Contains(position) ?? false))
|
||||
{
|
||||
var semanticModel = await document.GetSemanticModelAsync();
|
||||
return semanticModel is null ? null : new InvocationContext(semanticModel, position, objectCreation, objectCreation.ArgumentList, objectCreation.IsInStaticContext());
|
||||
}
|
||||
|
||||
if (node is AttributeSyntax attributeSyntax && (attributeSyntax.ArgumentList?.Span.Contains(position) ?? false))
|
||||
{
|
||||
var semanticModel = await document.GetSemanticModelAsync();
|
||||
return semanticModel is null ? null : new InvocationContext(semanticModel, position, attributeSyntax, attributeSyntax.ArgumentList, attributeSyntax.IsInStaticContext());
|
||||
}
|
||||
|
||||
node = node.Parent;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static int InvocationScore(IMethodSymbol symbol, IEnumerable<TypeInfo> types)
|
||||
{
|
||||
var parameters = symbol.Parameters;
|
||||
if (parameters.Length < types.Count())
|
||||
{
|
||||
return int.MinValue;
|
||||
}
|
||||
|
||||
var score = 0;
|
||||
var invocationEnum = types.GetEnumerator();
|
||||
var definitionEnum = parameters.GetEnumerator();
|
||||
while (invocationEnum.MoveNext() && definitionEnum.MoveNext())
|
||||
{
|
||||
if (invocationEnum.Current.ConvertedType == null)
|
||||
{
|
||||
// 1 point for having a parameter
|
||||
score += 1;
|
||||
}
|
||||
else if (SymbolEqualityComparer.Default.Equals(invocationEnum.Current.ConvertedType, definitionEnum.Current.Type))
|
||||
{
|
||||
// 2 points for having a parameter and being
|
||||
// the same type
|
||||
score += 2;
|
||||
}
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
private static SignatureInformation BuildSignature(IMethodSymbol symbol)
|
||||
{
|
||||
var StructuredDocumentation = DocumentationConverter.GetStructuredDocumentation(symbol);
|
||||
|
||||
return new SignatureInformation
|
||||
{
|
||||
Documentation = new MarkdownString()
|
||||
{
|
||||
Value = StructuredDocumentation?.SummaryText ?? "",
|
||||
},
|
||||
Label = symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat),
|
||||
Parameters = [..symbol.Parameters.Select(parameter => new ParameterInformation()
|
||||
{
|
||||
Label = parameter.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat),
|
||||
Documentation = new MarkdownString()
|
||||
{
|
||||
Value = StructuredDocumentation?.GetParameterText(parameter.Name) ?? string.Empty,
|
||||
},
|
||||
})],
|
||||
ActiveParameter = null,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public struct SignatureHelpResult
|
||||
{
|
||||
public SignatureHelp Value { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace RobotNet.WebApp.Scripts.Monaco.Languages;
|
||||
|
||||
public struct SignatureInformation
|
||||
{
|
||||
public int? ActiveParameter { get; set; }
|
||||
public MarkdownString? Documentation { get; set; }
|
||||
public string Label { get; set; }
|
||||
public ParameterInformation[] Parameters { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user