[MonoDevelop] Re: Removing SourceEditor{View, Buffer} dependancy from CompletionListWindow.

Peter Johanson latexer at gentoo.org
Thu Jun 16 23:41:00 EDT 2005


On Thu, Jun 16, 2005 at 08:29:09PM -0700, Peter Johanson wrote:
> 
> No changelog entry included in the patch, as I'm mainly interested in
> feedback or problems with the changes, so I can refine this more.
> 

adding the patch would be nice.

-pete

-- 
Peter Johanson
<latexer at gentoo.org>
-------------- next part --------------
Index: Core/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
===================================================================
--- Core/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs	(revision 2602)
+++ Core/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs	(working copy)
@@ -193,8 +193,7 @@
 				return;
 			triggerIter.ForwardChar ();
 			
-//			CompletionWindow.ShowWindow (triggerChar, triggerIter, true, new CodeCompletionDataProvider (true), this);
-			CompletionListWindow.ShowWindow (triggerChar, triggerIter, new CodeCompletionDataProvider (true), this);
+			CompletionListWindow.ShowWindow (triggerChar, triggerIter, new CodeCompletionDataProvider (true), this, this.ParentEditor.DisplayBinding.Project, this.ParentEditor.DisplayBinding.ContentName);
 		}
 
 		bool MonodocResolver ()
@@ -226,7 +225,7 @@
 			IParserService parser = (IParserService)ServiceManager.GetService (typeof (IParserService));
 			string fileName = ParentEditor.DisplayBinding.ContentName;
 			IExpressionFinder expressionFinder = parser.GetExpressionFinder(fileName);
-			string expression    = expressionFinder == null ? TextUtilities.GetExpressionBeforeOffset(this, insertIter.Offset) : expressionFinder.FindExpression(buf.GetText(buf.StartIter, insertIter, true), insertIter.Offset - 2);
+			string expression    = expressionFinder == null ? TextUtilities.GetExpressionBeforeOffset(this.Buffer.Text, insertIter.Offset) : expressionFinder.FindExpression(buf.GetText(buf.StartIter, insertIter, true), insertIter.Offset - 2);
 			if (expression == null) return false;
 			Console.WriteLine ("Expression: {" + expression + "}");
 			string type = parser.MonodocResolver (ParentEditor.DisplayBinding.Project, expression, insertIter.Line + 1, insertIter.LineOffset + 1, fileName, buf.Text);
