public LocalDocumentInfo BuildLocalDocument (DocumentInfo info, TextEditorData data,
		                                             string expressionText, string textAfterCaret, bool isExpression)
		{
			var sb = new StringBuilder ();
			
			WriteUsings (info.Imports, sb);
			WriteClassDeclaration (info, sb);
			sb.AppendLine ("{");
			var result = new LocalDocumentInfo ();
			if (isExpression) {
				sb.AppendLine ("void Generated ()");
				sb.AppendLine ("{");
				//Console.WriteLine ("start:" + location.BeginLine  +"/" +location.BeginColumn);
				foreach (var node in info.XExpressions) {
					bool isBlock = node is AspNetRenderBlock;

					if (node.Region.Begin.Line > data.Caret.Line || node.Region.Begin.Line == data.Caret.Line && node.Region.Begin.Column > data.Caret.Column - 5) 
						continue;
					//Console.WriteLine ("take xprt:" + expressions.Key.BeginLine  +"/" +expressions.Key.BeginColumn);

					var start = data.Document.LocationToOffset (node.Region.Begin.Line, node.Region.Begin.Column) + 2;
					var end = data.Document.LocationToOffset (node.Region.End.Line, node.Region.End.Column) - 2;

					if (!isBlock) {
						sb.Append ("WriteLine (");
						start += 1;
					}

					string expr = data.GetTextBetween (start, end);
					result.AddTextPosition (start, end, expr.Length);
					sb.Append (expr);

					if (!isBlock)
						sb.Append (");");
				}
			}
			sb.Append (expressionText);
			int caretPosition = sb.Length;
			sb.Append (textAfterCaret);
			
			sb.AppendLine ();
			sb.AppendLine ("}");
			sb.AppendLine ("}");
			
			result.LocalDocument = sb.ToString ();
			result.CaretPosition = caretPosition;
			result.OriginalCaretPosition = data.Caret.Offset;
			result.ParsedLocalDocument = Parse (info.AspNetDocument.FileName, sb.ToString ());
			return result;
		}
Beispiel #2
0
        public void InitializeCodeCompletion(char ch)
        {
            int caretOffset = Document.Editor.Caret.Offset;
            int start       = caretOffset - Tracker.Engine.CurrentStateLength;

            if (Document.Editor.GetCharAt(start) == '=')
            {
                start++;
            }
            string sourceText = Document.Editor.GetTextBetween(start, caretOffset);

            if (ch != '\0')
            {
                sourceText += ch;
            }
            string textAfterCaret = Document.Editor.GetTextBetween(caretOffset, Math.Min(Document.Editor.Length, Math.Max(caretOffset, Tracker.Engine.Position + Tracker.Engine.CurrentStateLength - 2)));

            var loc    = new MonoDevelop.AspNet.Parser.Internal.Location();
            var docLoc = Document.Editor.Document.OffsetToLocation(start);

            loc.EndLine   = loc.BeginLine = docLoc.Line;
            loc.EndColumn = loc.BeginColumn = docLoc.Column;
            if (documentBuilder == null)
            {
                localDocumentInfo = null;
                return;
            }
            localDocumentInfo = documentBuilder.BuildLocalDocument(documentInfo, Editor, sourceText, textAfterCaret, true);

            var viewContent = new MonoDevelop.Ide.Gui.HiddenTextEditorViewContent();

            viewContent.Project     = Document.Project;
            viewContent.ContentName = localDocumentInfo.ParsedLocalDocument.FileName;

            viewContent.Text = localDocumentInfo.LocalDocument;
            viewContent.GetTextEditorData().Caret.Offset = localDocumentInfo.CaretPosition;

            var workbenchWindow = new MonoDevelop.Ide.Gui.HiddenWorkbenchWindow();

            workbenchWindow.ViewContent      = viewContent;
            localDocumentInfo.HiddenDocument = new MonoDevelop.Ide.Gui.Document(workbenchWindow)
            {
                ParsedDocument = localDocumentInfo.ParsedLocalDocument,
                Dom            = domWrapper
            };
        }
		public LocalDocumentInfo BuildLocalDocument (DocumentInfo info, TextEditorData data,
		                                             string expressionText, string textAfterCaret, bool isExpression)
		{
			var sb = new StringBuilder ();
			
			WriteUsings (info.Imports, sb);
			WriteClassDeclaration (info, sb);
			sb.AppendLine ("{");
			var result = new LocalDocumentInfo ();
			if (isExpression) {
				sb.AppendLine ("void Generated ()");
				sb.AppendLine ("{");
				//Console.WriteLine ("start:" + location.BeginLine  +"/" +location.BeginColumn);
				foreach (var expression in info.Expressions) {
					if (expression.Location.BeginLine > data.Caret.Line || expression.Location.BeginLine == data.Caret.Line && expression.Location.BeginColumn > data.Caret.Column - 5) 
						continue;
					//Console.WriteLine ("take xprt:" + expressions.Key.BeginLine  +"/" +expressions.Key.BeginColumn);
					if (expression.IsExpression)
						sb.Append ("WriteLine (");
					string expr = expression.Expression.Trim ('=');
					result.AddTextPosition (data.Document.LocationToOffset (expression.Location.BeginLine, expression.Location.BeginColumn), sb.Length, expr.Length);
					sb.Append (expr);
					if (expression.IsExpression)
						sb.Append (");");
				}
			}
			sb.Append (expressionText);
			int caretPosition = sb.Length;
			sb.Append (textAfterCaret);
			
			sb.AppendLine ();
			sb.AppendLine ("}");
			sb.AppendLine ("}");
			
			result.LocalDocument = sb.ToString ();
			result.CaretPosition = caretPosition;
			result.OriginalCaretPosition = data.Caret.Offset;
			result.ParsedLocalDocument = Parse (info.AspNetDocument.FileName, sb.ToString ());
			
			return result;
		}
