public void SimpleTest(string expected) { var model = new DidChangeTextDocumentParams() { ContentChanges = new[] { new TextDocumentContentChangeEvent() { Range = new Range(new Position(1, 1), new Position(2, 2)), RangeLength = 12, Text = "abc" } }, TextDocument = new VersionedTextDocumentIdentifier() { Uri = "/somepath/to/a/file.ext", } }; var result = Fixture.SerializeObject(model); result.Should().Be(expected); var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject <DidChangeTextDocumentParams>(expected); deresult.Should().BeEquivalentTo(model); }
public async Task <Unit> Handle(DidChangeTextDocumentParams notification, CancellationToken token) { _foregroundDispatcher.AssertBackgroundThread(); var document = await Task.Factory.StartNew(() => { _documentResolver.TryResolveDocument(notification.TextDocument.Uri.GetAbsoluteOrUNCPath(), out var documentSnapshot); return(documentSnapshot); }, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler); var sourceText = await document.GetTextAsync(); sourceText = ApplyContentChanges(notification.ContentChanges, sourceText); if (notification.TextDocument.Version is null) { throw new InvalidOperationException("Provided version should not be null."); } await Task.Factory.StartNew( () => _projectService.UpdateDocument(document.FilePath, sourceText, notification.TextDocument.Version.Value), CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler); return(Unit.Value); }
public Task Handle(DidChangeTextDocumentParams notification) { var contentChanges = notification.ContentChanges.ToArray(); if (contentChanges.Length == 1 && contentChanges[0].Range == null) { var change = contentChanges[0]; return(_bufferHandler.Handle(new UpdateBufferRequest() { FileName = Helpers.FromUri(notification.TextDocument.Uri), Buffer = change.Text })); } var changes = contentChanges .Select(change => new LinePositionSpanTextChange() { NewText = change.Text, StartColumn = Convert.ToInt32(change.Range.Start.Character), StartLine = Convert.ToInt32(change.Range.Start.Line), EndColumn = Convert.ToInt32(change.Range.End.Character), EndLine = Convert.ToInt32(change.Range.End.Line), }) .ToArray(); return(_bufferHandler.Handle(new UpdateBufferRequest() { FileName = Helpers.FromUri(notification.TextDocument.Uri), Changes = changes })); }
/// <summary> /// Handles text document change events /// </summary> internal Task HandleDidChangeTextDocumentNotification( DidChangeTextDocumentParams textChangeParams, EventContext eventContext) { StringBuilder msg = new StringBuilder(); msg.Append("HandleDidChangeTextDocumentNotification"); List <ScriptFile> changedFiles = new List <ScriptFile>(); // A text change notification can batch multiple change requests foreach (var textChange in textChangeParams.ContentChanges) { string fileUri = textChangeParams.TextDocument.Uri ?? textChangeParams.TextDocument.Uri; msg.AppendLine(string.Format(" File: {0}", fileUri)); ScriptFile changedFile = Workspace.GetFile(fileUri); changedFile.ApplyChange( GetFileChangeDetails( textChange.Range.Value, textChange.Text)); changedFiles.Add(changedFile); } Logger.Write(LogLevel.Verbose, msg.ToString()); var handlers = TextDocChangeCallbacks.Select(t => t(changedFiles.ToArray(), eventContext)); return(Task.WhenAll(handlers)); }
public void TextDocumentDidChange(DidChangeTextDocumentParams param) { var path = Converters.PathFromUri(param.TextDocument.Uri); foreach (var contentChanges in param.ContentChanges) { if (_documentContents.TryGetValue(path, out var contents)) { if (contentChanges.Range is object) { // incremental update var startIndex = contentChanges.Range.Start.GetIndex(contents); var endIndex = contentChanges.Range.End.GetIndex(contents); var preText = contents.Substring(0, startIndex); var postText = contents.Substring(endIndex); var updatedContent = string.Concat(preText, contentChanges.Text, postText); _documentContents[path] = updatedContent; } else { // full update _documentContents[path] = contentChanges.Text; } } } }
public async Task <Unit> Handle(DidChangeTextDocumentParams notification, CancellationToken token) { var uri = notification.TextDocument.Uri.GetAbsoluteOrUNCPath(); var document = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() => { _documentResolver.TryResolveDocument(uri, out var documentSnapshot); return(documentSnapshot); }, CancellationToken.None).ConfigureAwait(false); if (document is null) { throw new InvalidOperationException(RazorLS.Resources.FormatDocument_Not_Found(uri)); } var sourceText = await document.GetTextAsync(); sourceText = ApplyContentChanges(notification.ContentChanges, sourceText); if (notification.TextDocument.Version is null) { throw new InvalidOperationException(RazorLS.Resources.Version_Should_Not_Be_Null); } await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync( () => _projectService.UpdateDocument(document.FilePath, sourceText, notification.TextDocument.Version.Value), CancellationToken.None).ConfigureAwait(false); return(Unit.Value); }
public async Task <Unit> Handle(DidChangeTextDocumentParams request, CancellationToken cancellationToken) { var text = request.ContentChanges.FirstOrDefault()?.Text; var buffer = _bufferManager.GetBuffer(request.TextDocument); int offset = 0; int characterToRemove = 0; foreach (var change in request.ContentChanges) { offset = Utils.PositionToOffset(change.Range.Start, buffer); characterToRemove = 0; if (change.Range.Start != change.Range.End) { characterToRemove = Utils.PositionToOffset(change.Range.End, buffer) - offset; } _bufferManager.UpdateBuffer(request.TextDocument, offset, text, characterToRemove); } if (request.ContentChanges.Count() == 1) { var bufferWithContentChange = _bufferManager.GetBuffer(request.TextDocument); await ApplyTextManipulations(request, text, buffer, bufferWithContentChange, offset, characterToRemove); } return(Unit.Value); }
public Task <Unit> Handle(DidChangeTextDocumentParams notification, CancellationToken token) { var text = notification.ContentChanges.First().Text; rhetosWorkspace.UpdateDocumentText(notification.TextDocument.Uri, text); return(Unit.Task); }
public async Task <Unit> Handle(DidChangeTextDocumentParams notification, CancellationToken token) { _threadManager.AssertBackgroundThread(); _router.Window.LogMessage(new LogMessageParams() { Type = MessageType.Log, Message = "Proto file changed: " + notification.TextDocument.Uri.AbsolutePath, }); var document = await Task.Factory.StartNew(() => { _snapshotManager.TryResolveDocument(notification.TextDocument.Uri.AbsolutePath, out var documentSnapshot); return(documentSnapshot); }, CancellationToken.None, TaskCreationOptions.None, _threadManager.ForegroundScheduler); var sourceText = await document.GetTextAsync(); sourceText = ApplyContentChanges(notification.ContentChanges, sourceText); await Task.Factory.StartNew( () => _snapshotManager.DocumentChanged(notification.TextDocument.Uri.AbsolutePath, sourceText, notification.TextDocument.Version), CancellationToken.None, TaskCreationOptions.None, _threadManager.ForegroundScheduler); return(Unit.Value); }
public override async Task <Unit> Handle(DidChangeTextDocumentParams request, CancellationToken cancellationToken) { await _onChangeHandler.Invoke(request, _capability, cancellationToken); return(Unit.Value); }
public Task <Unit> Handle(DidChangeTextDocumentParams notification, CancellationToken token) { _router.Window.Log($"Server: DidChangeText:"); var contentChanges = notification.ContentChanges.ToArray(); if (contentChanges.Length == 1 && contentChanges[0].Range == null) { _router.Window.Log($"Change buffer with no range: {contentChanges[0].Text}"); //var change = contentChanges[0]; //await _bufferHandler.Handle(new UpdateBufferRequest() //{ // FileName = Helpers.FromUri(notification.TextDocument.Uri), // Buffer = change.Text //}); return(Unit.Task); } foreach (var change in notification.ContentChanges) { //_router.Window.Log($"Change: {change.Text} Start: {change.Range.Start.Character} Line:{change.Range.Start.Line} {change.RangeLength}"); if (change.Range != null) { _router.Window.Log($"Change: {change.Text} Start: {change.Range.Start.Character} Line:{change.Range.Start.Line} Length: {change.RangeLength}"); } else { _router.Window.Log($"Change: {change.Text} Length: {change.RangeLength}"); } } return(Unit.Task); }
public async Task <Unit> Handle(DidChangeTextDocumentParams request, CancellationToken cancellationToken) { await Task.Yield(); var code = OpenFiles[request.TextDocument.Uri].Code; foreach (var change in request.ContentChanges) { if (cancellationToken.IsCancellationRequested) { break; } var range = change.Range; if (range != null) { var caret = new CodeLocation((int)range.Start.Character + 1, (int)range.Start.Line + 1); var end = new CodeLocation((int)range.End.Character + 1, (int)range.End.Line + 1); var startOffset = DocumentHelper.LocationToOffset(code, caret); var endOffset = DocumentHelper.GetOffsetByRelativeLocation(code, caret, startOffset, end); code = code.Substring(0, startOffset) + change.Text + code.Substring(endOffset); } else { code = change.Text; } } OpenFiles[request.TextDocument.Uri] = new DModuleDocument(code, request.TextDocument.Version, ParseFile(request.TextDocument.Uri, code)); return(Unit.Value); }
protected Task HandleDidChangeTextDocumentNotification( DidChangeTextDocumentParams textChangeParams, EventContext eventContext) { List <ScriptFile> changedFiles = new List <ScriptFile>(); // A text change notification can batch multiple change requests foreach (var textChange in textChangeParams.ContentChanges) { ScriptFile changedFile = editorSession.Workspace.GetFile(textChangeParams.Uri); changedFile.ApplyChange( GetFileChangeDetails( textChange.Range.Value, textChange.Text)); changedFiles.Add(changedFile); } // TODO: Get all recently edited files in the workspace this.RunScriptDiagnostics( changedFiles.ToArray(), editorSession, eventContext); return(Task.FromResult(true)); }
public Task <object> HandleDocumentDidChangeAsync(DidChangeTextDocumentParams didChangeParams, CancellationToken cancellationToken) { Contract.ThrowIfNull(_clientCapabilities, $"{nameof(InitializeAsync)} has not been called."); return(RequestDispatcher.ExecuteRequestAsync <DidChangeTextDocumentParams, object>(Queue, Methods.TextDocumentDidChangeName, didChangeParams, _clientCapabilities, ClientName, cancellationToken)); }
public Task <Unit> Handle(DidChangeTextDocumentParams request, CancellationToken cancellationToken) { if (request?.TextDocument == null) { return(Unit.Task); } if (null == request.TextDocument.Uri) { return(Unit.Task); } string documentPath = request.TextDocument.Uri.ToString(); if (null == request.ContentChanges) { return(Unit.Task); } if (null == request.ContentChanges.FirstOrDefault()) { return(Unit.Task); } string text = request.ContentChanges.FirstOrDefault()?.Text; m_bufferManager.UpdateBuffer(documentPath, new SimpleDocumentBuffer(text)); m_router.Window.LogInfo( LocalizableTexts.ResourceManager.GetString("GameConstantsFileDocumentSyncHandler_Handle_LogInfo") + ": " + documentPath + "\n" + text); return(Unit.Task); }
public override Task DidChangeTextDocument(DidChangeTextDocumentParams @params, CancellationToken cancellationToken) { _disposableBag.ThrowIfDisposed(); var openedFile = _editorFiles.GetDocument(@params.textDocument.uri); return(openedFile.DidChangeTextDocument(@params, true, cancellationToken)); }
/// <summary> /// To be called whenever a file is changed within the editor (i.e. changes are not necessarily reflected on disk). /// Does nothing if the given file is listed as to be ignored. /// Throws an ArgumentException if the uri of the text document identifier in the given parameter is null or not an absolute file uri. /// Throws an ArgumentNullException if the given content changes are null. /// </summary> internal Task DidChangeAsync(DidChangeTextDocumentParams param) { if (!ValidFileUri(param?.TextDocument?.Uri)) { throw new ArgumentException("invalid text document identifier"); } if (param.ContentChanges == null) { throw new ArgumentNullException(nameof(param.ContentChanges)); } return(this.Projects.ManagerTaskAsync(param.TextDocument.Uri, (manager, __) => { if (IgnoreFile(param.TextDocument.Uri)) { return; } // Currently it is not possible to handle both the behavior of VS and VS Code for changes on disk in a manner that will never fail. // To mitigate the impact of failures we choose to ignore them silently. if (!this.OpenFiles.ContainsKey(param.TextDocument.Uri)) { return; } _ = manager.SourceFileDidChangeAsync(param); // independent on whether the file does or doesn't belong to a project })); }
public async Task Handle(DidChangeTextDocumentParams notification) { foreach (var change in notification.ContentChanges) { await Parse(notification.TextDocument.Uri, change.Text).ConfigureAwait(false); } }
public TextDocumentItem ApplyChange(TextDocumentItem originalTextDocument, DidChangeTextDocumentParams documentChange, CancellationToken cancellationToken) { return(originalTextDocument with { Version = documentChange.TextDocument.Version, Text = ApplyTextChanges(originalTextDocument.Text, documentChange.ContentChanges, cancellationToken) }); }
public void DidChangeTextDocument(DidChangeTextDocumentParams @params) { _disposableBag.ThrowIfDisposed(); var uri = @params.textDocument.uri; var doc = _rdt.GetDocument(uri); if (doc != null) { var changes = new List <DocumentChange>(); foreach (var c in @params.contentChanges) { Debug.Assert(c.range.HasValue); var change = new DocumentChange { InsertedText = c.text, ReplacedSpan = c.range.Value }; changes.Add(change); } doc.Update(changes); _indexManager.AddPendingDoc(doc); } else { _log?.Log(TraceEventType.Warning, $"Unable to find document for {@params.textDocument.uri}"); } }
public void NonStandardCharactersTest(string expected) { var model = new DidChangeTextDocumentParams() { ContentChanges = new[] { new TextDocumentContentChangeEvent() { Range = new Range(new Position(1, 1), new Position(2, 2)), RangeLength = 12, Text = "abc" } }, TextDocument = new VersionedTextDocumentIdentifier() { Uri = new Uri("C:\\abc\\Mörkö.cs") } }; var result = Fixture.SerializeObject(model); result.Should().Be(expected); var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject <DidChangeTextDocumentParams>(expected); deresult.Should().BeEquivalentTo(model); }
public Task TextChanged(FilePath fileName, int version, TextChangeEventArgs e, TextEditor editor) { Runtime.AssertMainThread(); if (!IsStarted) { return(Task.FromResult(0)); } if (!IsDocumentSyncSupported) { Log("Document sync not supported by server for '{0}'. File: '{1}'", Methods.TextDocumentDidChangeName, fileName); return(Task.FromResult(0)); } Log("Sending '{0}'. File: '{1}'", Methods.TextDocumentDidChangeName, fileName); var message = new DidChangeTextDocumentParams { TextDocument = TextDocumentIdentifierFactory.Create(fileName, version), ContentChanges = e.CreateTextDocumentContentChangeEvents(editor, IsDocumentSyncFull) .ToArray() }; return(jsonRpc.NotifyWithParameterObjectAsync(Methods.TextDocumentDidChange, message)); }
public override Task <Unit> Handle(DidChangeTextDocumentParams request, CancellationToken cancellationToken) { var text = request.ContentChanges.First().Text; rhetosWorkspace.Value.UpdateDocumentText(request.TextDocument.Uri.ToUri(), text); return(Unit.Task); }
public Task <Unit> Handle(DidChangeTextDocumentParams request, CancellationToken cancellationToken) { var uri = request.TextDocument.Uri; var text = request.ContentChanges.FirstOrDefault()?.Text; _bufferManager.UpdateBuffer(uri, new StringBuffer(text)); return(Unit.Task); }
public override Task <Unit> Handle(DidChangeTextDocumentParams notification, CancellationToken token) { _logger.LogCritical("Critical"); _logger.LogDebug("Debug"); _logger.LogTrace("Trace"); _logger.LogInformation("Hello world!"); return(Unit.Task); }
public Task <Unit> Handle(DidChangeTextDocumentParams request, CancellationToken token) { PublishValidateDiagnostics(request.ContentChanges.First().Text, request.TextDocument.Uri); _workspaceService.UpdateMarineFileBuffer(request.TextDocument.Uri.Path, request.ContentChanges.First().Text); return(Unit.Task); }
public override Task <Unit> Handle(DidChangeTextDocumentParams request, CancellationToken token) { // we have full sync enabled, so apparently first change is the whole document var contents = request.ContentChanges.First().Text; this.compilationManager.UpsertCompilation(request.TextDocument.Uri, request.TextDocument.Version, contents); return(Unit.Task); }
public Task Handle(DidChangeTextDocumentParams notification) { _router.LogMessage(new LogMessageParams() { Type = MessageType.Log, Message = "Hello World!!!!" }); return(Task.CompletedTask); }
public Task <Unit> Handle(DidChangeTextDocumentParams request, CancellationToken cancellationToken) { Console.Error.WriteLine("Document changed"); foreach (var change in request.ContentChanges) { _bufferManager.Patch(request.TextDocument.Uri, change); } return(Unit.Task); }
public Task <Unit> Handle(DidChangeTextDocumentParams notification, CancellationToken token) { _router.Window.LogMessage(new LogMessageParams() { Type = MessageType.Log, Message = "Hello World!!!!" }); return(Unit.Task); }