Initial Completion support

This commit is contained in:
Deukhoofd 2018-11-27 14:15:03 +01:00
parent 238c2daa70
commit 682e784c20
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
4 changed files with 28 additions and 17 deletions

View File

@ -13,7 +13,7 @@ namespace UpsilonLanguageServer.Services
{ {
var item = RequestContext.Request.Parameters.ToObject<CompletionItem>(Utility.CamelCaseJsonSerializer); var item = RequestContext.Request.Parameters.ToObject<CompletionItem>(Utility.CamelCaseJsonSerializer);
// Add a pair of square brackets around the inserted text. // Add a pair of square brackets around the inserted text.
item.InsertText = $"[{item.Label}]"; item.InsertText = item.Label;
return item; return item;
} }
} }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -108,25 +109,35 @@ namespace UpsilonLanguageServer.Services
Session.Documents.TryRemove(textDocument.Uri, out _); Session.Documents.TryRemove(textDocument.Uri, out _);
} }
private static readonly CompletionItem[] PredefinedCompletionItems =
{
new CompletionItem(".NET", CompletionItemKind.Keyword,
"Keyword1",
"Short for **.NET Framework**, a software framework by Microsoft (possibly its subsets) or later open source .NET Core.",
null),
new CompletionItem(".NET Standard", CompletionItemKind.Keyword,
"Keyword2",
"The .NET Standard is a formal specification of .NET APIs that are intended to be available on all .NET runtimes.",
null),
new CompletionItem(".NET Framework", CompletionItemKind.Keyword,
"Keyword3",
".NET Framework (pronounced dot net) is a software framework developed by Microsoft that runs primarily on Microsoft Windows.", null),
};
[JsonRpcMethod] [JsonRpcMethod]
public async Task<CompletionList> Completion(TextDocumentIdentifier textDocument, Position position, CompletionContext context) public async Task<CompletionList> Completion(TextDocumentIdentifier textDocument, Position position, CompletionContext context)
{ {
return new CompletionList(PredefinedCompletionItems, false); if (Session.Documents.TryGetValue(textDocument.Uri, out var doc) && doc.Bound != null)
{
if (context.TriggerCharacter == '.')
{
var linePos = doc.SourceText.GetLineStartPos(position.Line);
var findNode = doc.Bound.GetNodeAtPosition(linePos + position.Character - 2);
if (findNode is BoundVariableSymbol variableSymbol)
{
if (variableSymbol.VariableSymbol is TableVariableSymbol tableSymbol)
{
return new CompletionList(
tableSymbol.Variables.Select(x => new CompletionItem(x.Name,
CompletionItemKind.Variable, x.Type.ToString(),
$"\n\n{string.Join(" \n", x.CommentValue)}")));
}
return new CompletionList(
new[]
{
new CompletionItem(findNode.Kind.ToString(), CompletionItemKind.Variable,
variableSymbol.VariableSymbol.Name, ""),
},
false);
}
}
}
return new CompletionList(new CompletionItem[0], false);
} }
} }