Browse Source

Merge branch '4.0'.

Conflicts - resolved:
	src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs
	src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/EditorContext.cs
pull/15/head
mkonicek 15 years ago
parent
commit
81b7a20c1d
  1. 6
      src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageControl.cs
  2. 9
      src/AddIns/Analysis/Profiler/Frontend/AddIn/Src/Views/ProfilerView.xaml.cs
  3. 42
      src/AddIns/Analysis/Profiler/Hook/Profiler.Rewriting.cpp
  4. 2
      src/AddIns/Analysis/Profiler/Hook/Profiler.cpp
  5. 15
      src/AddIns/Analysis/Profiler/Hook/constants.cpp
  6. 6
      src/AddIns/Analysis/Profiler/Hook/global.h
  7. 68
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CaretReferencesRenderer.cs
  8. 5
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs
  9. 18
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs
  10. 2
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/EditorContext.cs
  11. 55
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs

6
src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageControl.cs

@ -240,7 +240,7 @@ namespace ICSharpCode.CodeCoverage @@ -240,7 +240,7 @@ namespace ICSharpCode.CodeCoverage
CodeCoverageSequencePoint sequencePoint = methodNode.Method.SequencePoints[0];
if (sequencePoint.HasDocument()) {
if (classNode == null) {
OpenFile(sequencePoint.Document, sequencePoint.Line - 1, sequencePoint.Column - 1);
OpenFile(sequencePoint.Document, sequencePoint.Line, sequencePoint.Column);
} else {
OpenFile(sequencePoint.Document, 1, 1);
}
@ -310,8 +310,8 @@ namespace ICSharpCode.CodeCoverage @@ -310,8 +310,8 @@ namespace ICSharpCode.CodeCoverage
textEditor.Load(fileName);
}
textEditor.ScrollToEnd();
textEditor.TextArea.Caret.Line = line - 1;
textEditor.ScrollToLine(line - 1);
textEditor.TextArea.Caret.Location = new ICSharpCode.AvalonEdit.Document.TextLocation(line, column);
textEditor.ScrollToLine(line);
CodeCoverageService.ShowCodeCoverage(new AvalonEditTextEditorAdapter(textEditor), fileName);
}

9
src/AddIns/Analysis/Profiler/Frontend/AddIn/Src/Views/ProfilerView.xaml.cs

@ -106,9 +106,12 @@ namespace ICSharpCode.Profiler.AddIn.Views @@ -106,9 +106,12 @@ namespace ICSharpCode.Profiler.AddIn.Views
Dispatcher.Invoke(
(Action)(
() => {
WorkbenchSingleton.Workbench.GetPad(typeof(ErrorListPad)).BringPadToFront();
TaskService.ClearExceptCommentTasks();
TaskService.AddRange(errors.Select(error => new Task(null, error.ErrorText, error.Column, error.Line, (error.IsWarning) ? TaskType.Warning : TaskType.Error)));
var tasks = errors.Select(error => new Task(null, error.ErrorText, error.Column, error.Line, (error.IsWarning) ? TaskType.Warning : TaskType.Error)).ToList();
if (tasks.Count > 0) {
WorkbenchSingleton.Workbench.GetPad(typeof(ErrorListPad)).BringPadToFront();
TaskService.ClearExceptCommentTasks();
TaskService.AddRange(tasks);
}
}
)
);

42
src/AddIns/Analysis/Profiler/Hook/Profiler.Rewriting.cpp

