Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles text document change events
        /// </summary>
        internal async Task HandleDidChangeTextDocumentNotification(
            DidChangeTextDocumentParams textChangeParams,
            EventContext eventContext)
        {
            Logger.Instance.Write(LogLevel.Verbose, "textDocument/didChange");

            try
            {
                StringBuilder msg = new StringBuilder();
                msg.Append("HandleDidChangeTextDocumentNotification");
                List <TextDocument> changedFiles = new List <TextDocument>();

                // 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));

                    TextDocument changedFile = Workspace.GetFile(fileUri);
                    if (changedFile != null)
                    {
                        changedFile.ApplyChange(
                            GetFileChangeDetails(
                                textChange.Range.Value,
                                textChange.Text,
                                changedFile.BaseOffset));

                        changedFiles.Add(changedFile);
                    }
                }

                Logger.Instance.Write(LogLevel.Verbose, msg.ToString());

                var handlers = TextDocChangeCallbacks.Select(t => t(changedFiles.ToArray(), eventContext));
                await Task.WhenAll(handlers);
            }
            catch (Exception ex)
            {
                Logger.Instance.Write(LogLevel.Error, "Unknown error " + ex.ToString());
                // Swallow exceptions here to prevent us from crashing
                // TODO: this probably means the file model is in a bad state or out of sync with the actual file; we should recover here
                await Task.FromResult(true);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles text document change events
        /// </summary>
        internal Task HandleDidChangeTextDocumentNotification(
            DidChangeTextDocumentParams textChangeParams,
            EventContext eventContext)
        {
            try
            {
                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));
            }
            catch
            {
                // 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(Task.FromResult(true));
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Adds a new task to be called when the text of a document changes.
 /// </summary>
 /// <param name="task">Delegate to call when the document changes</param>
 public void RegisterTextDocChangeCallback(TextDocChangeCallback task)
 {
     TextDocChangeCallbacks.Add(task);
 }