Exemplo n.º 1
0
        public object OnCodeAction(JToken arg)
        {
            Command BuildCommand(string title, WorkspaceEdit edit)
            {
                var commandArgs = new ApplyWorkspaceEditParams {
                    Label = $"code action \"{title}\"", Edit = edit
                };

                return(new Command {
                    Title = title, CommandIdentifier = CommandIds.ApplyEdit, Arguments = new object[] { commandArgs }
                });
            }

            if (this.waitForInit != null)
            {
                return(ProtocolError.AwaitingInitialization);
            }
            var param = Utils.TryJTokenAs <Workarounds.CodeActionParams>(arg).ToCodeActionParams();

            try
            {
                //return
                //    QsCompilerError.RaiseOnFailure(
                //        () => this.editorState.CodeActions(param)
                //            ?.SelectMany(vs => vs.Select(v => BuildCommand(vs.Key, v)))
                //            ?? Enumerable.Empty<Command>(),
                //        "CodeAction threw an exception")
                //    .ToArray();
            }
            catch
            {
                return(Array.Empty <Command>());
            }
            return(Array.Empty <Command>());
        }
Exemplo n.º 2
0
        public void NonStandardCharactersTest(string expected)
        {
            var model = new ApplyWorkspaceEditParams {
                Edit = new WorkspaceEdit {
                    Changes = new Dictionary <DocumentUri, IEnumerable <TextEdit> > {
                        {
                            // Mörkö
                            new Uri("file:///abc/bc/123/M%C3%B6rk%C3%B6.cs"), new[] {
                                new TextEdit {
                                    NewText = "new text",
                                    Range   = new Range(new Position(1, 1), new Position(2, 2))
                                },
                                new TextEdit {
                                    NewText = "new text2",
                                    Range   = new Range(new Position(3, 3), new Position(4, 4))
                                }
                            }
                        }
                    }
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <ApplyWorkspaceEditParams>(expected);

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
        public void SimpleTest(string expected)
        {
            var model = new ApplyWorkspaceEditParams()
            {
                Edit = new WorkspaceEdit()
                {
                    Changes = new Dictionary <DocumentUri, IEnumerable <TextEdit> >()
                    {
                        {
                            new Uri("file:///abc/123/d.cs"), new [] {
                                new TextEdit()
                                {
                                    NewText = "new text",
                                    Range   = new Range(new Position(1, 1), new Position(2, 2))
                                },
                                new TextEdit()
                                {
                                    NewText = "new text2",
                                    Range   = new Range(new Position(3, 3), new Position(4, 4))
                                }
                            }
                        }
                    }
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject <ApplyWorkspaceEditParams>(expected);

            deresult.Should().BeEquivalentTo(model);
        }
Exemplo n.º 4
0
        public void DocumentChangesTest(string expected)
        {
            var model = new ApplyWorkspaceEditParams()
            {
                Edit = new WorkspaceEdit()
                {
                    DocumentChanges = new Container <TextDocumentEdit>(
                        new TextDocumentEdit()
                    {
                        TextDocument = new VersionedTextDocumentIdentifier()
                        {
                            Version = 1,
                            Uri     = new Uri("file:///abc/123/d.cs"),
                        },
                        Edits = new[] {
                            new TextEdit()
                            {
                                NewText = "new text",
                                Range   = new Range(new Position(1, 1), new Position(2, 2))
                            },
                            new TextEdit()
                            {
                                NewText = "new text2",
                                Range   = new Range(new Position(3, 3), new Position(4, 4))
                            }
                        }
                    },
                        new TextDocumentEdit()
                    {
                        TextDocument = new VersionedTextDocumentIdentifier()
                        {
                            Version = 1,
                            Uri     = new Uri("file:///abc/123/b.cs"),
                        },
                        Edits = new[] {
                            new TextEdit()
                            {
                                NewText = "new text2",
                                Range   = new Range(new Position(1, 1), new Position(2, 2))
                            },
                            new TextEdit()
                            {
                                NewText = "new text3",
                                Range   = new Range(new Position(3, 3), new Position(4, 4))
                            }
                        }
                    }
                        )
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = JsonConvert.DeserializeObject <ApplyWorkspaceEditParams>(expected);

            deresult.ShouldBeEquivalentTo(model);
        }
Exemplo n.º 5
0
        public Task <Result <ApplyWorkspaceEditResponse, ResponseError> > ApplyEdit(ApplyWorkspaceEditParams @params)
        {
            TaskCompletionSource <Result <ApplyWorkspaceEditResponse, ResponseError> > tcs = new TaskCompletionSource <Result <ApplyWorkspaceEditResponse, ResponseError> >();

            connection.SendRequest(
                new RequestMessage <ApplyWorkspaceEditParams>
            {
                Id     = IdGenerator.instance.Next(),
                Method = "workspace/applyEdit",
                Params = @params
            },
                (ResponseMessage <ApplyWorkspaceEditResponse, ResponseError> res) => tcs.TrySetResult(Message.ToResult(res)));
            return(tcs.Task);
        }
Exemplo n.º 6
0
        public bool ApplyEdit(string transaction_name, Dictionary <string, LspTypes.TextEdit[]> changes)
        {
            WorkspaceEdit edit = new WorkspaceEdit()
            {
                Changes = changes
            };
            ApplyWorkspaceEditParams parameter = new ApplyWorkspaceEditParams
            {
                Label = transaction_name,
                Edit  = edit
            };

            _ = rpc.InvokeAsync <ApplyWorkspaceEditResponse>(Methods.WorkspaceApplyEditName, parameter);
            return(true);
        }
        public Task <ApplyWorkspaceEditResponse> ApplyWorkspaceEdit(ApplyWorkspaceEditParams @params)
        {
            var evt = OnApplyWorkspaceEdit;

            if (evt == null)
            {
                return(Task.FromResult((ApplyWorkspaceEditResponse)null));
            }
            var tcs = new TaskCompletionSource <ApplyWorkspaceEditResponse>();
            var e   = new ApplyWorkspaceEditEventArgs(tcs)
            {
                @params = @params
            };

            evt(this, e);
            return(tcs.Task);
        }
Exemplo n.º 8
0
        public void DocumentChangesTest(string expected)
        {
            var model = new ApplyWorkspaceEditParams {
                Edit = new WorkspaceEdit {
                    DocumentChanges = new Container <WorkspaceEditDocumentChange>(
                        new TextDocumentEdit {
                        TextDocument = new OptionalVersionedTextDocumentIdentifier {
                            Version = 1,
                            Uri     = new Uri("file:///abc/123/d.cs"),
                        },
                        Edits = new[] {
                            new TextEdit {
                                NewText = "new text",
                                Range   = new Range(new Position(1, 1), new Position(2, 2))
                            },
                            new TextEdit {
                                NewText = "new text2",
                                Range   = new Range(new Position(3, 3), new Position(4, 4))
                            }
                        }
                    },
                        new TextDocumentEdit {
                        TextDocument = new OptionalVersionedTextDocumentIdentifier {
                            Version = 1,
                            Uri     = new Uri("file:///abc/123/b.cs"),
                        },
                        Edits = new[] {
                            new TextEdit {
                                NewText = "new text2",
                                Range   = new Range(new Position(1, 1), new Position(2, 2))
                            },
                            new TextEdit {
                                NewText = "new text3",
                                Range   = new Range(new Position(3, 3), new Position(4, 4))
                            }
                        }
                    },
                        new CreateFile {
                        Uri     = "file:///abc/123/b.cs",
                        Options = new CreateFileOptions {
                            IgnoreIfExists = true,
                            Overwrite      = true
                        }
                    },
                        new RenameFile {
                        OldUri  = "file:///abc/123/b.cs",
                        NewUri  = "file:///abc/123/c.cs",
                        Options = new RenameFileOptions {
                            IgnoreIfExists = true,
                            Overwrite      = true
                        }
                    },
                        new DeleteFile {
                        Uri     = "file:///abc/123/c.cs",
                        Options = new DeleteFileOptions {
                            IgnoreIfNotExists = true,
                            Recursive         = false
                        }
                    }
                        )
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = new LspSerializer(ClientVersion.Lsp3).DeserializeObject <ApplyWorkspaceEditParams>(expected);

            deresult.Should().BeEquivalentTo(
                model, x => x.UsingStructuralRecordEquality()
                .ComparingByMembers <WorkspaceEditDocumentChange>()
                //.ComparingByMembers<CreateFile>()
                //.ComparingByMembers<RenameFile>()
                //.ComparingByMembers<DeleteFile>()
                //.ComparingByMembers<CreateFileOptions>()
                //.ComparingByMembers<RenameFileOptions>()
                //.ComparingByMembers<DeleteFileOptions>()
                //.ComparingByMembers<TextDocumentEdit>()
                );
        }
 public static Task <ApplyWorkspaceEditResponse> ApplyEdit(this ILanguageServerWorkspace mediator, ApplyWorkspaceEditParams @params, CancellationToken cancellationToken = default)
 {
     return(mediator.SendRequest(@params, cancellationToken));
 }
 public abstract Task <ApplyWorkspaceEditResponse> Handle(ApplyWorkspaceEditParams request, CancellationToken cancellationToken);
 public override Task <ApplyWorkspaceEditResponse> Handle(ApplyWorkspaceEditParams request, CancellationToken cancellationToken) => _handler.Invoke(request);
Exemplo n.º 12
0
 public static Task <ApplyWorkspaceEditResponse> ApplyEdit(this ILanguageServerWorkspace mediator, ApplyWorkspaceEditParams @params)
 {
     return(mediator.SendRequest <ApplyWorkspaceEditParams, ApplyWorkspaceEditResponse>(WorkspaceNames.ApplyEdit, @params));
 }