public override Task <CodeLensContainer> Handle(CodeLensParams request, CancellationToken cancellationToken) { ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri); CodeLens[] codeLensResults = ProvideCodeLenses(scriptFile); return(Task.FromResult(new CodeLensContainer(codeLensResults))); }
/// <summary> /// Called to provide a list of Code Lens annotations that apply to ranges within the specified document from the workspace /// </summary> public Result <CodeLens[], ResponseError> CodeLens(CodeLensParams @params, CancellationToken token) { // TODO: support cancellation var fileUri = new Uri(@params.TextDocument.Uri); var pathToFile = fileUri.ToAbsolutePath(PathTable); var codeLensObjs = new List <CodeLens>(); // If it's not in the workspace (e.g. a configuration file), then we don't provide codelens if (Workspace.TryGetSourceFile(pathToFile, out var spec)) { // Need to get module definition for a given source file to check the module kind. // If the module is V1 module or configuration file, then the result should be empty var module = Workspace.TryGetModuleBySpecFileName(spec.GetAbsolutePath(PathTable)); if (module == null || module.Definition.ResolutionSemantics == NameResolutionSemantics.ExplicitProjectReferences || Workspace.IsPreludeOrConfigurationModule(module)) { // This specific module does not have any qualifiers. return(Result <CodeLens[], ResponseError> .Success(codeLensObjs.ToArray())); } codeLensObjs.AddRange(GetQualifierTypeForModulesAndTopLevelDeclarations(spec)); } return(Result <CodeLens[], ResponseError> .Success(codeLensObjs.ToArray())); }
public async Task <CodeLensContainer> Handle(CodeLensParams request, CancellationToken cancellationToken) { await _languageServer.DocumentHandler.WaitForParse(); var codeLenses = _languageServer.LastParse?.ScriptFromUri(request.TextDocument.Uri.ToUri())?.GetCodeLensRanges(); if (codeLenses == null) { return(new CodeLensContainer()); } List <CodeLens> finalLenses = new List <CodeLens>(); foreach (var lens in codeLenses) { // Do not show references for scoped variables and parameters. if (lens.SourceType != CodeLensSourceType.ScopedVariable && lens.SourceType != CodeLensSourceType.ParameterVariable // Check if the lens should be used. && lens.ShouldUse() // Check if the code lens type is enabled. && LensIsEnabled(lens)) { // Create the CodeLens. finalLenses.Add(new CodeLens() { Command = lens.GetCommand(), Range = lens.Range }); } } return(finalLenses); }
public async Task ShouldRouteToCorrect_Request_WithManyHandlers_CodeLensHandler() { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentSyncHandler2 = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cake"), "csharp"); textDocumentSyncHandler.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); textDocumentSyncHandler2.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); var codeActionHandler = Substitute.For <ICodeLensHandler>(); codeActionHandler.GetRegistrationOptions().Returns(new CodeLensRegistrationOptions { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") }); codeActionHandler .Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()) .Returns(new CodeLensContainer()); var codeActionHandler2 = Substitute.For <ICodeLensHandler>(); codeActionHandler2.GetRegistrationOptions().Returns(new CodeLensRegistrationOptions { DocumentSelector = DocumentSelector.ForPattern("**/*.cake") }); codeActionHandler2 .Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()) .Returns(new CodeLensContainer()); var tdi = new TextDocumentIdentifiers(); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, tdi, new ServiceCollection().BuildServiceProvider()) { textDocumentSyncHandler, textDocumentSyncHandler2, codeActionHandler, codeActionHandler2 }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); AutoSubstitute.Provide <IHandlerMatcher>(new TextDocumentMatcher(LoggerFactory.CreateLogger <TextDocumentMatcher>(), tdi)); var mediator = AutoSubstitute.Resolve <LspRequestRouter>(); var id = Guid.NewGuid().ToString(); var @params = new CodeLensParams { TextDocument = new TextDocumentIdentifier(new Uri("file:///c:/test/123.cs")) }; var request = new Request( id, TextDocumentNames.CodeLens, JObject.Parse(JsonConvert.SerializeObject(@params, new Serializer(ClientVersion.Lsp3).Settings)) ); await mediator.RouteRequest(mediator.GetDescriptors(request), request, CancellationToken.None); await codeActionHandler2.Received(0).Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()); await codeActionHandler.Received(1).Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()); }
protected void RunCodeLens(string testfile) { CodeLensParams codeLensParams = new CodeLensParams { TextDocument = new TextDocumentIdentifier(new Uri(testfile)) }; Client.TextDocument.DidOpen(testfile, "dfy"); var response = Client.SendRequest <CodeLensContainer>("textDocument/codeLens", codeLensParams, CancellationToken.None); codelensResults = response.Result; }
public void SimpleTest(string expected) { var model = new CodeLensParams { TextDocument = new TextDocumentIdentifier(new Uri("file:///abc/123/d.cs")), }; var result = Fixture.SerializeObject(model); result.Should().Be(expected); var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject <CodeLensParams>(expected); deresult.Should().BeEquivalentTo(model); }
public void NonStandardCharactersTest(string expected) { var model = new CodeLensParams { // UNC path with Chinese character for tree. TextDocument = new TextDocumentIdentifier(DocumentUri.FromFileSystemPath("\\\\abc\\123\\ТаЉ.cs")), }; var result = Fixture.SerializeObject(model); result.Should().Be(expected); var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject <CodeLensParams>(expected); deresult.Should().BeEquivalentTo(model); }
public async Task ShouldRouteToCorrect_Request_WithManyHandlers_CodeLensHandler() { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs")); var textDocumentSyncHandler2 = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cake")); textDocumentSyncHandler.Handle(Arg.Any <DidSaveTextDocumentParams>()).Returns(Task.CompletedTask); textDocumentSyncHandler2.Handle(Arg.Any <DidSaveTextDocumentParams>()).Returns(Task.CompletedTask); var codeActionHandler = Substitute.For <ICodeLensHandler>(); codeActionHandler.GetRegistrationOptions().Returns(new CodeLensRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") }); codeActionHandler .Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()) .Returns(new CodeLensContainer()); var codeActionHandler2 = Substitute.For <ICodeLensHandler>(); codeActionHandler2.GetRegistrationOptions().Returns(new CodeLensRegistrationOptions() { DocumentSelector = DocumentSelector.ForPattern("**/*.cake") }); codeActionHandler2 .Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()) .Returns(new CodeLensContainer()); var collection = new HandlerCollection { textDocumentSyncHandler, textDocumentSyncHandler2, codeActionHandler, codeActionHandler2 }; var handlerMatcherCollection = new HandlerMatcherCollection { new TextDocumentMatcher(_testLoggerFactory.CreateLogger <TextDocumentMatcher>(), collection.TextDocumentSyncHandlers) }; var mediator = new LspRequestRouter(collection, _testLoggerFactory, handlerMatcherCollection, new Serializer()); var id = Guid.NewGuid().ToString(); var @params = new CodeLensParams() { TextDocument = new TextDocumentIdentifier(new Uri("file:///c:/test/123.cs")) }; var request = new Request(id, DocumentNames.CodeLens, JObject.Parse(JsonConvert.SerializeObject(@params, new Serializer(ClientVersion.Lsp3).Settings))); await mediator.RouteRequest(mediator.GetDescriptor(request), request); await codeActionHandler2.Received(0).Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()); await codeActionHandler.Received(1).Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()); }
public async Task <CodeLensContainer> Handle(CodeLensParams request, CancellationToken cancellationToken) { _log.LogInformation(string.Format(Resources.LoggingMessages.request_handle, _method)); try { var fileRepo = _workspaceManager.GetFileRepository(request.TextDocument.Uri); ICodeLensProvider provider = new CodeLensProvider(fileRepo); return(await Task.Run(() => provider.GetCodeLensContainer(), cancellationToken)); } catch (Exception e) { HandleError(string.Format(Resources.LoggingMessages.request_error, _method), e); return(null); } }
public async override Task <CodeLensContainer> Handle(CodeLensParams request, CancellationToken token) { var omnisharpRequest = new MembersTreeRequest() { FileName = Helpers.FromUri(request.TextDocument.Uri), }; var omnisharpResponse = await _membersAsTreeHandler.Handle(omnisharpRequest); var codeLenseContainer = new List <CodeLens>(); foreach (var node in omnisharpResponse.TopLevelTypeDefinitions) { ToCodeLens(request.TextDocument, node, codeLenseContainer); } return(codeLenseContainer); }
public async Task <CodeLensContainer> Handle(CodeLensParams request, CancellationToken cancellationToken) { _languageServer.DocumentHandler.WaitForNextUpdate(); var codeLenses = _languageServer.LastParse?.ScriptFromUri(request.TextDocument.Uri)?.GetCodeLensRanges(); if (codeLenses == null) { return(new CodeLensContainer()); } List <CodeLens> finalLenses = new List <CodeLens>(); foreach (var lens in codeLenses) { // Do not show references for scoped variables and parameters. if (lens.SourceType != CodeLensSourceType.ScopedVariable && lens.SourceType != CodeLensSourceType.ParameterVariable // Check if the lens should be used. && lens.ShouldUse() // Check if the code lens type is enabled. && ((_languageServer.ConfigurationHandler.ReferencesCodeLens && lens is ReferenceCodeLensRange) || (_languageServer.ConfigurationHandler.ImplementsCodeLens && lens is ImplementsCodeLensRange)) ) { // Create the CodeLens. finalLenses.Add(new CodeLens() { Command = new Command() { Title = lens.GetTitle(), Name = lens.Command, Arguments = lens.GetArguments() }, Range = lens.Range.ToLsRange() }); } } return(finalLenses); }
public override async Task <CodeLensContainer> Handle(CodeLensParams request, CancellationToken cancellationToken) { var partial = _progressManager.For(request, cancellationToken); var workDone = _workDoneManager.For( request, new WorkDoneProgressBegin { Cancellable = true, Message = "Begin", Percentage = 0, Title = "Work is pending" }, onComplete: () => new WorkDoneProgressEnd { Message = "End" } ); partial.OnNext( new[] { new CodeLens { Command = new Command { Name = "CodeLens 1" } }, } ); workDone.OnNext( new WorkDoneProgressReport { Percentage = 10, Message = "Report 1" } ); partial.OnNext( new[] { new CodeLens { Command = new Command { Name = "CodeLens 2" } }, } ); workDone.OnNext( new WorkDoneProgressReport { Percentage = 20, Message = "Report 2" } ); partial.OnNext( new[] { new CodeLens { Command = new Command { Name = "CodeLens 3" } }, } ); workDone.OnNext( new WorkDoneProgressReport { Percentage = 30, Message = "Report 3" } ); partial.OnNext( new[] { new CodeLens { Command = new Command { Name = "CodeLens 4" } }, } ); workDone.OnNext( new WorkDoneProgressReport { Percentage = 40, Message = "Report 4" } ); workDone.OnCompleted(); await Task.Yield(); return(new CodeLensContainer()); }
public override Task <CodeLensContainer> Handle(CodeLensParams request, CancellationToken cancellationToken) => Task.FromResult(new CodeLensContainer());
public static Task <CodeLensContainer> CodeLens(this ILanguageClientDocument mediator, CodeLensParams @params) { return(mediator.SendRequest <CodeLensParams, CodeLensContainer>(DocumentNames.CodeLens, @params)); }
public abstract Task <CodeLensContainer> Handle(CodeLensParams request, CancellationToken cancellationToken);
public static Task <CodeLensContainer> CodeLens(this ILanguageClientDocument mediator, CodeLensParams @params, CancellationToken cancellationToken = default) { return(mediator.SendRequest(@params, cancellationToken)); }
/// <nodoc /> public Result <CodeLens[], ResponseError> CodeLens(CodeLensParams codeLens, CancellationToken token) { return(m_codeLensProvider.CodeLens(codeLens, token)); }
public override Task <CodeLensContainer> Handle(CodeLensParams request, CancellationToken cancellationToken) => _handler.Invoke(request, cancellationToken);
public abstract RpcResult CodeLens(CodeLensParams args);