@ -194,10 +194,6 @@ int CProfiler::SetInjectionCode(IMetaDataImport *metaData, byte *buffer, int *si @@ -194,10 +194,6 @@ int CProfiler::SetInjectionCode(IMetaDataImport *metaData, byte *buffer, int *si
buffer[(*size)++] = 0x14; //ldnull
break;
case 2: // Windows Forms
buffer[(*size)++] = 0x14; //ldnull
buffer[(*size)++] = 0x14; //ldnull
break;
/*
hr = metaData->FindTypeDefByName(L"System.Windows.Forms.Control", nullptr, &controlType);
if (!SUCCEEDED(hr) || controlType == 0) {
@ -234,7 +230,7 @@ int CProfiler::SetInjectionCode(IMetaDataImport *metaData, byte *buffer, int *si @@ -234,7 +230,7 @@ int CProfiler::SetInjectionCode(IMetaDataImport *metaData, byte *buffer, int *si
buffer[(*size)++] = 0x6F; //callvirt
*(mdMethodDef*)(&buffer[*size]) = getTextToken;
*size += sizeof(getTextToken);
break;*/
break;
case 3: // WPF
buffer[(*size)++] = 0x14; //ldnull
buffer[(*size)++] = 0x14; //ldnull
@ -318,6 +314,42 @@ STDMETHODIMP CProfiler::ModuleLoadFinished(ModuleID moduleID, HRESULT /*hrStatus @@ -318,6 +314,42 @@ STDMETHODIMP CProfiler::ModuleLoadFinished(ModuleID moduleID, HRESULT /*hrStatus
IMetaDataEmit *pIMetaDataEmit = nullptr;
IMetaDataAssemblyImport *asmMetaData = nullptr;
WCHAR moduleName[NAME_BUFFER_SIZE];
WCHAR assemblyName[NAME_BUFFER_SIZE];
AssemblyID assemblyID;
ULONG actualLen = 0;
hr = pICorProfilerInfo->GetModuleInfo(moduleID, nullptr, NAME_BUFFER_SIZE, &actualLen, moduleName, &assemblyID);
if (!SUCCEEDED(hr))
goto CLEANUP;
hr = pICorProfilerInfo->GetAssemblyInfo(assemblyID, NAME_BUFFER_SIZE, &actualLen, assemblyName, nullptr, nullptr);
if (!SUCCEEDED(hr))
goto CLEANUP;
DebugWriteLine(L"\n----------------- Module Load finished -----------------\n");
DebugWriteLine(L"Module Name: '%s'\n", moduleName);
DebugWriteLine(L"Assembly Name: '%s'\n", assemblyName);
DebugWriteLine(L"--------------------------------------------------------\n");
bool found = false;
for (int i = 0; i < ASSEMBLY_INJECTION_NAME_LIST_LENGTH; i++) {
if (wcscmp(assemblyInjectionNameList[i], assemblyName) == 0) {
found = true;
break;
}
}
if (!found) {
DebugWriteLine(L"Assembly Name '%s' not found in list!\n", assemblyName);
goto CLEANUP;
}
hr = pICorProfilerInfo->GetModuleMetaData(moduleID, ofRead | ofWrite, IID_IMetaDataEmit, (LPUNKNOWN *) &pIMetaDataEmit);
if (!SUCCEEDED(hr) || pIMetaDataEmit == nullptr)

2
src/AddIns/Analysis/Profiler/Hook/Profiler.cpp

@ -378,7 +378,7 @@ HRESULT CProfiler::SetEventMask() { @@ -378,7 +378,7 @@ HRESULT CProfiler::SetEventMask() {
COR_PRF_MONITOR_FUNCTION_UNLOADS | COR_PRF_MONITOR_CLR_EXCEPTIONS |
COR_PRF_MONITOR_EXCEPTIONS;
if (sharedMemoryHeader->trackEvents)
eventMask = eventMask | COR_PRF_MONITOR_MODULE_LOADS/* | COR_PRF_MONITOR_JIT_COMPILATION*/;
eventMask = eventMask | COR_PRF_MONITOR_MODULE_LOADS | COR_PRF_MONITOR_JIT_COMPILATION;
return pICorProfilerInfo->SetEventMask(eventMask);
}

15
src/AddIns/Analysis/Profiler/Hook/constants.cpp

@ -3,17 +3,22 @@ @@ -3,17 +3,22 @@
#include "global.h"
WCHAR *assemblyInjectionNameList[ASSEMBLY_INJECTION_NAME_LIST_LENGTH] = {
L"mscorlib",
L"System.Windows.Forms",
L"PresentationCore"
};
WCHAR *consoleGroupList[CONSOLE_GROUP_LENGTH] = {
L"System.Console.Write",
L"System.Console.WriteLine"
};
WCHAR *winFormsGroupList[WINFORMS_GROUP_LENGTH] = {
L"-------------------------------------------------",
// L"System.Windows.Forms.Control.OnClick",
// L"System.Windows.Forms.Control.OnDoubleClick",
// L"System.Windows.Forms.Control.OnMouseWheel",
// L"System.Windows.Forms.Control.OnKeyDown"
L"System.Windows.Forms.Control.OnClick",
L"System.Windows.Forms.Control.OnDoubleClick",
L"System.Windows.Forms.Control.OnMouseWheel",
L"System.Windows.Forms.Control.OnKeyDown"
};
WCHAR *wpfGroupList[WPF_GROUP_LENGTH] = {

6
src/AddIns/Analysis/Profiler/Hook/global.h

@ -10,8 +10,11 @@ @@ -10,8 +10,11 @@
#include "LightweightStack.h"
#include "LightweightList.h"
#define NAME_BUFFER_SIZE 1024
#define ASSEMBLY_INJECTION_NAME_LIST_LENGTH 3
#define CONSOLE_GROUP_LENGTH 2
#define WINFORMS_GROUP_LENGTH 1
#define WINFORMS_GROUP_LENGTH 4
#define WPF_GROUP_LENGTH 1
extern fastAllocator stackAllocator;
@ -21,6 +24,7 @@ extern HANDLE listMutex; @@ -21,6 +24,7 @@ extern HANDLE listMutex;
extern LightweightList *allThreadLocalDatas;
extern DWORD tls_index;
extern WCHAR *assemblyInjectionNameList[ASSEMBLY_INJECTION_NAME_LIST_LENGTH];
extern WCHAR *consoleGroupList[CONSOLE_GROUP_LENGTH];
extern WCHAR *winFormsGroupList[WINFORMS_GROUP_LENGTH];
extern WCHAR *wpfGroupList[WPF_GROUP_LENGTH];

68
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CaretReferencesRenderer.cs

@ -22,15 +22,22 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -22,15 +22,22 @@ namespace ICSharpCode.AvalonEdit.AddIn
public class CaretReferencesRenderer
{
/// <summary>
/// Delays the highlighting after the caret position changes, so that Find references does not get called too often.
/// Delays the Resolve check so that it does not get called too often when user holds an arrow.
/// </summary>
DispatcherTimer delayMoveTimer;
const int delayMoveMs = 100;
/// <summary>
/// Delays the Find references (and highlight) after the caret stays at one point for a while.
/// </summary>
DispatcherTimer delayTimer;
const int delayMilliseconds = 800;
const int delayMs = 800;
/// <summary>
/// Delays the Resolve check so that it does not get called too often when user holds an arrow.
/// Maximum time for Find references. After this time it gets cancelled and no highlight is displayed.
/// Useful for very large files.
/// </summary>
DispatcherTimer delayMoveTimer;
const int delayMoveMilliseconds = 100;
const int findReferencesTimeoutMs = 200;
CodeEditorView editorView;
ITextEditor Editor { get { return editorView.Adapter; } }
@ -53,10 +60,10 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -53,10 +60,10 @@ namespace ICSharpCode.AvalonEdit.AddIn
{
this.editorView = editorView;
this.highlightRenderer = new ExpressionHighlightRenderer(this.editorView.TextArea.TextView);
this.delayTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(delayMilliseconds) };
this.delayTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(delayMs) };
this.delayTimer.Stop();
this.delayTimer.Tick += TimerTick;
this.delayMoveTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(delayMoveMilliseconds) };
this.delayMoveTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(delayMoveMs) };
this.delayMoveTimer.Stop();
this.delayMoveTimer.Tick += TimerMoveTick;
this.editorView.TextArea.Caret.PositionChanged += CaretPositionChanged;
@ -67,13 +74,23 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -67,13 +74,23 @@ namespace ICSharpCode.AvalonEdit.AddIn
this.highlightRenderer.ClearHighlight();
}
/// <summary>
/// In the current document, highlights all references to the expression
/// which is currently under the caret (local variable, class, property).
/// This gets called on every caret position change, so quite often.
/// </summary>
void CaretPositionChanged(object sender, EventArgs e)
{
Restart(this.delayMoveTimer);
}
void TimerTick(object sender, EventArgs e)
{
this.delayTimer.Stop();
if (!IsEnabled)
return;
var referencesToBeHighlighted = GetReferencesInCurrentFile(this.lastResolveResult);
var referencesToBeHighlighted = FindReferencesInCurrentFile(this.lastResolveResult);
this.highlightRenderer.SetHighlight(referencesToBeHighlighted);
}
@ -85,9 +102,9 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -85,9 +102,9 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (!IsEnabled)
return;
var resolveResult = GetExpressionUnderCaret();
var resolveResult = GetExpressionAtCaret();
if (resolveResult == null) {
this.lastResolveResult = resolveResult;
this.lastResolveResult = null;
this.highlightRenderer.ClearHighlight();
return;
}
@ -97,25 +114,16 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -97,25 +114,16 @@ namespace ICSharpCode.AvalonEdit.AddIn
this.lastResolveResult = resolveResult;
this.highlightRenderer.ClearHighlight();
this.delayTimer.Start();
} else {
// highlight stays the same, both timers are stopped (will start again when caret moves)
}
}
/// <summary>
/// In the current document, highlights all references to the expression
/// which is currently under the caret (local variable, class, property).
/// This gets called on every caret position change, so quite often.
/// </summary>
void CaretPositionChanged(object sender, EventArgs e)
{
this.delayMoveTimer.Stop();
this.delayMoveTimer.Start();
}
/// <summary>
/// Resolves the current expression under caret.
/// This gets called on every caret position change, so quite often.
/// </summary>
ResolveResult GetExpressionUnderCaret()
ResolveResult GetExpressionAtCaret()
{
if (string.IsNullOrEmpty(Editor.FileName) || ParserService.LoadSolutionProjectsThreadRunning)
return null;
@ -127,14 +135,14 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -127,14 +135,14 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// <summary>
/// Finds references to resolved expression in the current file.
/// </summary>
List<Reference> GetReferencesInCurrentFile(ResolveResult resolveResult)
List<Reference> FindReferencesInCurrentFile(ResolveResult resolveResult)
{
var cancellationTokenSource = new CancellationTokenSource();
using (new Timer(
delegate {
LoggingService.Debug("Aborting GetReferencesInCurrentFile due to timeout");
LoggingService.Debug("Aborting FindReferencesInCurrentFile due to timeout");
cancellationTokenSource.Cancel();
}, null, 200, Timeout.Infinite))
}, null, findReferencesTimeoutMs, Timeout.Infinite))
{
var progressMonitor = new DummyProgressMonitor();
progressMonitor.CancellationToken = cancellationTokenSource.Token;
@ -147,6 +155,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -147,6 +155,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// <summary>
/// Returns true if the 2 ResolveResults refer to the same symbol.
/// So that when caret moves but stays inside the same symbol, symbol stays highlighted.
/// </summary>
bool SameResolveResult(ResolveResult resolveResult, ResolveResult resolveResult2)
{
@ -159,5 +168,14 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -159,5 +168,14 @@ namespace ICSharpCode.AvalonEdit.AddIn
// TODO determine if 2 ResolveResults refer to the same symbol
return false;
}
/// <summary>
/// Restarts a timer.
/// </summary>
void Restart(DispatcherTimer timer)
{
timer.Stop();
timer.Start();
}
}
}

