Ejemplo n.º 1
0
        public void intellisenseRequest(KernelMessage msg, IntellisenseRequest content)
        {
            var codeCells = JsonConvert.DeserializeObject <List <String> >(content.text);

            codeCells.Add(headerCode);

            var position   = JsonConvert.DeserializeObject <BlockType>(content.block);
            var lineOffset = 0;

            foreach (var line in codeCells.Take(position.selectedIndex + 1))
            {
                lineOffset += line.Split('\n').Length;
            }

            var realLineNumber = position.line + lineOffset + 1;
            var codeString     = string.Join("\n", codeCells);


            // TODO: Finish implementing intellisense...
            // Evaluation.GetDeclarations(codeString, realLineNumber, position.ch);
            var newContent = new CompleteReply()
            {
                matched_text       = "matched text",
                filter_start_index = 0,
                matches            = new object(),
                status             = "ok"
            };

            sendDisplayData("errors", new object(), "display_data");
            sendMessage(shellSocket, msg, "complete_reply", newContent);
        }
Ejemplo n.º 2
0
        private static void OnCompletionRequestCompleted(CompletionRequestCompleted completionRequestCompleted, IJupyterMessageSender jupyterMessageSender)
        {
            var command = completionRequestCompleted.Command as RequestCompletion;

            var pos   = SourceUtilities.ComputeReplacementStartPosition(command.Code, command.CursorPosition);
            var reply = new CompleteReply(pos, command.CursorPosition, matches: completionRequestCompleted.CompletionList.Select(e => e.InsertText ?? e.DisplayText).ToList());

            jupyterMessageSender.Send(reply);
        }
Ejemplo n.º 3
0
        private static void OnCompletionRequestCompleted(CompletionRequestCompleted completionRequestCompleted, Message request, IMessageSender serverChannel)
        {
            var command = completionRequestCompleted.Command as RequestCompletion;

            var pos   = ComputeReplacementStartPosition(command.Code, command.CursorPosition);
            var reply = new CompleteReply(pos, command.CursorPosition, matches: completionRequestCompleted.CompletionList.Select(e => e.InsertText).ToList());

            var completeReply = Message.CreateResponse(reply, request);

            serverChannel.Send(completeReply);
        }
Ejemplo n.º 4
0
        private static void OnCompletionRequestCompleted(CompletionRequestCompleted completionRequestCompleted, ConcurrentDictionary <IKernelCommand, InflightRequest> openRequests)
        {
            openRequests.TryGetValue(completionRequestCompleted.Command, out var openRequest);
            if (openRequest == null)
            {
                return;
            }

            var pos   = ComputeReplacementStartPosition(openRequest.Request.Code, openRequest.Request.CursorPosition);
            var reply = new CompleteReply(pos, openRequest.Request.CursorPosition, matches: completionRequestCompleted.CompletionList.Select(e => e.InsertText).ToList());

            var completeReply = Message.CreateResponse(reply, openRequest.Context.Request);

            openRequest.Context.ServerChannel.Send(completeReply);
            openRequest.Context.RequestHandlerStatus.SetAsIdle();
            openRequest.Dispose();
        }
Ejemplo n.º 5
0
        private async Task HandleCompleteRequest(ICommandDelivery <JupyterRequestContext> delivery)
        {
            var serverChannel = delivery.Command.ServerChannel;

            var completeRequest = delivery.Command.Request.Content as CompleteRequest;
            var code            = completeRequest.Code;

            var workspace = CreateScaffoldWorkspace(code, completeRequest.CursorPosition);

            var workspaceRequest = new WorkspaceRequest(workspace, activeBufferId: workspace.Buffers.First().Id);

            var result = await _server.GetCompletionList(workspaceRequest);

            var pos   = ComputeReplacementStartPosition(code, completeRequest.CursorPosition);
            var reply = new CompleteReply(pos, completeRequest.CursorPosition, matches: result.Items.Select(e => e.InsertText).ToList());

            var completeReply = Message.CreateResponseMessage(reply, delivery.Command.Request);

            serverChannel.Send(completeReply);
        }
Ejemplo n.º 6
0
        public void Complete_reply_contract_has_not_been_broken()
        {
            var socket = new TextSocket();
            var sender = new MessageSender(socket, new SignatureValidator("key", "HMACSHA256"));

            var completeReply = new CompleteReply(0, 0, matches: new List <string> {
                "Write", "WriteLine"
            });

            var header = new Header(messageType: JupyterMessageContentTypes.CompleteReply, messageId: Guid.Empty.ToString(),
                                    version: "5.3", username: Constants.USERNAME, session: "test session",
                                    date: DateTime.MinValue.ToString("yyyy-MM-ddTHH:mm:ssZ"));

            var replyMessage = new Message(header, content: completeReply);

            sender.Send(replyMessage);

            var encoded = socket.GetEncodedMessage();

            this.Assent(encoded, _configuration);
        }