Beispiel #4
0
        public void InitializeCodeCompletion()
        {
            int caretOffset = Document.TextEditorData.Caret.Offset;
            int start       = caretOffset - Tracker.Engine.CurrentStateLength;

            if (Document.TextEditor.GetCharAt(start) == '=')
            {
                start++;
            }

            string sourceText     = Document.TextEditor.GetText(start, caretOffset);
            string textAfterCaret = Document.TextEditor.GetText(caretOffset, Tracker.Engine.Position + Tracker.Engine.CurrentStateLength - start);

            var loc    = new MonoDevelop.AspNet.Parser.Internal.Location();
            var docLoc = Document.TextEditorData.Document.OffsetToLocation(start);

            loc.EndLine   = loc.BeginLine = docLoc.Line;
            loc.EndColumn = loc.BeginColumn = docLoc.Column;

            localDocumentInfo = documentBuilder.BuildLocalDocument(documentInfo, TextEditorData, sourceText, textAfterCaret, true);

            var viewContent = new MonoDevelop.Ide.Gui.HiddenTextEditorViewContent();

            viewContent.Project     = Document.Project;
            viewContent.ContentName = localDocumentInfo.ParsedLocalDocument.FileName;

            viewContent.Text = localDocumentInfo.LocalDocument;
            viewContent.GetTextEditorData().Caret.Offset = localDocumentInfo.CaretPosition;

            var workbenchWindow = new MonoDevelop.Ide.Gui.HiddenWorkbenchWindow();

            workbenchWindow.ViewContent = viewContent;
            hiddenDocument = new MonoDevelop.Ide.Gui.Document(workbenchWindow);

            hiddenDocument.ParsedDocument = localDocumentInfo.ParsedLocalDocument;
        }
			public AspCompletionWidget (MonoDevelop.Ide.Gui.Document realDocument, LocalDocumentInfo localInfo)
			{
				this.realDocument = realDocument;
				this.localInfo = localInfo;
			}
		CSharpTextEditorCompletion CreateCompletion (MonoDevelop.Ide.Gui.Document realDocument, DocumentInfo info, LocalDocumentInfo localInfo, out CodeCompletionContext codeCompletionContext)
		{
			var doc = new Mono.TextEditor.Document () {
				Text = localInfo.LocalDocument,
			};
			var documentLocation = doc.OffsetToLocation (localInfo.CaretPosition);
			
			codeCompletionContext = new CodeCompletionContext () {
				TriggerOffset = localInfo.CaretPosition,
				TriggerLine = documentLocation.Line,
				TriggerLineOffset = documentLocation.Column - 1
			};
			
			var r = new System.IO.StringReader (localInfo.LocalDocument);
			using (var parser = ICSharpCode.NRefactory.ParserFactory.CreateParser (SupportedLanguage.CSharp, r)) {
				parser.Parse ();
				return new CSharpTextEditorCompletion (localInfo.HiddenDocument) {
					ParsedUnit = parser.CompilationUnit,
					CompletionWidget = CreateCompletionWidget (realDocument, localInfo),
					Dom = localInfo.HiddenDocument.Dom
				};
			}
		}
		public ICompletionWidget CreateCompletionWidget (MonoDevelop.Ide.Gui.Document realDocument, LocalDocumentInfo localInfo)
		{
			return new AspCompletionWidget (realDocument, localInfo);
		}
		public bool GetParameterCompletionCommandOffset (MonoDevelop.Ide.Gui.Document realDocument, DocumentInfo info, LocalDocumentInfo localInfo, out int cpos)
		{
			CodeCompletionContext codeCompletionContext;
			using (var completion = CreateCompletion (realDocument, info, localInfo, out codeCompletionContext)) {
				
				return completion.GetParameterCompletionCommandOffset (out cpos);
			}
		}
		public IParameterDataProvider HandleParameterCompletion (MonoDevelop.Ide.Gui.Document realDocument, CodeCompletionContext completionContext, DocumentInfo info, LocalDocumentInfo localInfo, char completionChar)
		{
			CodeCompletionContext ccc;
			using (var completion = CreateCompletion (realDocument, info, localInfo, out ccc)) {
				return completion.HandleParameterCompletion (completionContext, completionChar);
			}
		}
		public ICompletionDataList HandleCompletion (MonoDevelop.Ide.Gui.Document realDocument, CodeCompletionContext completionContext, DocumentInfo info, LocalDocumentInfo localInfo, char currentChar, ref int triggerWordLength)
		{
			CodeCompletionContext ccc;
			using (var completion = CreateCompletion (realDocument, info, localInfo, out ccc)) {
				return completion.HandleCodeCompletion (completionContext, currentChar, ref triggerWordLength);
			}
		}
		public ICompletionDataList HandlePopupCompletion (MonoDevelop.Ide.Gui.Document realDocument, DocumentInfo info, LocalDocumentInfo localInfo)
		{
			CodeCompletionContext codeCompletionContext;
			using (var completion = CreateCompletion (realDocument, info, localInfo, out codeCompletionContext)) {
				return completion.CodeCompletionCommand (codeCompletionContext);
			}
		}
		public IParameterDataProvider HandleParameterCompletion (MonoDevelop.Ide.Gui.Document document, 
			DocumentInfo info, LocalDocumentInfo localInfo, ProjectDom dom, char completionChar)
		{
			CodeCompletionContext codeCompletionContext;
			using (var completion = CreateCompletion (document, info, localInfo, dom, out codeCompletionContext)) {
				return completion.HandleParameterCompletion (codeCompletionContext, completionChar);
			}
		}
		CSharpCompletionTextEditorExtension CreateCompletion (MonoDevelop.Ide.Gui.Document realDocument, DocumentInfo info, LocalDocumentInfo localInfo, out CodeCompletionContext codeCompletionContext)
		{
			var doc = new Mono.TextEditor.TextDocument () {
				Text = localInfo.LocalDocument,
			};
			var documentLocation = doc.OffsetToLocation (localInfo.CaretPosition);
			
			codeCompletionContext = new CodeCompletionContext () {
				TriggerOffset = localInfo.CaretPosition,
				TriggerLine = documentLocation.Line,
				TriggerLineOffset = documentLocation.Column - 1
			};
			
			return new CSharpCompletionTextEditorExtension (localInfo.HiddenDocument) {
				CompletionWidget = CreateCompletionWidget (realDocument, localInfo)
			};
		}