Пример #1
0
        private async Task VerifyFileIsNotAddedOnDocOpened(string filePath)
        {
            // setup test workspace
            var workspace        = new ServiceLayer.Workspace.Workspace();
            var workspaceService = new WorkspaceService <SqlToolsSettings> {
                Workspace = workspace
            };

            // send a document open event with git:/ prefix URI
            var openParams = new DidOpenTextDocumentNotification
            {
                TextDocument = new TextDocumentItem {
                    Uri = filePath
                }
            };

            await workspaceService.HandleDidOpenTextDocumentNotification(openParams, eventContext : null);

            // verify the file is not being tracked by workspace
            Assert.False(workspaceService.Workspace.ContainsFile(filePath));

            // send a close event with git:/ prefix URI
            var closeParams = new DidCloseTextDocumentParams
            {
                TextDocument = new TextDocumentItem {
                    Uri = filePath
                }
            };

            await workspaceService.HandleDidCloseTextDocumentNotification(closeParams, eventContext : null);

            // this is not that interesting validation since the open is ignored
            // the main validation is that close doesn't raise an exception
            Assert.False(workspaceService.Workspace.ContainsFile(filePath));
        }
Пример #2
0
 public Task Handle(DidCloseTextDocumentParams notification)
 {
     return(_closeHandler?.Handle(new FileCloseRequest()
     {
         FileName = Helpers.FromUri(notification.TextDocument.Uri)
     }) ?? Task.CompletedTask);
 }
Пример #3
0
        internal async Task HandleDidCloseTextDocumentNotification(
            DidCloseTextDocumentParams closeParams,
            EventContext eventContext)
        {
            Logger.Write(LogLevel.Verbose, "HandleDidCloseTextDocumentNotification");

            if (IsScmEvent(closeParams.TextDocument.Uri))
            {
                return;
            }

            // Skip closing this file if the file doesn't exist
            var closedFile = Workspace.GetFile(closeParams.TextDocument.Uri);

            if (closedFile == null)
            {
                return;
            }

            // Trash the existing document from our mapping
            Workspace.CloseFile(closedFile);

            // Send out a notification to other services that have subscribed to this event
            var textDocClosedTasks = TextDocCloseCallbacks.Select(t => t(closedFile, eventContext));
            await Task.WhenAll(textDocClosedTasks);
        }
Пример #4
0
            public override async Task <Unit> Handle(DidCloseTextDocumentParams request,
                                                     CancellationToken cancellationToken)
            {
                await _onCloseHandler.Invoke(request, _capability, cancellationToken);

                return(Unit.Value);
            }
Пример #5
0
        internal async Task HandleDidCloseTextDocumentNotification(
            DidCloseTextDocumentParams closeParams,
            EventContext eventContext)
        {
            try
            {
                Logger.Write(LogLevel.Verbose, "HandleDidCloseTextDocumentNotification");

                if (IsScmEvent(closeParams.TextDocument.Uri))
                {
                    return;
                }

                // Skip closing this file if the file doesn't exist
                var closedFile = Workspace.GetFile(closeParams.TextDocument.Uri);
                if (closedFile == null)
                {
                    return;
                }

                // Trash the existing document from our mapping
                Workspace.CloseFile(closedFile);

                // Send out a notification to other services that have subscribed to this event
                var textDocClosedTasks = TextDocCloseCallbacks.Select(t => t(closedFile, eventContext));
                await Task.WhenAll(textDocClosedTasks);
            }
            catch (Exception ex)
            {
                Logger.Write(LogLevel.Error, "Unknown error " + ex.ToString());
                // Swallow exceptions here to prevent us from crashing
                // TODO: this probably means the ScriptFile model is in a bad state or out of sync with the actual file; we should recover here
                return;
            }
        }
Пример #6
0
        public async Task Handle_DidCloseTextDocument_ClosesDocument()
        {
            // Arrange
            var documentPath   = "C:/path/to/document.cshtml";
            var projectService = new Mock <RazorProjectService>(MockBehavior.Strict);

            projectService.Setup(service => service.CloseDocument(It.IsAny <string>()))
            .Callback <string>((path) =>
            {
                Assert.Equal(documentPath, path);
            });
            var endpoint = new RazorDocumentSynchronizationEndpoint(Dispatcher, DocumentResolver, projectService.Object, LoggerFactory);
            var request  = new DidCloseTextDocumentParams()
            {
                TextDocument = new TextDocumentIdentifier()
                {
                    Uri = new Uri(documentPath)
                }
            };

            // Act
            await Task.Run(() => endpoint.Handle(request, default));

            // Assert
            projectService.VerifyAll();
        }