@@ -376,8 +375,7 @@
 			case '.':
 				bool retval = base.OnKeyPressEvent (evnt);
 				if (EnableCodeCompletion && PeekCharIsWhitespace ()) {
-//					CompletionWindow.ShowWindow ((char)key, buf.GetIterAtMark (buf.InsertMark), false, new CodeCompletionDataProvider (), this);
-					CompletionListWindow.ShowWindow ((char)key, buf.GetIterAtMark (buf.InsertMark), new CodeCompletionDataProvider (), this);
+					CompletionListWindow.ShowWindow ((char)key, buf.GetIterAtMark (buf.InsertMark), new CodeCompletionDataProvider (), this, this.ParentEditor.DisplayBinding.Project, this.ParentEditor.DisplayBinding.ContentName);
 				}
 				return retval;
 				/*case '(':
@@ -650,7 +648,7 @@
 		int IFormattableDocument.GetClosingBraceForLine (int ln, out int openingLine)
 		{
 			int offset = MonoDevelop.SourceEditor.CodeCompletion.TextUtilities.SearchBracketBackward
-				(this, Buffer.GetIterAtLine (ln).Offset - 1, '{', '}');
+				(this.Buffer.Text, Buffer.GetIterAtLine (ln).Offset - 1, '{', '}');
 			
 			openingLine = offset == -1 ? -1 : Buffer.GetIterAtOffset (offset).Line;
 			return offset;
Index: Core/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/MethodInsightDataProvider.cs
===================================================================
--- Core/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/MethodInsightDataProvider.cs	(revision 2602)
+++ Core/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/MethodInsightDataProvider.cs	(working copy)
@@ -58,7 +58,7 @@
 			initialOffset = initialIter.Offset;
 			string text = textArea.Buffer.Text;
 			
-			string word         = TextUtilities.GetExpressionBeforeOffset(textArea, initialOffset);
+			string word         = TextUtilities.GetExpressionBeforeOffset(textArea.Buffer.Text, initialOffset);
 			string methodObject = word;
 			string methodName   =  null;
 			int idx = methodObject.LastIndexOf('.');
Index: Core/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/IndexerInsightDataProvider.cs
===================================================================
--- Core/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/IndexerInsightDataProvider.cs	(revision 2602)
+++ Core/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/IndexerInsightDataProvider.cs	(working copy)
@@ -54,7 +54,7 @@
 			Gtk.TextIter initialIter = textArea.Buffer.GetIterAtMark (textArea.Buffer.InsertMark);
 			initialOffset = initialIter.Offset;
 			
-			string word         = TextUtilities.GetExpressionBeforeOffset(textArea, initialOffset);
+			string word         = TextUtilities.GetExpressionBeforeOffset(textArea.Buffer.Text, initialOffset);
 			string methodObject = word;
 			
 			// the parser works with 1 based coordinates
Index: Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/ICompletionData.cs
===================================================================
--- Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/ICompletionData.cs	(revision 2602)
+++ Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/ICompletionData.cs	(working copy)
@@ -33,7 +33,7 @@
 			get;
 		}
 		
-		void InsertAction(SourceEditorView control);
+		void InsertAction(Gtk.TextView control);
 	}
 	
 	public interface ICompletionDataWithMarkup : ICompletionData
Index: Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionListWindow.cs
===================================================================
--- Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionListWindow.cs	(revision 2602)
+++ Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionListWindow.cs	(working copy)
@@ -12,7 +12,7 @@
 	{
 		string fileName;
 		Project project;
-		SourceEditorView control;
+		TextView view;
 		TextMark triggeringMark;
 		ICompletionData[] completionData;
 		DeclarationViewWindow declarationviewwindow = new DeclarationViewWindow ();
@@ -40,13 +40,13 @@
 			SizeAllocated += new SizeAllocatedHandler (ListSizeChanged);
 		}
 		
-		public static void ShowWindow (char firstChar, TextIter trigIter, ICompletionDataProvider provider, SourceEditorView ctrl)
+		public static void ShowWindow (char firstChar, TextIter trigIter, ICompletionDataProvider provider, TextView view, Project project, string fileName)
 		{
-			if (!wnd.ShowListWindow (firstChar, trigIter, provider,  ctrl))
+			if (!wnd.ShowListWindow (firstChar, trigIter, provider,  view, project, fileName))
 				return;
 			
 			// makes control-space in midle of words to work
-			TextBuffer buf = wnd.control.Buffer; 
+			TextBuffer buf = wnd.view.Buffer; 
 			string text = buf.GetText (trigIter, buf.GetIterAtMark (buf.InsertMark), false);
 			if (text.Length == 0)
 				return;
@@ -63,28 +63,28 @@
 			wnd.PartialWord = wnd.CompleteWord;		
 		}
 		
-		bool ShowListWindow (char firstChar, TextIter trigIter, ICompletionDataProvider provider, SourceEditorView ctrl)
+		bool ShowListWindow (char firstChar, TextIter trigIter, ICompletionDataProvider provider, TextView view, Project project, string fileName)
 		{
-			this.control = ctrl;
-			this.fileName = ctrl.ParentEditor.DisplayBinding.ContentName;
-			this.project = ctrl.ParentEditor.DisplayBinding.Project;
-			triggeringMark = control.Buffer.CreateMark (null, trigIter, true);
+			this.view = view;
+			this.fileName = fileName;
+			this.project = project;
+			triggeringMark = view.Buffer.CreateMark (null, trigIter, true);
 			
-			completionData = provider.GenerateCompletionData (project, fileName, ctrl, firstChar, triggeringMark);
+			completionData = provider.GenerateCompletionData (project, fileName, view.Buffer.Text, firstChar, trigIter.Offset, trigIter.Line, trigIter.LineOffset);
 			if (completionData == null || completionData.Length == 0) return false;
 			
-			this.Style = ctrl.Style.Copy();
+			this.Style = view.Style.Copy();
 			
 			Array.Sort (completionData, dataComparer);
 			
 			DataProvider = this;
-			Gdk.Rectangle rect = control.GetIterLocation (control.Buffer.GetIterAtMark (triggeringMark));
+			Gdk.Rectangle rect = view.GetIterLocation (view.Buffer.GetIterAtMark (triggeringMark));
 
 			int wx, wy;
-			control.BufferToWindowCoords (Gtk.TextWindowType.Widget, rect.X /*+ rect.Width*/, rect.Y + rect.Height, out wx, out wy);
+			view.BufferToWindowCoords (Gtk.TextWindowType.Widget, rect.X /*+ rect.Width*/, rect.Y + rect.Height, out wx, out wy);
 			
 			int tx, ty;
