Ejemplo n.º 1
0
        public async Task ExecuteAsync(AsyncData data, WorkSession session, ICommandResultSender sender, CancellationToken cancellationToken)
        {
            var roslynSession = session.Roslyn;

            var actionId = FastConvert.Utf8ByteArrayToInt32(data.GetFirst());
            var action   = roslynSession.CurrentCodeActions[actionId];

            var operations = await action.GetOperationsAsync(cancellationToken).ConfigureAwait(false);

            foreach (var operation in operations)
            {
                operation.Apply(roslynSession.Workspace, cancellationToken);
            }
            // I rollback the changes since I want to send them to client and get them back as ReplaceText
            // This makes sure any other typing on client merges with these changes properly
            var changes = await roslynSession.RollbackWorkspaceChangesAsync().ConfigureAwait(false);

            var writer = sender.StartJsonMessage("changes");

            writer.WriteProperty("reason", "fix");
            writer.WritePropertyStartArray("changes");
            foreach (var change in changes)
            {
                writer.WriteChange(change);
            }
            writer.WriteEndArray();
            await sender.SendJsonMessageAsync(cancellationToken).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        public Task ExecuteAsync(AsyncData data, WorkSession session, ICommandResultSender sender, CancellationToken cancellationToken)
        {
            var first     = data.GetFirst();
            var firstByte = first.Array[first.Offset];

            if (firstByte == (byte)'I')
            {
                var infoItemIndex = FastConvert.Utf8ByteArrayToInt32(first.Skip(1));
                return(_completion.SendItemInfoAsync(infoItemIndex, session, sender, cancellationToken));
            }

            if (firstByte == (byte)'X')
            {
                return(_completion.CancelCompletionAsync(session, sender, cancellationToken));
            }

            if (firstByte == (byte)'F')
            {
                return(_completion.ForceCompletionAsync(session, sender, cancellationToken));
            }

            var itemIndex = FastConvert.Utf8ByteArrayToInt32(first);

            return(_completion.SelectCompletionAsync(itemIndex, session, sender, cancellationToken));
        }
Ejemplo n.º 3
0
        public Task ExecuteAsync(AsyncData data, WorkSession session, ICommandResultSender sender, CancellationToken cancellationToken)
        {
            var cursorPosition = FastConvert.Utf8ByteArrayToInt32(data.GetFirst());

            session.CursorPosition = cursorPosition;
            return(_signatureHelp.ApplyCursorPositionChangeAsync(session, sender, cancellationToken));
        }
Ejemplo n.º 4
0
        public Task ExecuteAsync(AsyncData data, WorkSession session, ICommandResultSender sender, CancellationToken cancellationToken)
        {
            var @char = FastConvert.Utf8ByteArrayToChar(data.GetFirst());

            session.ReplaceText(FastConvert.CharToString(@char), session.CursorPosition, 0);
            session.CursorPosition += 1;

            return(_effects.ApplyTypedCharAsync(@char, session, sender, cancellationToken));
        }
Ejemplo n.º 5
0
        public async Task ExecuteAsync(AsyncData data, WorkSession session, ICommandResultSender sender, CancellationToken cancellationToken)
        {
            var first     = data.GetFirst();
            var endOffset = first.Offset + first.Count - 1;
            var partStart = first.Offset;

            int?   start          = null;
            int?   length         = null;
            int?   cursorPosition = null;
            string?reason         = null;

            for (var i = first.Offset; i <= endOffset; i++)
            {
                if (first.Array[i] != (byte)':')
                {
                    continue;
                }

                var part = new ArraySegment <byte>(first.Array, partStart, i - partStart);
                if (start == null)
                {
                    start     = FastConvert.Utf8ByteArrayToInt32(part);
                    partStart = i + 1;
                    continue;
                }

                if (length == null)
                {
                    length    = FastConvert.Utf8ByteArrayToInt32(part);
                    partStart = i + 1;
                    continue;
                }

                if (cursorPosition == null)
                {
                    cursorPosition = FastConvert.Utf8ByteArrayToInt32(part);
                    partStart      = i + 1;
                    continue;
                }

                reason    = part.Count > 0 ? Encoding.UTF8.GetString(part) : string.Empty;
                partStart = i + 1;
                break;
            }
            if (start == null || length == null || cursorPosition == null || reason == null)
            {
                throw new FormatException("Command arguments must be 'start:length:cursor:reason:text'.");
            }

            var text = await AsyncDataConvert.ToUtf8StringAsync(data, partStart - first.Offset, _charArrayPool).ConfigureAwait(false);

            session.ReplaceText(text, start.Value, length.Value);
            session.CursorPosition = cursorPosition.Value;
            await _signatureHelp.ApplyCursorPositionChangeAsync(session, sender, cancellationToken).ConfigureAwait(false);

            await _completion.ApplyReplacedTextAsync(reason, _typedCharEffects, session, sender, cancellationToken).ConfigureAwait(false);
        }
Ejemplo n.º 6
0
        public Task ExecuteAsync(AsyncData data, WorkSession session, ICommandResultSender sender, CancellationToken cancellationToken)
        {
            if (!session.IsRoslyn)
            {
                return(Task.CompletedTask);
            }

            var cursorPosition = FastConvert.Utf8ByteArrayToInt32(data.GetFirst());

            return(ExecuteForRoslynAsync(cursorPosition, session, sender, cancellationToken));
        }
Ejemplo n.º 7
0
        public Task ExecuteAsync(AsyncData data, WorkSession session, ICommandResultSender sender, CancellationToken cancellationToken)
        {
            var @char = FastConvert.Utf8ByteArrayToChar(data.GetFirst());

            if (@char != 'F')
            {
                // ReSharper disable once HeapView.BoxingAllocation
                throw new FormatException($"Unknown SignatureHelp command '{@char}'.");
            }

            return(_signatureHelp.ForceSignatureHelpAsync(session, sender, cancellationToken));
        }