Ejemplo n.º 7
0
        private static void OnCompletionRequestCompleted(CompletionRequestCompleted completionRequestCompleted, IJupyterMessageSender jupyterMessageSender)
        {
            var command = completionRequestCompleted.Command as RequestCompletion;

            int startPosition, endPosition;

            if (completionRequestCompleted.ReplacementStartIndex != null)
            {
                startPosition = completionRequestCompleted.ReplacementStartIndex.Value;
                endPosition   = completionRequestCompleted.ReplacementEndIndex.Value;
            }
            else
            {
                startPosition = SourceUtilities.ComputeReplacementStartPosition(command.Code, command.CursorPosition);
                endPosition   = command.CursorPosition;
            }

            var reply = new CompleteReply(startPosition, endPosition, matches: completionRequestCompleted.CompletionList.Select(e => e.InsertText ?? e.DisplayText).ToList());

            jupyterMessageSender.Send(reply);
        }
        private static void OnCompletionRequestCompleted(CompletionRequestCompleted completionRequestCompleted, IJupyterMessageSender jupyterMessageSender)
        {
            var command = completionRequestCompleted.Command as RequestCompletion;

            int startPosition, endPosition;

            if (completionRequestCompleted.Range != null)
            {
                startPosition = SourceUtilities.GetCursorOffsetFromPosition(command.Code, completionRequestCompleted.Range.GetValueOrDefault().Start);
                endPosition   = SourceUtilities.GetCursorOffsetFromPosition(command.Code, completionRequestCompleted.Range.GetValueOrDefault().End);
            }
            else
            {
                var cursorOffset = SourceUtilities.GetCursorOffsetFromPosition(command.Code, command.Position);
                startPosition = SourceUtilities.ComputeReplacementStartPosition(command.Code, cursorOffset);
                endPosition   = cursorOffset;
            }

            var reply = new CompleteReply(startPosition, endPosition, matches: completionRequestCompleted.CompletionList.Select(e => e.InsertText ?? e.DisplayText).ToList());

            jupyterMessageSender.Send(reply);
        }
Ejemplo n.º 9
0
        public void HandleMessage(Message message, RouterSocket serverSocket, PublisherSocket ioPub)
        {
            CompleteRequest completeRequest = JsonSerializer.Deserialize <CompleteRequest>(message.Content);

            string code = completeRequest.CodeCells[0];
            string line = completeRequest.Line;

            code = Regex.Replace(code.Substring(1, code.Length - 2), @"\\n", "*");
            line = line.Substring(1, line.Length - 2);

            int cur_pos = completeRequest.CursorPosition;

            this.logger.Info("cur_pos " + cur_pos);

            line = line.Substring(0, cur_pos); //get substring of code from start to cursor position

            List <CompleteReplyMatch> matches_ = new List <CompleteReplyMatch>();

            string cursorWord = FindWordToAutoComplete(line);

            CompleteReply completeReply = new CompleteReply()
            {
                //CursorEnd = 10,
                Matches = matches_,
                Status  = "ok",
                //CursorStart = 5,
                // MetaData = null
            };



            Message completeReplyMessage = MessageBuilder.CreateMessage(MessageTypeValues.CompleteReply, JsonSerializer.Serialize(completeReply), message.Header);

            this.logger.Info("Sending complete_reply");
            this.messageSender.Send(completeReplyMessage, serverSocket);
        }
Ejemplo n.º 10
0
        private static void OnCompletionRequestCompleted(CompletionsProduced completionsProduced, IJupyterMessageSender jupyterMessageSender)
        {
            var startPosition = 0;
            var endPosition   = 0;

            if (completionsProduced.Command is RequestCompletions command)
            {
                if (completionsProduced.LinePositionSpan is not null)
                {
                    startPosition = SourceUtilities.GetCursorOffsetFromPosition(command.Code, completionsProduced.LinePositionSpan.Start);
                    endPosition   = SourceUtilities.GetCursorOffsetFromPosition(command.Code, completionsProduced.LinePositionSpan.End);
                }
                else
                {
                    var cursorOffset = SourceUtilities.GetCursorOffsetFromPosition(command.Code, command.LinePosition);
                    startPosition = SourceUtilities.ComputeReplacementStartPosition(command.Code, cursorOffset);
                    endPosition   = cursorOffset;
                }
            }

            var reply = new CompleteReply(startPosition, endPosition, matches: completionsProduced.Completions.Select(e => e.InsertText ?? e.DisplayText).ToList());

            jupyterMessageSender.Send(reply);
        }