Пример #1
0
        private IEnumerable <CompletionItem> CreateSnippets(FuncDefinitionAst ast)
        {
            if (ast != null)
            {
                yield return(CreateSnippetItem("letc", "let ${1:foo} = $2"));

                yield return(CreateSnippetItem("if", "if ($1) {\n\t$2\n}"));

                yield return(CreateSnippetItem("else", "else {\n\t$1\n}"));

                yield return(CreateSnippetItem("elseif", "else if ($1) {\n\t$2\n}"));

                yield return(CreateSnippetItem("while", "while ($1) {\n\t$2\n}"));

                yield return(CreateSnippetItem("for", "for ${1:i} = $2, $3, $4 {\n\t$5\n}"));

                yield return(CreateSnippetItem("foreach", "foreach ${1:val} in $2 {\n\t$3\n}"));

                yield return(CreateSnippetItem("letac", "let ${1:foo} = {|$2| $3}"));
            }
            else
            {
                yield return(CreateSnippetItem("fun", "fun ${1:foo}()\n\t$2\nend"));
            }
        }
Пример #2
0
        public async Task <CompletionList> Handle(CompletionParams request, CancellationToken cancellationToken)
        {
            var text   = _workspaceService.GetMarineFileBuffer(request.TextDocument.Uri.Path);
            var tokens = new LexicalAnalyzer().GetTokens(text);
            var result = new SyntaxAnalyzer().Parse(tokens);

            var tasks = new List <Task <IEnumerable <CompletionItem> > >();
            FuncDefinitionAst currentFuncDefAst = null;

            if (result.programAst != null)
            {
                currentFuncDefAst = await Task.Run(() => GetCurrentFunctionAst(result.programAst, request.Position),
                                                   cancellationToken);

                if (currentFuncDefAst != null)
                {
                    tasks.Add(Task.Run(() => CreateFunctions(result.programAst), cancellationToken));

                    tasks.Add(Task.Run(() => CreateFunctionParamaters(currentFuncDefAst), cancellationToken));
                    tasks.Add(Task.Run(() => CreateVariables(currentFuncDefAst, request.Position), cancellationToken));

                    tasks.Add(Task.Run(CreateKeywords, cancellationToken));
                }
            }

            tasks.Add(Task.Run(() => CreateSnippets(currentFuncDefAst), cancellationToken));

            return(new CompletionList((await Task.WhenAll(tasks)).SelectMany(e => e)));
        }
Пример #3
0
 private IEnumerable <CompletionItem> CreateVariables(FuncDefinitionAst ast, Position position)
 {
     return(ast.LookUp <AssignmentVariableAst>().Select(e => CreateCompletionItem(e.variableAst.VarName,
                                                                                  CompletionItemKind.Variable, $"local variable {e.variableAst.VarName}")));
 }
Пример #4
0
 private IEnumerable <CompletionItem> CreateFunctionParamaters(FuncDefinitionAst ast)
 {
     return(ast.args.Select(e =>
                            CreateCompletionItem(e.VarName, CompletionItemKind.Variable, $"paramater {e.VarName}")));
 }