-			control.GdkWindow.GetOrigin (out tx, out ty);
+			view.GdkWindow.GetOrigin (out tx, out ty);
 			
 			int x = tx + wx;
 			int y = ty + wy;
@@ -140,11 +140,11 @@
 		
 		void UpdateWord ()
 		{
-			TextIter offsetIter = wnd.control.Buffer.GetIterAtMark (wnd.triggeringMark);
-			TextIter endIter = wnd.control.Buffer.GetIterAtOffset (offsetIter.Offset + wnd.PartialWord.Length);
-			wnd.control.Buffer.MoveMark (wnd.control.Buffer.InsertMark, offsetIter);
-			wnd.control.Buffer.Delete (ref offsetIter, ref endIter);
-			wnd.control.Buffer.InsertAtCursor (wnd.CompleteWord);
+			TextIter offsetIter = wnd.view.Buffer.GetIterAtMark (wnd.triggeringMark);
+			TextIter endIter = wnd.view.Buffer.GetIterAtOffset (offsetIter.Offset + wnd.PartialWord.Length);
+			wnd.view.Buffer.MoveMark (wnd.view.Buffer.InsertMark, offsetIter);
+			wnd.view.Buffer.Delete (ref offsetIter, ref endIter);
+			wnd.view.Buffer.InsertAtCursor (wnd.CompleteWord);
 		}
 		
 		public new void Hide ()
Index: Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CodeCompletionData.cs
===================================================================
--- Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CodeCompletionData.cs	(revision 2602)
+++ Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CodeCompletionData.cs	(working copy)
@@ -219,9 +219,9 @@
 			documentation = "";
 		}
 		
-		public void InsertAction (SourceEditorView control)
+		public void InsertAction (Gtk.TextView view)
 		{
-			control.Buffer.InsertAtCursor (completionString);
+			view.Buffer.InsertAtCursor (completionString);
 		}
 
 		public static string GetDocumentation (string doc)
Index: Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TextUtilities.cs
===================================================================
--- Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TextUtilities.cs	(revision 2602)
+++ Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TextUtilities.cs	(working copy)
@@ -74,23 +74,20 @@
 		/// That method is used in code completion to determine the expression given
 		/// to the parser for type resolve.
 		/// </remarks>
-		public static string GetExpressionBeforeOffset(SourceEditorView textArea, int offset)
+		public static string GetExpressionBeforeOffset(string text, int offset)
 		{
-			// FIXME: we should actually use GtkTextIter's
-			string text = textArea.Buffer.Text;
 			int origOffset = offset;
 			
 			while (offset - 1 > 0) {
 				switch (text [offset - 1]) {
 					case '}':
 						goto done;
-//						offset = SearchBracketBackward(document, offset - 2, '{','}');
 //						break;
 					case ']':
-						offset = SearchBracketBackward(textArea, offset - 2, '[',']');
+						offset = SearchBracketBackward(text, offset - 2, '[',']');
 						break;
 					case ')':
-						offset = SearchBracketBackward(textArea, offset - 2, '(',')');
+						offset = SearchBracketBackward(text, offset - 2, '(',')');
 						break;
 					case '.':
 						--offset;
@@ -119,11 +116,9 @@
 							--start;
 						}
 						
-						//Console.WriteLine("{0} -- {1}", offset, start);
-						Gtk.TextIter startIter = textArea.Buffer.GetIterAtOffset (start);
-						Gtk.TextIter endIter = textArea.Buffer.GetIterAtOffset (offset);
-						string word = textArea.Buffer.GetText (startIter, endIter, false).Trim();
-						//Console.WriteLine("word >{0}<", word);
+						Console.WriteLine("{0} -- {1}", offset, start);
+						string word = text.Substring(start, offset - start);
+						Console.WriteLine("word >{0}<", word);
 						switch (word) {
 							case "ref":
 							case "out":
@@ -142,11 +137,8 @@
 				}
 			}
 			done:
-//			Console.WriteLine("ofs : {0} cart:{1}", offset, document.Caret.Offset);
-//			Console.WriteLine("return:" + document.GetText(offset, document.Caret.Offset - offset).Trim());
-			Gtk.TextIter start_Iter = textArea.Buffer.GetIterAtOffset (origOffset);
-			Gtk.TextIter offset_Iter = textArea.Buffer.GetIterAtOffset (offset);
-			return textArea.Buffer.GetText (start_Iter, offset_Iter, false ).Trim();
+//			Console.WriteLine("offset : {0} origOffset: {1}", offset, origOffset);
+			return offset - origOffset > 0 ? text.Substring(origOffset, offset - origOffset).Trim() : "";
 		}
 		
 /*		
@@ -244,10 +236,8 @@
 			return document.GetText(line.Offset, line.Length);
 		}
 */
