Work on function signatures
This commit is contained in:
parent
d6b65a8d16
commit
f75b7fc223
Binary file not shown.
Binary file not shown.
|
@ -120,12 +120,14 @@ namespace UpsilonLanguageServer
|
||||||
foreach (var prop in properties)
|
foreach (var prop in properties)
|
||||||
{
|
{
|
||||||
var parameterValue = (JObject) prop.Value;
|
var parameterValue = (JObject) prop.Value;
|
||||||
|
var parName = parameterValue.GetValue("name", StringComparison.InvariantCultureIgnoreCase)
|
||||||
|
?.ToString();
|
||||||
var parType = parameterValue.GetValue("type", StringComparison.InvariantCultureIgnoreCase)
|
var parType = parameterValue.GetValue("type", StringComparison.InvariantCultureIgnoreCase)
|
||||||
?.ToString();
|
?.ToString();
|
||||||
var parsedType = ParseType(parType);
|
var parsedType = ParseType(parType);
|
||||||
var isOptional = parameterValue.GetValue("IsOptional", StringComparison.InvariantCultureIgnoreCase)
|
var isOptional = parameterValue.GetValue("IsOptional", StringComparison.InvariantCultureIgnoreCase)
|
||||||
?.ToObject<bool>();
|
?.ToObject<bool>();
|
||||||
parameters.Add(new InternalFunctionVariableSymbol.InternalFunctionParameter(parsedType,
|
parameters.Add(new InternalFunctionVariableSymbol.InternalFunctionParameter(parName, parsedType,
|
||||||
isOptional.HasValue && isOptional.Value));
|
isOptional.HasValue && isOptional.Value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace UpsilonLanguageServer
|
||||||
var task = RealLint(document, maxNumberOfProblems, session, content, diag);
|
var task = RealLint(document, maxNumberOfProblems, session, content, diag);
|
||||||
// either wait until the script is linted, or until a second has passed (timeout)
|
// either wait until the script is linted, or until a second has passed (timeout)
|
||||||
await Task.WhenAny(task, Task.Delay(1000));
|
await Task.WhenAny(task, Task.Delay(1000));
|
||||||
|
session.IsChanging = false;
|
||||||
return diag;
|
return diag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,9 +71,11 @@ namespace UpsilonLanguageServer
|
||||||
|
|
||||||
public BoundScript Bound { get; set; }
|
public BoundScript Bound { get; set; }
|
||||||
public SourceText SourceText { get; set; }
|
public SourceText SourceText { get; set; }
|
||||||
|
public bool IsChanging { get; set; }
|
||||||
|
|
||||||
public void NotifyChanges(IEnumerable<TextDocumentContentChangeEvent> changes)
|
public void NotifyChanges(IEnumerable<TextDocumentContentChangeEvent> changes)
|
||||||
{
|
{
|
||||||
|
IsChanging = true;
|
||||||
lock (_syncLock)
|
lock (_syncLock)
|
||||||
{
|
{
|
||||||
if (_impendingChanges == null)
|
if (_impendingChanges == null)
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace UpsilonLanguageServer.Services
|
||||||
return new InitializeResult(new ServerCapabilities
|
return new InitializeResult(new ServerCapabilities
|
||||||
{
|
{
|
||||||
HoverProvider = true,
|
HoverProvider = true,
|
||||||
SignatureHelpProvider = new SignatureHelpOptions("()"),
|
SignatureHelpProvider = new SignatureHelpOptions( new[]{'(', ','}),
|
||||||
CompletionProvider = new CompletionOptions(true, ""),
|
CompletionProvider = new CompletionOptions(true, ""),
|
||||||
TextDocumentSync = new TextDocumentSyncOptions
|
TextDocumentSync = new TextDocumentSyncOptions
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,12 +66,37 @@ namespace UpsilonLanguageServer.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonRpcMethod]
|
[JsonRpcMethod]
|
||||||
public SignatureHelp SignatureHelp(TextDocumentIdentifier textDocument, Position position)
|
public async Task<SignatureHelp> SignatureHelp(TextDocumentIdentifier textDocument, Position position)
|
||||||
{
|
{
|
||||||
// TODO
|
if (Session.Documents.TryGetValue(textDocument.Uri, out var doc))
|
||||||
return new SignatureHelp(new List<SignatureInformation>
|
|
||||||
{
|
{
|
||||||
});
|
await doc.WaitForDocumentBound();
|
||||||
|
if (doc.Bound != null && doc.SourceText != null)
|
||||||
|
{
|
||||||
|
var linePos = doc.SourceText.GetLineStartPos(position.Line);
|
||||||
|
var findNode = doc.Bound.GetBottomNodeAtPosition(linePos + position.Character);
|
||||||
|
if (findNode != null)
|
||||||
|
{
|
||||||
|
if (findNode.Kind == BoundKind.BoundFunctionCallExpression)
|
||||||
|
{
|
||||||
|
var functionCall = (BoundFunctionCallExpression)findNode;
|
||||||
|
var exp = Binder.ResolveVariable(functionCall.Identifier, null);
|
||||||
|
if (exp is InternalFunctionVariableSymbol internalFunction)
|
||||||
|
{
|
||||||
|
var n = new SignatureHelp(new List<SignatureInformation>()
|
||||||
|
{
|
||||||
|
new SignatureInformation(exp.Name, string.Join(" \n", exp.CommentValue),
|
||||||
|
internalFunction.FunctionParameters.Select(
|
||||||
|
x => new ParameterInformation("", $"{x.Name} ({x.ValidTypes})")).ToList())
|
||||||
|
}, 0, functionCall.Parameters.Length);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SignatureHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonRpcMethod(IsNotification = true)]
|
[JsonRpcMethod(IsNotification = true)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
|
@ -15,5 +16,13 @@ namespace UpsilonLanguageServer
|
||||||
{
|
{
|
||||||
return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task WaitForDocumentBound(this SessionDocument doc)
|
||||||
|
{
|
||||||
|
while (doc.IsChanging)
|
||||||
|
{
|
||||||
|
await Task.Delay(20);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue