...
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using NubLang.Ast;
|
||||
using NubLang.Modules;
|
||||
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
|
||||
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
|
||||
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
|
||||
@@ -29,13 +30,6 @@ internal class CompletionHandler(WorkspaceManager workspaceManager) : Completion
|
||||
Label = "module",
|
||||
InsertTextFormat = InsertTextFormat.Snippet,
|
||||
InsertText = "module \"$0\"",
|
||||
},
|
||||
new()
|
||||
{
|
||||
Kind = CompletionItemKind.Keyword,
|
||||
Label = "import",
|
||||
InsertTextFormat = InsertTextFormat.Snippet,
|
||||
InsertText = "import \"$0\"",
|
||||
}
|
||||
];
|
||||
|
||||
@@ -112,65 +106,76 @@ internal class CompletionHandler(WorkspaceManager workspaceManager) : Completion
|
||||
private CompletionList HandleSync(CompletionParams request, CancellationToken cancellationToken)
|
||||
{
|
||||
var completions = new List<CompletionItem>();
|
||||
var position = request.Position;
|
||||
|
||||
var uri = request.TextDocument.Uri;
|
||||
var compilationUnit = workspaceManager.GetCompilationUnit(uri);
|
||||
if (compilationUnit != null)
|
||||
var compilationUnit = workspaceManager.GetTopLevelNodes(request.TextDocument.Uri.GetFileSystemPath());
|
||||
|
||||
var repository = workspaceManager.GetModuleRepository();
|
||||
|
||||
var function = compilationUnit
|
||||
.OfType<FuncNode>()
|
||||
.FirstOrDefault(x => x.Body != null && x.Body.ContainsPosition(request.Position.Line, request.Position.Character));
|
||||
|
||||
if (function != null)
|
||||
{
|
||||
var function = compilationUnit.OfType<FuncNode>().FirstOrDefault(x => x.Body != null && x.Body.ContainsPosition(position.Line, position.Character));
|
||||
if (function != null)
|
||||
completions.AddRange(_statementSnippets);
|
||||
|
||||
foreach (var module in repository.GetAll())
|
||||
{
|
||||
completions.AddRange(_statementSnippets);
|
||||
|
||||
// foreach (var (module, prototypes) in compilationUnit.ImportedFunctions)
|
||||
// {
|
||||
// foreach (var prototype in prototypes)
|
||||
// {
|
||||
// var parameterStrings = new List<string>();
|
||||
// foreach (var (index, parameter) in prototype.Parameters.Index())
|
||||
// {
|
||||
// parameterStrings.AddRange($"${{{index + 1}:{parameter.NameToken.Value}}}");
|
||||
// }
|
||||
//
|
||||
// completions.Add(new CompletionItem
|
||||
// {
|
||||
// Kind = CompletionItemKind.Function,
|
||||
// Label = $"{module.Value}::{prototype.NameToken.Value}",
|
||||
// InsertTextFormat = InsertTextFormat.Snippet,
|
||||
// InsertText = $"{module.Value}::{prototype.NameToken.Value}({string.Join(", ", parameterStrings)})",
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
foreach (var parameter in function.Prototype.Parameters)
|
||||
foreach (var prototype in module.FunctionPrototypes)
|
||||
{
|
||||
var parameterStrings = new List<string>();
|
||||
foreach (var (index, parameter) in prototype.Parameters.Index())
|
||||
{
|
||||
parameterStrings.AddRange($"${{{index + 1}:{parameter.NameToken.Value}}}");
|
||||
}
|
||||
|
||||
var isCurrentModule = false;
|
||||
var moduleDecl = compilationUnit.OfType<ModuleNode>().FirstOrDefault();
|
||||
if (moduleDecl != null)
|
||||
{
|
||||
if (moduleDecl.NameToken.Value == module.Name)
|
||||
{
|
||||
isCurrentModule = true;
|
||||
}
|
||||
}
|
||||
|
||||
completions.Add(new CompletionItem
|
||||
{
|
||||
Kind = CompletionItemKind.Variable,
|
||||
Label = parameter.NameToken.Value,
|
||||
InsertText = parameter.NameToken.Value,
|
||||
});
|
||||
}
|
||||
|
||||
var variables = function.Body!
|
||||
.Descendants()
|
||||
.OfType<VariableDeclarationNode>();
|
||||
|
||||
foreach (var variable in variables)
|
||||
{
|
||||
completions.Add(new CompletionItem
|
||||
{
|
||||
Kind = CompletionItemKind.Variable,
|
||||
Label = variable.NameToken.Value,
|
||||
InsertText = variable.NameToken.Value,
|
||||
Kind = CompletionItemKind.Function,
|
||||
Label = isCurrentModule ? prototype.NameToken.Value : $"{module.Name}::{prototype.NameToken.Value}",
|
||||
InsertTextFormat = InsertTextFormat.Snippet,
|
||||
InsertText = $"{(isCurrentModule ? "" : $"{module.Name}::")}{prototype.NameToken.Value}({string.Join(", ", parameterStrings)})",
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
foreach (var parameter in function.Prototype.Parameters)
|
||||
{
|
||||
completions.AddRange(_definitionSnippets);
|
||||
completions.Add(new CompletionItem
|
||||
{
|
||||
Kind = CompletionItemKind.Variable,
|
||||
Label = parameter.NameToken.Value,
|
||||
InsertText = parameter.NameToken.Value,
|
||||
});
|
||||
}
|
||||
|
||||
var variables = function.Body!
|
||||
.Descendants()
|
||||
.OfType<VariableDeclarationNode>();
|
||||
|
||||
foreach (var variable in variables)
|
||||
{
|
||||
completions.Add(new CompletionItem
|
||||
{
|
||||
Kind = CompletionItemKind.Variable,
|
||||
Label = variable.NameToken.Value,
|
||||
InsertText = variable.NameToken.Value,
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
completions.AddRange(_definitionSnippets);
|
||||
}
|
||||
|
||||
return new CompletionList(completions, false);
|
||||
|
||||
Reference in New Issue
Block a user