-		static bool ScanLineComment(SourceEditorView document, int offset)
+		static bool ScanLineComment(string text, int offset)
 		{
-			// FIXME: use iters
-			string text = document.Buffer.Text;
 			while (offset > 0 && offset < text.Length) {
 				char ch = text [offset];
 				switch (ch) {
@@ -265,10 +255,9 @@
 			return false;
 		}
 		
-		public static int SearchBracketBackward(SourceEditorView document, int offset, char openBracket, char closingBracket)
+		public static int SearchBracketBackward(string text, int offset, char openBracket, char closingBracket)
 		{
 			// FIXME: use iters
-			string text = document.Buffer.Text;			
 			int brackets = -1;		
 			bool inString = false;
 			bool inChar   = false;	
@@ -290,22 +279,22 @@
 						}
 						break;
 					case '"':
-						if (!inChar && !blockComment && !ScanLineComment(document, offset)) {
+						if (!inChar && !blockComment && !ScanLineComment(text, offset)) {
 							inString = !inString;
 						}
 						break;
 					case '\'':
-						if (!inString && !blockComment && !ScanLineComment(document, offset)) {
+						if (!inString && !blockComment && !ScanLineComment(text, offset)) {
 							inChar = !inChar;
 						}
 						break;
 					default :
 						if (ch == closingBracket) {
-							if (!(inString || inChar || blockComment) && !ScanLineComment(document, offset)) {
+							if (!(inString || inChar || blockComment) && !ScanLineComment(text, offset)) {
 								--brackets;
 							}
 						} else if (ch == openBracket) {
-							if (!(inString || inChar || blockComment) && !ScanLineComment(document, offset)) {
+							if (!(inString || inChar || blockComment) && !ScanLineComment(text, offset)) {
 								++brackets;
 								if (brackets == 0) {
 									return offset;
Index: Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionWindow.cs
===================================================================
--- Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionWindow.cs	(revision 2602)
+++ Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionWindow.cs	(working copy)
@@ -334,7 +334,9 @@
 		
 		void FillList (bool firstTime, char ch)
 		{
-			ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(project, fileName, control, ch, triggeringMark);
+			TextIter offsetIter = control.Buffer.GetIterAtMark (triggeringMark);
+			ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(project, fileName, control.Buffer.Text, ch, offsetIter.Offset, offsetIter.Line, offsetIter.LineOffset);
+
 			if (completionData == null || completionData.Length == 0) {
 				return;
 			}
Index: Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CommentCompletionDataProvider.cs
===================================================================
--- Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CommentCompletionDataProvider.cs	(revision 2602)
+++ Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CommentCompletionDataProvider.cs	(working copy)
@@ -63,7 +63,7 @@
 			return row >= region.BeginLine && (row <= region.EndLine || region.EndLine == -1);
 		}
 		
-		public ICompletionData[] GenerateCompletionData (Project project, string fileName, SourceEditorView textArea, char charTyped, Gtk.TextMark triggerMark)
+		public ICompletionData[] GenerateCompletionData (Project project, string fileName, string text, char charTyped, int triggerOffset, int caret_line, int caret_column)
 		{
 			/*caretLineNumber = textArea.Caret.Line;
 			caretColumn     = textArea.Caret.Column;
@@ -114,7 +114,7 @@
 				}
 			}
 			
-			public void InsertAction (SourceEditorView control)
+			public void InsertAction (Gtk.TextView view)
 			{
 				//((SharpDevelopTextAreaControl)control).ActiveTextAreaControl.TextArea.InsertString(text);
 			}
Index: Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/ICompletionDataProvider.cs
===================================================================
--- Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/ICompletionDataProvider.cs	(revision 2602)
+++ Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/ICompletionDataProvider.cs	(working copy)
@@ -17,6 +17,6 @@
 
 namespace MonoDevelop.SourceEditor.CodeCompletion {
 	public interface ICompletionDataProvider {
-		ICompletionData[] GenerateCompletionData(Project project, string fileName, SourceEditorView textArea, char charTyped, Gtk.TextMark mark);
+		ICompletionData[] GenerateCompletionData(Project project, string fileName, string text, char charTyped, int triggerOffset, int caret_line, int caret_column);
 	}
 }
Index: Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CodeCompletionDataProvider.cs
===================================================================
--- Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CodeCompletionDataProvider.cs	(revision 2602)
+++ Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CodeCompletionDataProvider.cs	(working copy)
@@ -55,29 +55,26 @@
 		
 		ArrayList completionData = null;
 		
-		public ICompletionData[] GenerateCompletionData(Project project, string fileName, SourceEditorView textArea, char charTyped, TextMark triggerMark)
+		public ICompletionData[] GenerateCompletionData(Project project, string fileName, string text, char charTyped, int triggerOffset, int caret_line, int caret_column)
 		{
 			completionData = new ArrayList();
 			this.fileName = fileName;
 			
-			Gtk.TextIter insertIter = textArea.Buffer.GetIterAtMark (triggerMark);
-			
 			// the parser works with 1 based coordinates
-			
-			caretLineNumber      = insertIter.Line + 1;
-			caretColumn          = insertIter.LineOffset + 1;
+			caretLineNumber      = caret_line + 1;
+			caretColumn          = caret_column + 1;
 			//string expression    = TextUtilities.GetExpressionBeforeOffset (textArea, insertIter.Offset);
 			ResolveResult results;
 			
 			IParserService parserService = (IParserService)MonoDevelop.Core.Services.ServiceManager.GetService(typeof(IParserService));
 			IExpressionFinder expressionFinder = parserService.GetExpressionFinder(fileName);
-			string expression    = expressionFinder == null ? TextUtilities.GetExpressionBeforeOffset(textArea, insertIter.Offset) : expressionFinder.FindExpression(textArea.Buffer.GetText(textArea.Buffer.StartIter, insertIter, true), insertIter.Offset - 2);
+			string expression    = expressionFinder == null ? TextUtilities.GetExpressionBeforeOffset(text, triggerOffset) : expressionFinder.FindExpression(text.Substring(0, triggerOffset), triggerOffset - 2);
 			if (expression == null) return null;
 			Console.WriteLine ("Expr: |{0}|", expression);
 			//FIXME: This chartyped check is a fucking *HACK*
 			if (expression == "is" || expression == "as") {
-				string expr = expressionFinder == null ? TextUtilities.GetExpressionBeforeOffset (textArea, insertIter.Offset - 3) : expressionFinder.FindExpression (textArea.Buffer.GetText (textArea.Buffer.StartIter, insertIter, true), insertIter.Offset - 5);
-				AddResolveResults (parserService.IsAsResolve (project, expr, caretLineNumber, caretColumn, fileName, textArea.Buffer.Text));
+				string expr = expressionFinder == null ? TextUtilities.GetExpressionBeforeOffset (text, triggerOffset - 3) : expressionFinder.FindExpression (text.Substring(0, triggerOffset), triggerOffset - 5);
+				AddResolveResults (parserService.IsAsResolve (project, expr, caretLineNumber, caretColumn, fileName, text));
 				return (ICompletionData[])completionData.ToArray (typeof (ICompletionData));
 			}
 			if (ctrlspace && charTyped != '.') {
@@ -92,7 +89,7 @@
 			} else {
 				//FIXME: I added the null check, #D doesnt need it, why do we?
 				if (fileName != null) {
-					results = parserService.Resolve(project, expression, caretLineNumber, caretColumn, fileName, textArea.Buffer.Text);
+					results = parserService.Resolve(project, expression, caretLineNumber, caretColumn, fileName, text);
 					AddResolveResults(results);
 				}
 			}
Index: Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TemplateCompletionDataProvider.cs
===================================================================
--- Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TemplateCompletionDataProvider.cs	(revision 2602)
+++ Core/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/TemplateCompletionDataProvider.cs	(working copy)
@@ -27,7 +27,7 @@
 			}
 		}
 		
-		public ICompletionData[] GenerateCompletionData(Project project, string fileName, SourceEditorView textArea, char charTyped, Gtk.TextMark triggerMark)
+		public ICompletionData[] GenerateCompletionData(Project project, string fileName, string text, char charTyped, int triggerOffset, int caret_line, int caret_column)
 		{
 			CodeTemplateGroup templateGroup = CodeTemplateLoader.GetTemplateGroupPerFilename(fileName);
 			if (templateGroup == null) {
@@ -74,7 +74,7 @@
 				}
 			}
 			
-			public void InsertAction(SourceEditorView control)
+			public void InsertAction(Gtk.TextView control)
 			{
 				//((SharpDevelopTextAreaControl)control).InsertTemplate(template);
 			}


More information about the Monodevelop-list mailing list