Ejemplo n.º 1
0
        protected override async Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(CancellationToken cancellationToken)
        {
            // If we have a command, return an operation that will execute the command on the host side.
            if (_command != null)
            {
                var operation = new RoslynRemoteCodeActionOperation(_command, _lspClient);
                return(ImmutableArray.Create(operation));
            }

            // We have a codeaction - create an applychanges operation from it.
            var operations  = new LinkedList <CodeActionOperation>();
            var newSolution = _document.Project.Solution;

            foreach (var changePair in _codeActionWorkspaceEdit.Changes)
            {
                var documentName = await _lspClient.ProtocolConverter.FromProtocolUriAsync(new Uri(changePair.Key), true, cancellationToken).ConfigureAwait(false);

                // The document name here is a document URI that we're trying to apply an edit to. The edit was already computed on the
                // server and we're trying to create an equivalent copy on the client; we're only fetching the text of the document
                // rather than any syntax trees, and so it doesn't matter from which context we grab if there are linked files --
                // all the files are the same and modifying any of them is fine.
                var doc = newSolution.GetDocuments(documentName).First();
                if (doc == null)
                {
                    continue;
                }

                var newDoc = await ApplyEditsAsync(doc, changePair.Value, cancellationToken).ConfigureAwait(false);

                newSolution = newDoc.Project.Solution;
            }
            operations.AddLast(new ApplyChangesOperation(newSolution));

            if (_codeActionCommand != null)
            {
                operations.AddLast(new RoslynRemoteCodeActionOperation(_codeActionCommand, _lspClient));
            }

            return(operations.AsImmutable());
        }
Ejemplo n.º 2
0
        protected override async Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(CancellationToken cancellationToken)
        {
            // If we have a command, return an operation that will execute the command on the host side.
            if (_command != null)
            {
                var operation = new RoslynRemoteCodeActionOperation(_command, _lspClient);
                return(ImmutableArray.Create(operation));
            }

            // We have a codeaction - create an applychanges operation from it.
            var operations  = new LinkedList <CodeActionOperation>();
            var newSolution = _document.Project.Solution;

            foreach (var changePair in _codeActionWorkspaceEdit.Changes)
            {
                var documentName = await _lspClient.ProtocolConverter.FromProtocolUriAsync(new Uri(changePair.Key), true, cancellationToken).ConfigureAwait(false);

                var doc = newSolution.GetDocumentFromURI(documentName);
                if (doc == null)
                {
                    continue;
                }

                var newDoc = await ApplyEditsAsync(doc, changePair.Value, cancellationToken).ConfigureAwait(false);

                newSolution = newDoc.Project.Solution;
            }
            operations.AddLast(new ApplyChangesOperation(newSolution));

            if (_codeActionCommand != null)
            {
                operations.AddLast(new RoslynRemoteCodeActionOperation(_codeActionCommand, _lspClient));
            }

            return(operations.AsImmutable());
        }