Пример #7
0
        internal virtual void DigClose(LSP.Implementation.LanguageClient client)
        {
            var param = new DidCloseTextDocumentParams();

            param.textDocument.uri = sourceUri.AbsoluteUri;
            client.Send.TextDocumentDidClose(param);
        }
Пример #8
0
        public Task <object?> HandleDocumentDidCloseAsync(DidCloseTextDocumentParams didCloseParams, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(_clientCapabilities, $"{nameof(InitializeAsync)} has not been called.");

            return(RequestDispatcher.ExecuteRequestAsync <DidCloseTextDocumentParams, object?>(Queue, Methods.TextDocumentDidCloseName,
                                                                                               didCloseParams, _clientCapabilities, ClientName, cancellationToken));
        }
        // Handle close.
        public Task <Unit> Handle(DidCloseTextDocumentParams closeParams, CancellationToken token)
        {
            var removing = TextDocumentFromUri(closeParams.TextDocument.Uri.ToUri());

            removing.Remove();
            Documents.Remove(removing);
            return(Unit.Task);
        }
Пример #10
0
        void IWorker.DidClose(string absFilename)
        {
            var sourceUri = new Uri(absFilename);
            var param     = new DidCloseTextDocumentParams();

            param.textDocument.uri = sourceUri.AbsoluteUri;
            client_.Send.TextDocumentDidClose(param);
        }
Пример #11
0
        public Task <Unit> Handle(DidCloseTextDocumentParams request, CancellationToken cancellationToken)
        {
            var uri = request.TextDocument.Uri;

            sourceContainer.Remove(uri);

            return(Unit.Task);
        }
        public void DidCloseTextDocument(DidCloseTextDocumentParams @params)
        {
            _disposableBag.ThrowIfDisposed();
            var uri = @params.textDocument.uri;

            _rdt.CloseDocument(uri);
            _indexManager.ProcessClosedFile(uri.AbsolutePath);
        }
        public async Task <Unit> Handle(DidCloseTextDocumentParams notification, CancellationToken token)
        {
            await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
                () => _projectService.CloseDocument(notification.TextDocument.Uri.GetAbsoluteOrUNCPath()),
                CancellationToken.None).ConfigureAwait(false);

            return(Unit.Value);
        }
Пример #14
0
        public Task <Unit> Handle(DidCloseTextDocumentParams notification, CancellationToken token)
        {
            if (_configuration.TryGetScopedConfiguration(notification.TextDocument.Uri, out var disposable))
            {
                disposable.Dispose();
            }

            return(Unit.Task);
        }
        public override Task <Unit> Handle(DidCloseTextDocumentParams request, CancellationToken cancellationToken)
        {
            //if (configuration.TryGetScopedConfiguration(request.TextDocument.Uri, out var disposable))
            //{
            //    disposable.Dispose();
            //}

            this.compilationManager.CloseCompilation(request.TextDocument.Uri);
            return(Unit.Task);
        }
        Task SendCloseDocumentMessage(FilePath fileName)
        {
            Log("Sending '{0}'. File: '{1}'", Methods.TextDocumentDidCloseName, fileName);

            var message = new DidCloseTextDocumentParams {
                TextDocument = TextDocumentIdentifierFactory.Create(fileName)
            };

            return(jsonRpc.NotifyWithParameterObjectAsync(Methods.TextDocumentDidClose, message));
        }
        public override Task <Unit> Handle(DidCloseTextDocumentParams notification, CancellationToken cancellationToken)
        {
            _logger.LogTrace("received close notification {}", notification.TextDocument.Uri);
            var document = _documents.CloseDocument(notification.TextDocument);

            if (document != null)
            {
                _diagnosticPublisher.HideDiagnostics(document);
            }
            return(Unit.Task);
        }
Пример #18
0
        public Task <Unit> Handle(DidCloseTextDocumentParams request, CancellationToken cancellationToken)
        {
            lock (_lock)
            {
                var filePath = request.TextDocument.Uri.ToFilePath();

                _documentItems.Remove(filePath);
            }

            return(Unit.Task);
        }
Пример #19
0
        public Task <Unit> Handle(DidCloseTextDocumentParams notification, CancellationToken cancellationToken)
        {
            var document = _workspace.GetDocument(notification.TextDocument.Uri);

            if (document != null)
            {
                _workspace.CloseDocument(document.Id);
            }

            return(Unit.Task);
        }
