public bool CanResolve(CodeLens value) { var textDocumentUri = value.Data.ToObject <Uri>(); return(textDocumentUri != null && _documentSelector.IsMatch(new TextDocumentAttributes(textDocumentUri, string.Empty))); }
public void SimpleTest(string expected) { var model = new CodeLens() { Command = new Command() { Arguments = new JArray { 1, "2", true }, Name = "abc", Title = "Cool story bro" }, Data = JObject.FromObject(new Dictionary <string, object>() { { "somethingCool", 1 } }), Range = new Range(new Position(1, 2), new Position(2, 3)), }; var result = Fixture.SerializeObject(model); result.Should().Be(expected); // TODO: Come back and fix this... var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject <CodeLens>(expected); deresult.Should().BeEquivalentTo(model); }
public void Should_Update_CodeLens_Removing_HandlerType() { // Given var handlerMatcher = new ResolveCommandMatcher(_logger); var resolveHandler = Substitute.For(new Type[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]); (resolveHandler as ICodeLensResolveHandler).CanResolve(Arg.Any <CodeLens>()).Returns(true); var descriptor = new HandlerDescriptor( DocumentNames.CodeLensResolve, "Key", resolveHandler as IJsonRpcHandler, resolveHandler.GetType(), typeof(CodeLens), null, null, () => { }); var item = new CodeLens() { Data = JObject.FromObject(new { data = new { hello = "world" } }) }; item.Data[ResolveCommandMatcher.PrivateHandlerTypeName] = resolveHandler.GetType().FullName; // When var response = handlerMatcher.Process(descriptor, item); // Then response.Should().Be(item); item.Data?[ResolveCommandMatcher.PrivateHandlerTypeName].Should().BeNull(); item.Data["hello"].Value <string>().Should().Be("world"); }
public override async Task <CodeLens> Handle(CodeLens request, CancellationToken token) { var omnisharpRequest = new FindUsagesRequest { FileName = Helpers.FromUri(request.Data.ToObject <Uri>()), Column = (int)request.Range.Start.Character, Line = (int)request.Range.Start.Line, OnlyThisFile = false, ExcludeDefinition = true }; var omnisharpResponse = await _findUsagesHandler.Handle(omnisharpRequest); var length = omnisharpResponse?.QuickFixes?.Count() ?? 0; var jsonCamelCaseContract = new JsonSerializer { ContractResolver = new CamelCasePropertyNamesContractResolver() }; request = request with { Command = new Command { Title = length == 1 ? "1 reference" : $"{length} references", Name = "omnisharp/client/findReferences", Arguments = new JArray( new[]
public async Task CanSendReferencesCodeLensRequest() { string filePath = NewTestFile(@" function CanSendReferencesCodeLensRequest { } CanSendReferencesCodeLensRequest "); CodeLensContainer codeLenses = await LanguageClient.SendRequest <CodeLensContainer>( "textDocument/codeLens", new CodeLensParams { TextDocument = new TextDocumentIdentifier { Uri = new Uri(filePath) } }); CodeLens codeLens = Assert.Single(codeLenses); Range range = codeLens.Range; Assert.Equal(1, range.Start.Line); Assert.Equal(0, range.Start.Character); Assert.Equal(3, range.End.Line); Assert.Equal(1, range.End.Character); CodeLens codeLensResolveResult = await LanguageClient.SendRequest <CodeLens>( "codeLens/resolve", codeLens); Assert.Equal("1 reference", codeLensResolveResult.Command.Title); }
public override bool CanResolve(CodeLens value) { var textDocumentUri = value.Data.ToObject <Uri>(); return(textDocumentUri != null && GetRegistrationOptions().DocumentSelector.IsMatch(new TextDocumentAttributes(textDocumentUri, string.Empty))); }
public static LanguageServer.CodeLens ToProtocolCodeLens( this CodeLens codeLens, JsonSerializer jsonSerializer) { return(new LanguageServer.CodeLens { Range = codeLens.ScriptExtent.ToRange(), Command = codeLens.Command.ToProtocolCommand(jsonSerializer) }); }
public override Task <CodeLens> Handle(CodeLens request, CancellationToken cancellationToken) { // TODO: Catch deserializtion exception on bad object CodeLensData codeLensData = request.Data.ToObject <CodeLensData>(); ICodeLensProvider originalProvider = _symbolsService .GetCodeLensProviders() .FirstOrDefault(provider => provider.ProviderId.Equals(codeLensData.ProviderId, StringComparison.Ordinal)); ScriptFile scriptFile = _workspaceService.GetFile(codeLensData.Uri); return(originalProvider.ResolveCodeLens(request, scriptFile)); }
public async Task Should_Update_CodeLensContainer_With_HandlerType() { // Given var resolveHandler = Substitute.For( new[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler), typeof(ICanBeIdentifiedHandler) }, new object[0] ); (resolveHandler as ICanBeIdentifiedHandler)?.Id.Returns(TrueId); var descriptor = new LspHandlerDescriptor( TextDocumentNames.CodeLens, "Key", resolveHandler as IJsonRpcHandler, resolveHandler.GetType(), typeof(CodeLensParams), null, null, () => false, null, null, () => { }, Substitute.For <ILspHandlerTypeDescriptor>() ); var handlerMatcher = new ResolveCommandPipeline <CodeLensParams, CodeLensContainer>( new RequestContext { Descriptor = descriptor }, Substitute.For <ILogger <ResolveCommandPipeline <CodeLensParams, CodeLensContainer> > >() ); var item = new CodeLens { Data = JObject.FromObject(new { hello = "world" }) }; var list = new CodeLensContainer(item); (list is IEnumerable <ICanBeResolved>).Should().BeTrue(); // When var response = await handlerMatcher.Handle(new CodeLensParams(), CancellationToken.None, () => Task.FromResult(list)); // Then response.Should().BeEquivalentTo(list); response.Should().Contain(item); var responseItem = response.First(); responseItem.Data[Constants.PrivateHandlerId].Value <Guid>().Should().Be(TrueId); responseItem.Data["hello"].Value <string>().Should().Be("world"); }
public async Task Should_Update_CodeLensContainer_With_HandlerType() { // Given var resolveHandler = Substitute.For(new Type[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]); (resolveHandler as ICodeLensResolveHandler).CanResolve(Arg.Any <CodeLens>()).Returns(true); var descriptor = new HandlerDescriptor( DocumentNames.CodeLens, "Key", resolveHandler as IJsonRpcHandler, resolveHandler.GetType(), typeof(CodeLensParams), null, null, false, null, () => { }); var handlerMatcher = new ResolveCommandPipeline <CodeLensParams, CodeLensContainer>( new RequestContext() { Descriptor = descriptor }, Substitute.For <ILogger <ResolveCommandPipeline <CodeLensParams, CodeLensContainer> > >()); var item = new CodeLens() { Data = JObject.FromObject(new { hello = "world" }) }; var list = new CodeLensContainer(new[] { item }); (list is IEnumerable <ICanBeResolved>).Should().BeTrue(); // When var response = await handlerMatcher.Handle(new CodeLensParams(), CancellationToken.None, () => Task.FromResult(list)); // Then response.Should().BeEquivalentTo(list); (response as CodeLensContainer).Should().Contain(item); var responseItem = (response as CodeLensContainer).First(); responseItem.Data[ResolveCommandMatcher.PrivateHandlerTypeName].Value <string>().Should().NotBeNullOrEmpty(); responseItem.Data[ResolveCommandMatcher.PrivateHandlerKey].Value <string>().Should().NotBeNullOrEmpty(); responseItem.Data["data"]["hello"].Value <string>().Should().Be("world"); }
public Task <CodeLens> Handle(CodeLens request, CancellationToken cancellationToken) { // TODO: Catch deserializtion exception on bad object CodeLensData codeLensData = request.Data.ToObject <CodeLensData>(); ICodeLensProvider originalProvider = _providers.FirstOrDefault( provider => provider.ProviderId.Equals(codeLensData.ProviderId)); ScriptFile scriptFile = _workspaceService.GetFile( codeLensData.Uri); var resolvedCodeLens = originalProvider.ResolveCodeLens(request, scriptFile); return(Task.FromResult(resolvedCodeLens)); }
public async Task Should_Update_CodeLens_Removing_HandlerType() { // Given var resolveHandler = Substitute.For(new Type[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]); (resolveHandler as ICodeLensResolveHandler).CanResolve(Arg.Any <CodeLens>()).Returns(true); var descriptor = new LspHandlerDescriptor( TextDocumentNames.CodeLensResolve, "Key", resolveHandler as IJsonRpcHandler, resolveHandler.GetType(), typeof(CodeLens), null, null, () => false, null, null, () => { }, Substitute.For <ILspHandlerTypeDescriptor>()); var handlerMatcher = new ResolveCommandPipeline <CodeLens, CodeLens>( new RequestContext() { Descriptor = descriptor }, Substitute.For <ILogger <ResolveCommandPipeline <CodeLens, CodeLens> > >()); var item = new CodeLens() { Data = JObject.FromObject(new { data = new { hello = "world" } }) }; item.Data[ResolveCommandMatcher.PrivateHandlerTypeName] = resolveHandler.GetType().FullName; // When var response = await handlerMatcher.Handle(item, CancellationToken.None, () => Task.FromResult(item)); // Then response.Should().BeEquivalentTo(item); item.Data?[ResolveCommandMatcher.PrivateHandlerTypeName].Should().BeNull(); item.Data["hello"].Value <string>().Should().Be("world"); }
public static LanguageServer.CodeLens ToProtocolCodeLens( this CodeLens codeLens, object codeLensData, JsonSerializer jsonSerializer) { LanguageServer.ServerCommand command = null; if (codeLens.Command != null) { command = codeLens.Command.ToProtocolCommand(jsonSerializer); } return(new LanguageServer.CodeLens { Range = codeLens.ScriptExtent.ToRange(), Data = JToken.FromObject(codeLensData, jsonSerializer), Command = command }); }
private static void ToCodeLens(TextDocumentIdentifier textDocument, FileMemberElement node, List <CodeLens> codeLensContainer) { var codeLens = new CodeLens { Data = JToken.FromObject(string.IsNullOrEmpty(node.Location.FileName) ? textDocument.Uri : Helpers.ToUri(node.Location.FileName)), Range = node.Location.ToRange() }; codeLensContainer.Add(codeLens); if (node.ChildNodes != null) { foreach (var childNode in node.ChildNodes) { ToCodeLens(textDocument, childNode, codeLensContainer); } } }
private bool GetQualifierAsCodeLens(INode node, out CodeLens codeLens) { codeLens = default(CodeLens); // If the current module is V1 the qualifier types would be unavailable var qualifierType = SemanticModel.GetCurrentQualifierType(node); if (qualifierType == null) { return(false); } var qualifierDeclaration = SemanticModel.GetCurrentQualifierDeclaration(node); if (qualifierDeclaration == null) { return(false); } var formattedQualifier = TypeChecker.TypeToString(qualifierType); var fileUri = qualifierDeclaration.GetSourceFile().ToUri().AbsoluteUri; var range = qualifierDeclaration.ToRange(); codeLens = new CodeLens { Range = node.ToRange(), Command = new Command { Title = FormattableStringEx.I($"Qualifier type: {formattedQualifier}"), CommandIdentifier = "DScript.openDocument", Arguments = new object[] { fileUri, range, }, }, }; return(true); }
public void Should_Update_CodeLensContainer_With_HandlerType() { // Given var handlerMatcher = new ResolveCommandMatcher(_logger); var resolveHandler = Substitute.For(new Type[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]); (resolveHandler as ICodeLensResolveHandler).CanResolve(Arg.Any <CodeLens>()).Returns(true); var descriptor = new HandlerDescriptor( DocumentNames.CodeLens, "Key", resolveHandler as IJsonRpcHandler, resolveHandler.GetType(), typeof(CodeLensParams), null, null, () => { }); var item = new CodeLens() { Data = JObject.FromObject(new { hello = "world" }) }; var list = new CodeLensContainer(new[] { item }); (list is IEnumerable <ICanBeResolved>).Should().BeTrue(); // When var response = handlerMatcher.Process(descriptor, new CodeLensParams(), list); // Then response.Should().Be(list); (response as CodeLensContainer).Should().Contain(item); var responseItem = (response as CodeLensContainer).First(); responseItem.Data[ResolveCommandMatcher.PrivateHandlerTypeName].Value <string>().Should().NotBeNullOrEmpty(); responseItem.Data[ResolveCommandMatcher.PrivateHandlerKey].Value <string>().Should().NotBeNullOrEmpty(); responseItem.Data["data"]["hello"].Value <string>().Should().Be("world"); }
public async override Task <CodeLens> Handle(CodeLens request, CancellationToken token) { var omnisharpRequest = new FindUsagesRequest { FileName = Helpers.FromUri(request.Data.ToObject <Uri>()), Column = (int)request.Range.Start.Character, Line = (int)request.Range.Start.Line, OnlyThisFile = false, ExcludeDefinition = true }; var omnisharpResponse = await _findUsagesHandler.Handle(omnisharpRequest); var length = omnisharpResponse?.QuickFixes?.Count() ?? 0; request.Command = new Command { Title = length == 1 ? "1 reference" : $"{length} references" // TODO: Hook up command. }; return(request); }
public void SimpleTest(string expected) { var model = new CodeLens() { Command = new Command() { Arguments = new object[] { 1, "2", true }, Name = "abc", Title = "Cool story bro" }, Data = new Dictionary <string, object>() { { "somethingCool", 1 } }, Range = new Range(new Position(1, 2), new Position(2, 3)), }; var result = Fixture.SerializeObject(model); result.Should().Be(expected); // TODO: Come back and fix this... //var deresult = JsonConvert.DeserializeObject<CodeLens>(expected); //deresult.ShouldBeEquivalentTo(model); }
public override Task <CodeLens> Handle(CodeLens request, CancellationToken cancellationToken) => Task.FromResult(request);
public abstract Task <CodeLens> Handle(CodeLens request, CancellationToken cancellationToken);
public override Task <CodeLens> Handle(CodeLens request, CancellationToken cancellationToken) => _resolveHandler.Invoke(request, cancellationToken);
public virtual Task <CodeLens> CodeLensResolve(CodeLens item, CancellationToken cancellationToken) => throw new NotImplementedException();
public static Task <CodeLens> CodeLensResolve(this ILanguageClientDocument mediator, CodeLens @params) { return(mediator.SendRequest <CodeLens, CodeLens>(DocumentNames.CodeLensResolve, @params)); }
public bool CanResolve(CodeLens value) { CodeLensData codeLensData = value.Data.ToObject <CodeLensData>(); return(value?.Data != null && _providers.Any(provider => provider.ProviderId.Equals(codeLensData.ProviderId))); }
public override bool CanResolve(CodeLens value) => true;
public static Task <CodeLens> CodeLensResolve(this ILanguageClientDocument mediator, CodeLens @params, CancellationToken cancellationToken = default) { return(mediator.SendRequest(@params, cancellationToken)); }
public IAsyncOperation <CodeLens> ResolveCodeLensAsync(IModel model, CodeLens codeLens) { return(AsyncInfo.Run(delegate(CancellationToken cancelationToken) { return Task.FromResult(codeLens); })); }
public abstract bool CanResolve(CodeLens value);
public abstract RpcResult ResolveCodeLens(CodeLens args);
public override bool CanResolve(CodeLens value) => _canResolve.Invoke(value);