Browse Source
- add new watch using Ins key - ability to edit the name of the variable using also autocomplete.pull/15/head
10 changed files with 342 additions and 36 deletions
@ -0,0 +1,178 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.IO; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Input; |
||||||
|
|
||||||
|
using ICSharpCode.AvalonEdit; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.NRefactory; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Debugging; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
using ICSharpCode.SharpDevelop.Gui.Pads; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using ICSharpCode.SharpDevelop.Services; |
||||||
|
|
||||||
|
namespace Debugger.AddIn.Pads.Controls |
||||||
|
{ |
||||||
|
public partial class WatchListAutoCompleteCell : UserControl |
||||||
|
{ |
||||||
|
private string language; |
||||||
|
|
||||||
|
protected ConsoleControl console; |
||||||
|
|
||||||
|
public static readonly DependencyProperty CommandTextProperty = |
||||||
|
DependencyProperty.Register("CommandText", typeof(string), typeof(WatchListAutoCompleteCell), |
||||||
|
new UIPropertyMetadata(null, new PropertyChangedCallback(OnCommandTextChanged))); |
||||||
|
|
||||||
|
private NRefactoryResolver resolver; |
||||||
|
|
||||||
|
public event EventHandler CommandEntered; |
||||||
|
|
||||||
|
public WatchListAutoCompleteCell() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
|
||||||
|
console = new ConsoleControl(); |
||||||
|
console.TextAreaTextEntered += new TextCompositionEventHandler(consoleControl_TextAreaTextEntered); |
||||||
|
console.TextAreaPreviewKeyDown += new KeyEventHandler(console_TextAreaPreviewKeyDown); |
||||||
|
console.LostFocus += new RoutedEventHandler(console_LostFocus); |
||||||
|
console.HideScrollBar(); |
||||||
|
ConsolePanel.Content = console; |
||||||
|
|
||||||
|
// get language
|
||||||
|
if (ProjectService.CurrentProject == null) |
||||||
|
language = "C#"; |
||||||
|
else |
||||||
|
language = ProjectService.CurrentProject.Language; |
||||||
|
resolver = new NRefactoryResolver(LanguageProperties.GetLanguage(language)); |
||||||
|
|
||||||
|
// FIXME set language
|
||||||
|
if (language == "VB" || language == "VBNet") { |
||||||
|
console.SetHighlighting("VBNET"); |
||||||
|
} |
||||||
|
else { |
||||||
|
console.SetHighlighting("C#"); |
||||||
|
} |
||||||
|
|
||||||
|
// get process
|
||||||
|
WindowsDebugger debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; |
||||||
|
|
||||||
|
debugger.ProcessSelected += delegate(object sender, ProcessEventArgs e) { |
||||||
|
this.Process = e.Process; |
||||||
|
}; |
||||||
|
this.Process = debugger.DebuggedProcess; |
||||||
|
} |
||||||
|
|
||||||
|
private Process Process { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/sets the command text displayed at the command prompt.
|
||||||
|
/// </summary>
|
||||||
|
public string CommandText { |
||||||
|
get { return console.CommandText.Trim(); } |
||||||
|
set { console.CommandText = value; } |
||||||
|
} |
||||||
|
|
||||||
|
private ITextEditor TextEditor { |
||||||
|
get { |
||||||
|
return console.TextEditor; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void console_TextAreaPreviewKeyDown(object sender, KeyEventArgs e) |
||||||
|
{ |
||||||
|
if (e.Key == Key.Return || e.Key == Key.Escape) { |
||||||
|
|
||||||
|
if (e.Key == Key.Escape) |
||||||
|
CommandText = string.Empty; |
||||||
|
else { |
||||||
|
if(!CheckSyntax()) |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if (CommandEntered != null) |
||||||
|
CommandEntered(this, EventArgs.Empty); |
||||||
|
|
||||||
|
e.Handled = true; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void console_LostFocus(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
if (string.IsNullOrEmpty(CommandText) || !this.CheckSyntax()) |
||||||
|
return; |
||||||
|
|
||||||
|
if (CommandEntered != null) |
||||||
|
CommandEntered(this, EventArgs.Empty); |
||||||
|
} |
||||||
|
|
||||||
|
private bool CheckSyntax() |
||||||
|
{ |
||||||
|
string command = CommandText; |
||||||
|
|
||||||
|
// FIXME workaround the NRefactory issue that needs a ; at the end
|
||||||
|
if (language == "C#" || language == "CSharp") { |
||||||
|
if(!command.EndsWith(";")) |
||||||
|
command += ";"; |
||||||
|
// FIXME only one string should be available; highlighting expects C#, supproted language, CSharp
|
||||||
|
language = "CSharp"; |
||||||
|
} |
||||||
|
|
||||||
|
SupportedLanguage supportedLanguage = (SupportedLanguage)Enum.Parse(typeof(SupportedLanguage), language.ToString(), true); |
||||||
|
using (var parser = ParserFactory.CreateParser(supportedLanguage, new StringReader(command))) { |
||||||
|
parser.ParseExpression(); |
||||||
|
if (parser.Errors.Count > 0) { |
||||||
|
MessageService.ShowError(parser.Errors.ErrorOutput); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
private void consoleControl_TextAreaTextEntered(object sender, TextCompositionEventArgs e) |
||||||
|
{ |
||||||
|
foreach (char ch in e.Text) { |
||||||
|
if (ch == '.') { |
||||||
|
ShowDotCompletion(console.CommandText); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void ShowDotCompletion(string currentText) |
||||||
|
{ |
||||||
|
var seg = Process.SelectedStackFrame.NextStatement; |
||||||
|
|
||||||
|
var expressionFinder = ParserService.GetExpressionFinder(seg.Filename); |
||||||
|
var info = ParserService.GetParseInformation(seg.Filename); |
||||||
|
|
||||||
|
string text = ParserService.GetParseableFileContent(seg.Filename).Text; |
||||||
|
|
||||||
|
int currentOffset = TextEditor.Caret.Offset - console.CommandOffset - 1; |
||||||
|
|
||||||
|
var expr = expressionFinder.FindExpression(currentText, currentOffset); |
||||||
|
|
||||||
|
expr.Region = new DomRegion(seg.StartLine, seg.StartColumn, seg.EndLine, seg.EndColumn); |
||||||
|
|
||||||
|
var rr = resolver.Resolve(expr, info, text); |
||||||
|
|
||||||
|
if (rr != null) { |
||||||
|
TextEditor.ShowCompletionWindow(new DotCodeCompletionItemProvider().GenerateCompletionListForResolveResult(rr, expr.Context)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static void OnCommandTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { |
||||||
|
var cell = d as WatchListAutoCompleteCell; |
||||||
|
cell.CommandText = e.NewValue.ToString(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
<UserControl x:Class="Debugger.AddIn.Pads.Controls.WatchListAutoCompleteCell" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||||
|
<Grid> |
||||||
|
<Grid.ColumnDefinitions> |
||||||
|
<ColumnDefinition Width="Auto" MinWidth="200"/> |
||||||
|
</Grid.ColumnDefinitions> |
||||||
|
<ContentPresenter |
||||||
|
Name="ConsolePanel" /> |
||||||
|
</Grid> |
||||||
|
</UserControl> |
Loading…
Reference in new issue