Пример #20
0
        public override void OnDidCloseTextDocument(DidCloseTextDocumentParams parameters)
        {
            Uri objUri = new Uri(parameters.textDocument.uri);

            if (objUri.IsFile)
            {
                typeCobolWorkspace.CloseSourceFile(objUri);

                // DEBUG information
                RemoteConsole.Log("Closed source file : " + objUri.LocalPath);
            }
        }
Пример #21
0
        public async Task <Unit> Handle(DidCloseTextDocumentParams notification, CancellationToken token)
        {
            _foregroundDispatcher.AssertBackgroundThread();

            await Task.Factory.StartNew(
                () => _projectService.CloseDocument(notification.TextDocument.Uri.GetAbsoluteOrUNCPath()),
                CancellationToken.None,
                TaskCreationOptions.None,
                _foregroundDispatcher.ForegroundScheduler);

            return(Unit.Value);
        }
Пример #22
0
        public async Task <Unit> Handle(DidCloseTextDocumentParams request, CancellationToken cancellationToken)
        {
            await Task.Yield();

            await Task.Run(() => Program.AnalyticsApi.TrackEvent("File-Close", "File closed"), cancellationToken);

            await Task.Run(
                () => WorkspaceManager.Instance.HandleClosedFile(
                    WorkspaceManager.Instance.GetOrCreateByUri(request.TextDocument.Uri.ToUri())), cancellationToken);

            return(Unit.Value);
        }
        public async override Task <Unit> Handle(DidCloseTextDocumentParams notification, CancellationToken cancellationToken)
        {
            if (_closeHandler != null)
            {
                await _closeHandler.Handle(new FileCloseRequest()
                {
                    FileName = Helpers.FromUri(notification.TextDocument.Uri)
                });
            }

            return(Unit.Value);
        }
Пример #24
0
        public override Task <Unit> Handle(DidCloseTextDocumentParams request, CancellationToken cancellationToken)
        {
            var documentUri = request.TextDocument.Uri;

            // If the documentUri corresponds to bicepconfig.json, we'll remove the entry from activeBicepConfigCache.
            if (ConfigurationHelper.IsBicepConfigFile(documentUri))
            {
                bicepConfigChangeHandler.HandleBicepConfigCloseEvent(documentUri);
            }

            this.compilationManager.CloseCompilation(request.TextDocument.Uri);
            return(Unit.Task);
        }
Пример #25
0
        public void SimpleTest(string expected)
        {
            var model = new DidCloseTextDocumentParams {
                TextDocument = new TextDocumentIdentifier(new Uri("file:///abc/def.cs"))
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.Should().BeEquivalentTo(model, x => x.UsingStructuralRecordEquality());
        }
Пример #26
0
        public override async Task DidCloseTextDocument(DidCloseTextDocumentParams @params, CancellationToken token)
        {
            _disposableBag.ThrowIfDisposed();
            _editorFiles.Close(@params.textDocument.uri);

            if (ProjectFiles.GetEntry(@params.textDocument.uri) is IDocument doc)
            {
                // No need to keep in-memory buffers now
                doc.ResetDocument(-1, null);
                // Pick up any changes on disk that we didn't know about
                await EnqueueItemAsync(doc, AnalysisPriority.Low);
            }
        }
        public override Task <Unit> Handle(DidCloseTextDocumentParams notification, CancellationToken token)
        {
            // Find and close the file in the current session
            var fileToClose = _workspaceService.GetFile(notification.TextDocument.Uri);

            if (fileToClose != null)
            {
                _workspaceService.CloseFile(fileToClose);
                _analysisService.ClearMarkers(fileToClose);
            }

            _logger.LogTrace("Finished closing document.");
            return(Unit.Task);
        }
        public void SimpleTest(string expected)
        {
            var model = new DidCloseTextDocumentParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri("file:///abc/def.cs"))
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

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

            deresult.ShouldBeEquivalentTo(model);
        }
        private async Task HandleDidCloseTextDocumentNotification(
            DidCloseTextDocumentParams closeParams,
            EventContext eventContext)
        {
            // Find and close the file in the current session
            var fileToClose = GetDocument(closeParams.TextDocument);

            if (fileToClose != null)
            {
                _workspace.CloseDocument(fileToClose.Id);
                await ClearMarkers(fileToClose, eventContext);
            }

            Logger.Write(LogLevel.Verbose, "Finished closing document.");
        }
Пример #30
0
        public void CloseDocument(Document document)
        {
            var textDocument = new TextDocumentIdentifier {
                uri = document.FileName
            };

            var messageParams = new DidCloseTextDocumentParams {
                textDocument = textDocument
            };

            var notification = new NotificationMessage {
                method  = "textDocument/didClose",
                @params = messageParams
            };

            client.SendMessage(notification);
        }