5
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs

@ -1102,6 +1102,11 @@ namespace ICSharpCode.AvalonEdit @@ -1102,6 +1102,11 @@ namespace ICSharpCode.AvalonEdit
TextView textView = textArea.TextView;
TextDocument document = textView.Document;
if (scrollViewer != null && document != null) {
if (line < 1)
line = 1;
if (line > document.LineCount)
line = document.LineCount;
IScrollInfo scrollInfo = textView;
if (!scrollInfo.CanHorizontallyScroll) {
// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll

18
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs

@ -18,6 +18,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -18,6 +18,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring
{
private static ContextActionsService instance = new ContextActionsService();
/// <summary>
/// Key for storing the names of disabled providers in PropertyService.
/// </summary>
const string PropertyServiceKey = "DisabledContextActionProviders";
public static ContextActionsService Instance {
@ -71,6 +74,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -71,6 +74,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring
throw new ArgumentNullException("providers");
this.editor = editor;
this.providers = providers;
// DO NOT USE Wait on the main thread!
// causes deadlocks!
// parseTask.Wait();
// Reparse so that we have up-to-date DOM.
ParserService.ParseCurrentViewContent();
this.EditorContext = new EditorContext(editor);
}
@ -106,23 +113,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -106,23 +113,14 @@ namespace ICSharpCode.SharpDevelop.Refactoring
{
if (ParserService.LoadSolutionProjectsThreadRunning)
yield break;
// DO NOT USE Wait on the main thread!
// causes deadlocks!
//parseTask.Wait();
var sw = new Stopwatch(); sw.Start();
var editorContext = new EditorContext(this.editor);
long elapsedEditorContextMs = sw.ElapsedMilliseconds;
// could run providers in parallel
foreach (var provider in providers) {
foreach (var action in provider.GetAvailableActions(editorContext)) {
foreach (var action in provider.GetAvailableActions(this.EditorContext)) {
providerForAction[action] = provider;
yield return action;
}
}
// ICSharpCode.Core.LoggingService.Debug(string.Format("Context actions elapsed {0}ms ({1}ms in EditorContext)",
// sw.ElapsedMilliseconds, elapsedEditorContextMs));
}
}
}

2
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/EditorContext.cs

@ -247,7 +247,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -247,7 +247,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
ExpressionResult GetExpressionAt(ITextEditor editor, int caretLine, int caretColumn)
{
ExpressionResult expr = ParserService.FindFullExpression(caretLine, caretColumn, editor.Document, editor.FileName);
// if no expression, look one character back (works better with method calls - Foo()(*caret*))
// if no expression, look one character back (works better with method calls, e.g. Foo()(*caret*))
if (string.IsNullOrWhiteSpace(expr.Expression) && caretColumn > 1)
expr = ParserService.FindFullExpression(caretLine, caretColumn - 1, editor.Document, editor.FileName);
return expr;

55
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/DefaultProjectContent.cs

@ -815,7 +815,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -815,7 +815,7 @@ namespace ICSharpCode.SharpDevelop.Dom
return GetNamespaces(language).ContainsKey(name);
}
bool MatchesRequest(ref SearchTypeRequest request, ref SearchTypeResult result)
bool MatchesRequest(SearchTypeRequest request, ref SearchTypeResult result)
{
if (result.NamespaceResult != null)
return request.TypeParameterCount == 0;
@ -852,7 +852,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -852,7 +852,7 @@ namespace ICSharpCode.SharpDevelop.Dom
foreach (IClass innerClass in baseClass.InnerClasses) {
if (language.NameComparer.Equals(innerClass.Name, name)) {
result = new SearchTypeResult(innerClass);
if (MatchesRequest(ref request, ref result)) {
if (MatchesRequest(request, ref result)) {
return result;
}
}
@ -873,50 +873,55 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -873,50 +873,55 @@ namespace ICSharpCode.SharpDevelop.Dom
IClass c = GetClass(fullname, request.TypeParameterCount);
if (c != null) {
result = new SearchTypeResult(c);
if (MatchesRequest(ref request, ref result)) {
if (MatchesRequest(request, ref result)) {
return result;
}
}
if (NamespaceExists(fullname)) {
result = new SearchTypeResult(fullname, null);
if (MatchesRequest(ref request, ref result)) {
if (MatchesRequest(request, ref result)) {
return result;
}
}
// prefer aliases over imported types
foreach (IUsing u in usingScope.Usings) {
foreach (IReturnType r in u.SearchType(name, request.TypeParameterCount)) {
result = new SearchTypeResult(r, u);
if (MatchesRequest(ref request, ref result)) {
if (u.HasAliases) {
if (SearchTypeInUsing(u, request, ref result))
return result;
}
}
string nsResult = u.SearchNamespace(name);
if (nsResult != null) {
result = new SearchTypeResult(nsResult, null);
if (MatchesRequest(ref request, ref result)) {
}
foreach (IUsing u in usingScope.Usings) {
if (!u.HasAliases) {
if (SearchTypeInUsing(u, request, ref result))
return result;
}
}
}
}
if (defaultImports != null) {
foreach (IReturnType r in defaultImports.SearchType(name, request.TypeParameterCount)) {
result = new SearchTypeResult(r, defaultImports);
if (MatchesRequest(ref request, ref result)) {
return result;
}
if (SearchTypeInUsing(defaultImports, request, ref result));
return result;
}
return result;
}
bool SearchTypeInUsing(IUsing u, SearchTypeRequest request, ref SearchTypeResult result)
{
foreach (IReturnType r in u.SearchType(request.Name, request.TypeParameterCount)) {
result = new SearchTypeResult(r, u);
if (MatchesRequest(request, ref result)) {
return true;
}
string nsResult = defaultImports.SearchNamespace(name);
if (nsResult != null) {
result = new SearchTypeResult(nsResult, null);
if (MatchesRequest(ref request, ref result)) {
return result;
}
}
string nsResult = u.SearchNamespace(request.Name);
if (nsResult != null) {
result = new SearchTypeResult(nsResult, null);
if (MatchesRequest(request, ref result)) {
return true;
}
}
return result;
return false;
}
/// <summary>

Loading…
Cancel
Save