protected override async Task SetWatchTextAsync (WatchVariable w, List<string> vals) { var doc = IdeApp.Workbench.GetDocument (w.FilePath); if (doc == null) return; var ed = doc.Editor; if (ed == null || !ed.CanEdit (w.FileLine)) return; var line = ed.GetLine (w.FileLine); if (line == null) return; var newText = "//" + w.ExplicitExpression + "= " + GetValsText (vals); var lineText = ed.GetLineText (w.FileLine); var commentIndex = lineText.IndexOf ("//"); if (commentIndex < 0) return; var commentCol = commentIndex + 1; if (commentCol != w.FileColumn) return; var existingText = lineText.Substring (commentIndex); if (existingText != newText) { var offset = line.Offset + commentIndex; var remLen = line.Length - commentIndex; ed.Remove (offset, remLen); ed.Insert (offset, newText); } }
SyntaxNode AddWatchNode(StatementSyntax node, ExpressionSyntax expr) { var id = Guid.NewGuid().ToString(); var c = node.GetTrailingTrivia().First(t => t.Kind() == SyntaxKind.SingleLineCommentTrivia && t.ToString().StartsWith("//=", StringComparison.InvariantCultureIgnoreCase)); var p = c.GetLocation().GetLineSpan().StartLinePosition; var wv = new WatchVariable { Id = id, Expression = expr.ToString(), ExplicitExpression = "", FilePath = path, FileLine = p.Line + 1, // 0-based index FileColumn = p.Character + 1, // 0-based index }; WatchVariables.Add(wv); var wi = GetWatchInstrument(id, expr); // creating a block and removing the open/close braces is a bit of a hack but // lets us replace one node with two... return (SyntaxFactory .Block(node, wi) .WithOpenBraceToken(SyntaxFactory.MissingToken(SyntaxKind.OpenBraceToken)) .WithCloseBraceToken(SyntaxFactory.MissingToken(SyntaxKind.CloseBraceToken)) .WithTrailingTrivia(SyntaxFactory.EndOfLine("\r\n"))); }
protected override async Task SetWatchTextAsync(WatchVariable w, List <string> vals) { var doc = IdeApp.Workbench.GetDocument(w.FilePath); if (doc == null) { return; } var ed = doc.Editor; if (ed == null || !ed.CanEdit(w.FileLine)) { return; } var line = ed.GetLine(w.FileLine); if (line == null) { return; } var newText = "//" + w.ExplicitExpression + "= " + GetValsText(vals); var lineText = ed.GetLineText(w.FileLine); var commentIndex = lineText.IndexOf("//"); if (commentIndex < 0) { return; } var commentCol = commentIndex + 1; if (commentCol != w.FileColumn) { return; } var existingText = lineText.Substring(commentIndex); if (existingText != newText) { var offset = line.Offset + commentIndex; var remLen = line.Length - commentIndex; ed.Remove(offset, remLen); ed.Insert(offset, newText); } }
protected override async Task SetWatchTextAsync(WatchVariable w, List <string> vals) { Console.WriteLine("Ignoring SetWatchTextAsync"); return; /* * var doc = IdeApp.Workbench.GetDocument(w.FilePath); * if (doc == null) * return; * * var ed = doc.Editor; * * if (ed == null || ed.IsReadOnly) * return; * var line = ed.GetLine (w.FileLine); * if (line == null) * return; * var newText = "//" + w.ExplicitExpression + "= " + GetValsText (vals); * var lineText = ed.GetLineText (w.FileLine); * var commentIndex = lineText.IndexOf ("//"); * if (commentIndex < 0) * return; * var commentCol = commentIndex + 1; * if (commentCol != w.FileColumn) * return; * * var existingText = lineText.Substring (commentIndex); * * if (existingText != newText) { * var offset = line.Offset + commentIndex; * var remLen = line.Length - commentIndex; * ed.RemoveText (offset, remLen); * ed.InsertText (offset, newText); * } */ }
protected override async Task SetWatchTextAsync (WatchVariable w, List<string> vals) { // throw new NotImplementedException (); }
protected abstract Task SetWatchTextAsync (WatchVariable w, List<string> vals);
SyntaxNode AddWatchNode(StatementSyntax node, ExpressionSyntax expr) { var id = Guid.NewGuid().ToString(); var c = node.GetTrailingTrivia().First(t => t.Kind() == SyntaxKind.SingleLineCommentTrivia && t.ToString().StartsWith("//=")); var p = c.GetLocation().GetLineSpan().StartLinePosition; var wv = new WatchVariable { Id = id, Expression = expr.ToString(), ExplicitExpression = "", FilePath = path, FileLine = p.Line + 1, // 0-based index FileColumn = p.Character + 1, // 0-based index }; WatchVariables.Add(wv); var wi = GetWatchInstrument(id, expr); // creating a block and removing the open/close braces is a bit of a hack but // lets us replace one node with two... return SyntaxFactory .Block(node, wi) .WithOpenBraceToken(SyntaxFactory.MissingToken(SyntaxKind.OpenBraceToken)) .WithCloseBraceToken(SyntaxFactory.MissingToken(SyntaxKind.CloseBraceToken)) .WithTrailingTrivia(SyntaxFactory.EndOfLine("\r\n")); }
protected abstract Task SetWatchTextAsync(WatchVariable w, List <string> vals);
protected override async Task SetWatchTextAsync(WatchVariable w, List <string> vals) { // throw new NotImplementedException (); }