Inheritance: AbstractAnnotatable, IBuffer, ICSharpCode.NRefactory.Editor.IDocument
        // todo: move to version control backend
        IEnumerable <Conflict> Conflicts(Mono.TextEditor.TextDocument doc)
        {
            int mergeStart = 0;

            while ((mergeStart = doc.IndexOf("<<<<<<<", mergeStart, doc.TextLength - mergeStart, StringComparison.Ordinal)) >= 0)
            {
                DocumentLine start = doc.GetLineByOffset(mergeStart);
                if (start.Offset != mergeStart)
                {
                    continue;
                }
                int          dividerOffset = doc.IndexOf("=======", mergeStart, doc.TextLength - mergeStart, StringComparison.Ordinal);
                DocumentLine divider       = doc.GetLineByOffset(dividerOffset);

                int          endOffset = doc.IndexOf(">>>>>>>", dividerOffset, doc.TextLength - dividerOffset, StringComparison.Ordinal);
                DocumentLine end       = doc.GetLineByOffset(endOffset);
                mergeStart = dividerOffset + 1;

                yield return(new Conflict(new TextSegment(start.EndOffsetIncludingDelimiter, divider.Offset - start.EndOffsetIncludingDelimiter),
                                          new TextSegment(divider.EndOffsetIncludingDelimiter, end.Offset - divider.EndOffsetIncludingDelimiter),
                                          start,
                                          divider,
                                          end));
            }
        }
Esempio n. 2
0
                MonoDevelop.Projects.Project GetProject(Mono.TextEditor.TextDocument doc)
                {
                    // There is no reference between document & higher level infrastructure,
                    // therefore it's a bit tricky to find the right project.

                    MonoDevelop.Projects.Project project = null;
                    var view = doc.Annotation <MonoDevelop.SourceEditor.SourceEditorView> ();

                    if (view != null)
                    {
                        project = view.Project;
                    }

                    if (project == null)
                    {
                        var ideDocument = IdeApp.Workbench.GetDocument(doc.FileName);
                        if (ideDocument != null)
                        {
                            project = ideDocument.Project;
                        }
                    }

                    if (project == null)
                    {
                        project = IdeApp.Workspace.GetProjectContainingFile(doc.FileName);
                    }

                    return(project);
                }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Trilogic.CompareWindow"/> class.
        /// </summary>
        /// <param name="parent">The parent window.</param>
        /// <param name="compareName">Compare name.</param>
        /// <param name="fileSide">File side.</param>
        /// <param name="databaseSide">Database side.</param>
        public CompareWindow(MainWindow parent, string compareName, SchemaData fileSide, SchemaData databaseSide)
            : base(Gtk.WindowType.Toplevel)
        {
            this.Build();
            this.parent = parent;

            this.docLocal = new TextDocument();
            this.docDB = new TextDocument();

            this.editorLocal = new TextEditor(this.docLocal);
            this.editorDB = new TextEditor(this.docDB);

            Gtk.ScrolledWindow scrollLocal = new Gtk.ScrolledWindow();
            Gtk.ScrolledWindow scrollDB = new Gtk.ScrolledWindow();
            scrollLocal.Add(this.editorLocal);
            scrollDB.Add(this.editorDB);

            this.hbox1.Add(scrollDB);
            this.hbox1.Add(scrollLocal);

            Gtk.Box.BoxChild childLocal = (Gtk.Box.BoxChild)this.hbox1[scrollLocal];
            childLocal.Position = 2;

            Gtk.Box.BoxChild childDB = (Gtk.Box.BoxChild)this.hbox1[scrollDB];
            childDB.Position = 0;

            this.ShowAll();

            this.Title += " - " + compareName;

            this.fileSide = fileSide;
            this.databaseSide = databaseSide;

            this.ShowSchema();
        }
		public void InvalidMimeTypeInScriptTypeAttribute ()
		{
			var doc = new TextDocument ();
			var syntaxMode = new WebFormsSyntaxMode ();
			syntaxMode.Document = doc;
			doc.Text = 
@"<%@ Page Language=""C#"" Inherits=""AspnetTest.Default"" %>
<!DOCTYPE html>
<html>
<head runat=""server"">
	<title>Default</title>
</head>
<body>
	<form id=""form1"" runat=""server"">
		<asp:Button id=""button1"" runat=""server"" Text=""Click me!"" OnClick=""button1Clicked"" />
	</form>
	<script type=""></script>
</body>
</html>
";
			var style = new ColorScheme ();
			foreach (DocumentLine line in doc.Lines) {
				Assert.DoesNotThrow (() => syntaxMode.GetChunks (style, line, line.Offset, line.Length).ToList ());
			}
		}
    void SetLocationTextData (Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
    {
        CellRendererText cellRendererText = (CellRendererText)cell;
        Change change = store.GetValue (iter, objColumn) as Change;
        cellRendererText.Visible = (bool)store.GetValue (iter, statusVisibleColumn);
        TextReplaceChange replaceChange = change as TextReplaceChange;
        if (replaceChange == null)
        {
            cellRendererText.Text = "";
            return;
        }

        Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument ();
        doc.Text = Mono.TextEditor.Utils.TextFileUtility.ReadAllText (replaceChange.FileName);
        DocumentLocation loc = doc.OffsetToLocation (replaceChange.Offset);

        string text = string.Format (GettextCatalog.GetString ("(Line:{0}, Column:{1})"), loc.Line, loc.Column);
        if (treeviewPreview.Selection.IterIsSelected (iter))
        {
            cellRendererText.Text = text;
        }
        else
        {
            cellRendererText.Markup = "<span foreground=\"" + MonoDevelop.Components.PangoCairoHelper.GetColorString (Style.Text (StateType.Insensitive)) + "\">" + text + "</span>";
        }
    }
Esempio n. 6
0
                public ConditinalExpressionEvaluator(Mono.TextEditor.TextDocument doc, IEnumerable <string> symbols)
                {
                    this.symbols = new HashSet <string> (symbols);
                    var project = GetProject(doc);

                    if (project == null)
                    {
                        var ideDocument = IdeApp.Workbench.GetDocument(doc.FileName);
                        if (ideDocument != null)
                        {
                            project = ideDocument.Project;
                        }
                    }

                    if (project == null)
                    {
                        project = IdeApp.Workspace.GetProjectContainingFile(doc.FileName);
                    }

                    if (project != null)
                    {
                        var configuration = project.GetConfiguration(IdeApp.Workspace.ActiveConfiguration) as DotNetProjectConfiguration;
                        if (configuration != null)
                        {
                            var cparams = configuration.CompilationParameters as CSharpCompilerParameters;
                            if (cparams != null)
                            {
                                string[] syms = cparams.DefineSymbols.Split(';', ',', ' ', '\t');
                                foreach (string s in syms)
                                {
                                    string ss = s.Trim();
                                    if (ss.Length > 0 && !symbols.Contains(ss))
                                    {
                                        this.symbols.Add(ss);
                                    }
                                }
                            }
                            // Workaround for mcs defined symbol
                            if (configuration.TargetRuntime.RuntimeId == "Mono")
                            {
                                this.symbols.Add("__MonoCS__");
                            }
                        }
                        else
                        {
                            Console.WriteLine("NO CONFIGURATION");
                        }
                    }

/*					var parsedDocument = TypeSystemService.ParseFile (document.ProjectContent, doc.FileName, doc.MimeType, doc.Text);
 *                                      if (parsedDocument == null)
 *                                              parsedDocument = TypeSystemService.ParseFile (dom, doc.FileName ?? "a.cs", delegate { return doc.Text; });
 *                                      if (parsedDocument != null) {
 *                                              foreach (PreProcessorDefine define in parsedDocument.Defines) {
 *                                                      symbols.Add (define.Define);
 *                                              }
 *
 *                                      }*/
                }
		protected override void Run (object dataItem)
		{
			base.Run (dataItem);

			if (IdeApp.Workspace == null) return;
			if (IdeApp.Workbench.ActiveDocument == null || IdeApp.Workbench.ActiveDocument.FileName == FilePath.Null) return;

			var document = IdeApp.Workbench.ActiveDocument;

			ResolveResult resolveResult = null;
			object item = CurrentRefactoryOperationsHandler.GetItem (document, out resolveResult);

			IMethod method = item as IMethod;
			if (method == null)
				return;

			ISearchProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true, true);
			ThreadPool.QueueUserWorkItem((data) => 
			{
				try
				{
					ImplementationsFinder.Find(method, implementation =>
					{
						FileProvider fileProvider = new FileProvider(implementation.Region.FileName);
						TextDocument doc = new TextDocument();
						doc.Text = fileProvider.ReadString();
						int offset = doc.LocationToOffset(implementation.Region.BeginLine, implementation.Region.BeginColumn);
						while ((offset + implementation.Name.Length) < doc.TextLength)
						{
							if (doc.GetTextAt(offset, implementation.Name.Length) == implementation.Name)
							{
								break;
							}
							offset++;
						}

						monitor.ReportResult (new MonoDevelop.Ide.FindInFiles.SearchResult(fileProvider, offset, implementation.Name.Length));
					});
				}
				catch (Exception exception)
				{
					if (monitor != null)
					{
						monitor.ReportError("Error finding references", exception);
					}
					else
					{
						LoggingService.LogError("Error finding references", exception);
					}
				}
				finally
				{
					if (monitor != null)
					{
						monitor.Dispose();
					}
				}
			});
		}
		public SourceEditorPrintOperation (TextDocument doc, FilePath filename)
		{
			this.doc = doc;
			this.filename = filename;
			this.settings = SourceEditorPrintSettings.Load ();
			
			this.Unit = Unit.Mm;
		}
		static int GetNextOffset (TextDocument document, int lineNumber)
		{
			int startLineNumber = lineNumber + 1;
			if (startLineNumber > document.TextLength) 
				startLineNumber = 0;
			var line = document.GetLinesStartingAt (startLineNumber).FirstOrDefault (l => l.IsBookmarked);
			return line != null ? line.Offset : -1;
		}
		static int GetPrevOffset (TextDocument document, int lineNumber)
		{
			int startLineNumber = lineNumber - 1;
			if (startLineNumber < 0) 
				startLineNumber =  document.TextLength - 1;
			var line = document.GetLinesReverseStartingAt (startLineNumber - 1).FirstOrDefault (l => l.IsBookmarked);
			return line != null ? line.Offset : -1;
		}
		static List<string> GetList (TextDocument document, string name)
		{
			var mode = document.SyntaxMode as SyntaxMode;
			if (mode != null) {
				if (mode.Properties.ContainsKey(name)) 
					return mode.Properties[name];
			}
			return new List<string> ();
		}
Esempio n. 12
0
		public UrlMarker (TextDocument doc, DocumentLine line, string url, UrlType urlType, string style, int startColumn, int endColumn)
		{
			this.doc = doc;
			this.line = line;
			this.url = url;
			this.urlType = urlType;
			this.style = style;
			this.startColumn = startColumn;
			this.endColumn = endColumn;
			doc.LineChanged += HandleDocLineChanged;
		}
		public TextDocumentWrapper (TextDocument document)
		{
			if (document == null)
				throw new ArgumentNullException (nameof (document));
			this.document = document;
			this.document.TextReplaced += HandleTextReplaced;
			this.document.TextReplacing += HandleTextReplacing;
			this.document.LineChanged += Document_LineChanged; 
			this.document.LineInserted += Document_LineInserted;
			this.document.LineRemoved += Document_LineRemoved;
		}
		static int StartsWithListMember (TextDocument document, List<string> list, int offset)
		{
			for (int i = 0; i < list.Count; i++) {
				string item = list[i];
				if (offset + item.Length < document.TextLength) {
					if (document.GetTextAt (offset, item.Length) == item) 
						return i;
				}
			}
			return -1;
		}
		public void MatchingBracketTests (string text, int offset, int expectedOffsetMatch)
		{
			var editor = TextEditorFactory.CreateNewEditor ();
			editor.MimeType = "text/x-csharp";
			editor.Text = text;
			var document = new TextDocument (text);

			int actualOffset = SimpleBracketMatcher.GetMatchingBracketOffset (editor, offset);
			int actualOffset2 = document.GetMatchingBracketOffset (offset);

			Assert.AreEqual (actualOffset2, actualOffset);
			Assert.AreEqual (expectedOffsetMatch, actualOffset);
		}
		public override ParsedDocument Parse (bool storeAst, string fileName, System.IO.TextReader content, Projects.Project project = null)
		{
			currentDocument = openDocuments.FirstOrDefault (d => d != null && d.FileName == fileName);
			// We need document and project to be loaded to correctly initialize Razor Host.
			this.project = project as DotNetProject;
			if (this.project == null || (currentDocument == null && !TryAddDocument (fileName)))
				return new RazorCSharpParsedDocument (fileName, new RazorCSharpPageInfo ());

			this.aspProject = project as AspMvcProject;

			EnsureParserInitializedFor (fileName);

			var errors = new List<Error> ();

			using (var source = new SeekableTextReader (content)) {
				var textChange = CreateTextChange (source);
				var parseResult = editorParser.CheckForStructureChanges (textChange);
				if (parseResult == PartialParseResult.Rejected) {
					parseComplete.WaitOne ();
					if (!capturedArgs.GeneratorResults.Success)
						GetRazorErrors (errors);
				}
			}

			CreateHtmlDocument ();
			GetHtmlErrors (errors);
			CreateCSharpParsedDocument ();
			ClearLastChange ();

			RazorHostKind kind = RazorHostKind.WebPage;
			if (editorParser.Host is WebCodeRazorHost) {
				kind = RazorHostKind.WebCode;
			} else if (editorParser.Host is MonoDevelop.RazorGenerator.RazorHost) {
				kind = RazorHostKind.Template;
			}

			var pageInfo = new RazorCSharpPageInfo () {
				HtmlRoot = htmlParsedDocument,
				GeneratorResults = capturedArgs.GeneratorResults,
				Spans = editorParser.CurrentParseTree.Flatten (),
				CSharpParsedFile = parsedCodeFile,
				CSharpCode = csharpCode,
				Errors = errors,
				FoldingRegions = GetFoldingRegions (),
				Comments = comments,
				Compilation = CreateCompilation (),
				HostKind = kind,
			};

			return new RazorCSharpParsedDocument (fileName, pageInfo);
		}
Esempio n. 17
0
        static string StripDoubleBlankLines(string content)
        {
            var doc = new Mono.TextEditor.TextDocument(content);

            for (int i = 1; i + 1 <= doc.LineCount; i++)
            {
                if (IsBlankLine(doc, i) && IsBlankLine(doc, i + 1))
                {
                    doc.Remove(doc.GetLine(i).SegmentIncludingDelimiter);
                    i--;
                    continue;
                }
            }
            return(doc.Text);
        }
		int FindPrevWordOffset (TextDocument doc, int offset, bool subword)
		{
			int lineNumber = doc.OffsetToLineNumber (offset);
			DocumentLine line = doc.GetLine (lineNumber);
			if (line == null)
				return offset;
			
			int result = offset;
			if (result == line.Offset) {
				line = doc.GetLine (lineNumber - 1);
				if (line != null)
					result = line.Offset + line.Length;
				return result;
			}
			
			CharacterClass current = GetCharacterClass (doc.GetCharAt (result - 1), subword, false);
			
			if (current == CharacterClass.Whitespace && result - 1 > line.Offset) {
				result--;
				current = GetCharacterClass (doc.GetCharAt (result - 2), subword, false);
			}
			
			while (result > line.Offset) {
				CharacterClass prev = GetCharacterClass (doc.GetCharAt (result - 1), subword, false);
				if (prev != current) {
					
					// camelCase and PascalCase handling
					bool camelSkip = false;
					if (prev == CharacterClass.UppercaseLetter && current == CharacterClass.LowercaseLetter) {
						if (result-2 > line.Offset) {
							CharacterClass back2 = GetCharacterClass (doc.GetCharAt (result-2), subword, false);
							if (back2 == CharacterClass.UppercaseLetter)
								result--;
							else
								camelSkip = true;
						}
					}
					
					if (!camelSkip)
						break;
				}
				
				current = prev;
				result--;
			}
			
			return result;
		}
Esempio n. 19
0
		public JaySyntaxMode (TextDocument doc) : base (doc)
		{
			ResourceXmlProvider provider = new ResourceXmlProvider (typeof(IXmlProvider).Assembly, typeof(IXmlProvider).Assembly.GetManifestResourceNames ().First (s => s.Contains ("JaySyntaxMode")));
			using (XmlReader reader = provider.Open ()) {
				SyntaxMode baseMode = SyntaxMode.Read (reader);
				this.rules = new List<Rule> (baseMode.Rules);
				this.keywords = new List<Keywords> (baseMode.Keywords);
				this.spans = new List<Span> (baseMode.Spans).ToArray ();
				this.matches = baseMode.Matches;
				this.prevMarker = baseMode.PrevMarker;
				this.SemanticRules = new List<SemanticRule> (baseMode.SemanticRules);
				this.keywordTable = baseMode.keywordTable;
				this.keywordTableIgnoreCase = baseMode.keywordTableIgnoreCase;
				this.properties = baseMode.Properties;
			}
		}
		int FindNextWordOffset (TextDocument doc, int offset, bool subword)
		{
			int lineNumber   = doc.OffsetToLineNumber (offset);
			DocumentLine line = doc.GetLine (lineNumber);
			if (line == null)
				return offset;
			
			int result    = offset;
			int endOffset = line.Offset + line.Length;
			if (result == endOffset) {
				line = doc.GetLine (lineNumber + 1);
				if (line != null)
					result = line.Offset;
				return result;
			}
			
			CharacterClass current = GetCharacterClass (doc.GetCharAt (result), subword, false);
			while (result < endOffset) {
				CharacterClass next = GetCharacterClass (doc.GetCharAt (result), subword, false);
				if (next != current) {
					
					// camelCase and PascalCase handling
					bool camelSkip = false;
					if (next == CharacterClass.LowercaseLetter && current == CharacterClass.UppercaseLetter) {
						if (result-2 > line.Offset) {
							CharacterClass previous = GetCharacterClass (doc.GetCharAt (result-2), subword, false);
							if (previous == CharacterClass.UppercaseLetter && result-2 > offset)
								result--;
							else
								camelSkip = true;
						}
					}
					
					if (!camelSkip)
						break;
				}
				
				current = next;		
				result++;
			}
			while (result < endOffset && GetCharacterClass (doc.GetCharAt (result), subword, false) == CharacterClass.Whitespace) {
				result++;
			}
			return result;
		}
		int FindNextWordOffset (TextDocument doc, int offset, bool subword)
		{
			if (offset + 1 >= doc.TextLength)
				return doc.TextLength;
			int result = offset + 1;
			CC previous = SW.GetCharacterClass (doc.GetCharAt (result), subword, includeUnderscore);
			bool inIndentifier = previous != CC.Unknown && previous != CC.Whitespace;			
			while (result < doc.TextLength) {
				char ch = doc.GetCharAt (result);
				CC current = SW.GetCharacterClass (ch, subword, includeUnderscore);
				
				//camelCase / PascalCase splitting
				if (subword) {
					if (current == CC.Digit && (previous != CC.Digit || (result-1 == offset && !Char.IsDigit (doc.GetCharAt (result-1))))) {
						break;
					} else if (previous == CC.Digit && current != CC.Digit) {
						break;
					} else if (current == CC.UppercaseLetter && previous != CC.UppercaseLetter) {
						break;
					} else if (current == CC.LowercaseLetter && previous == CC.UppercaseLetter && result - 2 > 0
					           && SW.GetCharacterClass (doc.GetCharAt (result - 2), subword, includeUnderscore) != CC.LowercaseLetter)
					{
						result--;
						break;
					}
				}
				
				//else break at end of identifiers
				if (previous != CC.Unknown && previous != CC.Whitespace) {
					inIndentifier = true;
				} else if (inIndentifier) {
					result--;
					break;
				}
				previous = current;
				result++;
			}
			foreach (FoldSegment segment in doc.GetFoldingsFromOffset (result)) {
				if (segment.IsFolded)
					result = System.Math.Max (result, segment.EndLine.Offset + segment.EndColumn);
			}
			return result;
		}
    void SetDiffCellData (Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
    {
        try
        {
            CellRendererDiff cellRendererDiff = (CellRendererDiff)cell;
            Change change = store.GetValue (iter, objColumn) as Change;
            cellRendererDiff.Visible = !(bool)store.GetValue (iter, statusVisibleColumn);
            if (change == null || !cellRendererDiff.Visible)
            {
                cellRendererDiff.InitCell (treeviewPreview, false, "", "");
                return;
            }
            TextReplaceChange replaceChange = change as TextReplaceChange;
            if (replaceChange == null)
                return;

            var openDocument = IdeApp.Workbench.GetDocument (replaceChange.FileName);
            Mono.TextEditor.TextDocument originalDocument = new Mono.TextEditor.TextDocument ();
            originalDocument.FileName = replaceChange.FileName;
            if (openDocument == null)
            {
                originalDocument.Text = Mono.TextEditor.Utils.TextFileUtility.ReadAllText (replaceChange.FileName);
            }
            else
            {
                originalDocument.Text = openDocument.Editor.Document.Text;
            }

            Mono.TextEditor.TextDocument changedDocument = new Mono.TextEditor.TextDocument ();
            changedDocument.FileName = replaceChange.FileName;
            changedDocument.Text = originalDocument.Text;

            changedDocument.Replace (replaceChange.Offset, replaceChange.RemovedChars, replaceChange.InsertedText);

            string diffString = Mono.TextEditor.Utils.Diff.GetDiffString (originalDocument, changedDocument);

            cellRendererDiff.InitCell (treeviewPreview, true, diffString, replaceChange.FileName);
        }
        catch (Exception e)
        {
            Console.WriteLine (e);
        }
    }
Esempio n. 23
0
        static string StripHeader(string content)
        {
            var doc = new Mono.TextEditor.TextDocument(content);

            while (true)
            {
                string lineText = doc.GetLineText(1);
                if (lineText == null)
                {
                    break;
                }
                if (lineText.StartsWith("//"))
                {
                    doc.Remove(doc.GetLine(1).SegmentIncludingDelimiter);
                    continue;
                }
                break;
            }
            return(doc.Text);
        }
Esempio n. 24
0
			public override void Analyze(TextDocument doc, DocumentLine line, Chunk startChunk, int startOffset, int endOffset)
			{
				// Check line start
				int o = line.Offset;
				char c = '\0';
				for (; o < line.EndOffset && char.IsWhiteSpace(c = doc.GetCharAt(o)); o++) ;

				if (c != '-' && c != '#')
					return;

				DSyntax.Document = doc;
				var spanParser = new SpanParser(DSyntax, new CloneableStack<Span>());
				var chunkP = new ChunkParser(DSyntax, spanParser, Ide.IdeApp.Workbench.ActiveDocument.Editor.ColorStyle, line);

				var n = chunkP.GetChunks(startOffset, endOffset - startOffset);
				if (n == null)
					return;
				startChunk.Next = n;
				startChunk.Length = n.Offset - startChunk.Offset;
			}
Esempio n. 25
0
		public override void Analyze (TextDocument doc, DocumentLine line, Chunk startChunk, int startOffset, int endOffset)
		{
			if (endOffset <= startOffset || startOffset >= doc.TextLength || inUpdate)
				return;
			inUpdate = true;
			try {
				string text = doc.GetTextAt (startOffset, endOffset - startOffset);
				int startColumn = startOffset - line.Offset;
				var markers = new List <UrlMarker> (line.Markers.Where (m => m is UrlMarker).Cast<UrlMarker> ());
				markers.ForEach (m => doc.RemoveMarker (m, false));
				foreach (System.Text.RegularExpressions.Match m in UrlRegex.Matches (text)) {
					doc.AddMarker (line, new UrlMarker (doc, line, m.Value, UrlType.Url, syntax, startColumn + m.Index, startColumn + m.Index + m.Length), false);
				}
				foreach (System.Text.RegularExpressions.Match m in MailRegex.Matches (text)) {
					doc.AddMarker (line, new UrlMarker (doc, line, m.Value, UrlType.Email, syntax, startColumn + m.Index, startColumn + m.Index + m.Length), false);
				}
			} finally {
				inUpdate = false;
			}
		}
Esempio n. 26
0
        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)
            });
        }
Esempio n. 27
0
		public override void Analyze (TextDocument doc, DocumentLine line, Chunk startChunk, int startOffset, int endOffset)
		{
			if (endOffset <= startOffset || startOffset >= doc.TextLength || inUpdate)
				return;
			if (startChunk.Style != Highlighting.ColorScheme.CommentsSingleLineKey && startChunk.Style != Highlighting.ColorScheme.CommentsBlockKey)
				return;
			inUpdate = true;
			try {
				string text = doc.GetTextAt (startOffset, System.Math.Min (endOffset, doc.TextLength) - startOffset);
				int startColumn = startOffset - line.Offset;
				var markers = new List <UrlMarker> (line.Markers.OfType<UrlMarker> ());
				markers.ForEach (m => doc.RemoveMarker (m, false));
				foreach (System.Text.RegularExpressions.Match m in UrlRegex.Matches (text)) {
					doc.AddMarker (line, new UrlMarker (doc, line, m.Value, UrlType.Url, syntax, startColumn + m.Index, startColumn + m.Index + m.Length), false);
				}
				foreach (System.Text.RegularExpressions.Match m in MailRegex.Matches (text)) {
					doc.AddMarker (line, new UrlMarker (doc, line, m.Value, UrlType.Email, syntax, startColumn + m.Index, startColumn + m.Index + m.Length), false);
				}
			} finally {
				inUpdate = false;
			}
		}
Esempio n. 28
0
			public override System.IO.Stream CreateFileContent(SolutionItem policyParent, Project project, string language, string fileName, string identifier)
			{
				if (Outer.FormatCode)
				{
					return base.CreateFileContent(policyParent, project, language, fileName, identifier);
				}

				var model = GetTagModel (policyParent, project, language, identifier, fileName);
				string text = CreateContent (project, model.OverrideTags, language);

				text = ProcessContent (text, model);
				var memoryStream = new MemoryStream ();
				byte[] preamble = Encoding.UTF8.GetPreamble ();
				memoryStream.Write (preamble, 0, preamble.Length);
				if (AddStandardHeader) {
					string header = StandardHeaderService.GetHeader (policyParent, fileName, true);
					byte[] bytes = Encoding.UTF8.GetBytes (header);
					memoryStream.Write (bytes, 0, bytes.Length);
				}

				var textDocument = new TextDocument ();
				textDocument.Text = text;
				var textStylePolicy = (policyParent == null) ? PolicyService.GetDefaultPolicy<TextStylePolicy> ("text/plain") : policyParent.Policies.Get<TextStylePolicy> ("text/plain");
				string eolMarker = TextStylePolicy.GetEolMarker (textStylePolicy.EolMarker);
				byte[] eol = Encoding.UTF8.GetBytes (eolMarker);
				string indent = (!textStylePolicy.TabsToSpaces) ? null : new string (' ', textStylePolicy.TabWidth);
				foreach (DocumentLine current in textDocument.Lines) {
					string line = textDocument.GetTextAt (current.Offset, current.Length);
					if (indent != null) {
						line = line.Replace ("	", indent);
					}
					byte[] bytes = Encoding.UTF8.GetBytes (line);
					memoryStream.Write (bytes, 0, bytes.Length);
					memoryStream.Write (eol, 0, eol.Length);
				}
				memoryStream.Position = 0;
				return memoryStream;				
			}
Esempio n. 29
0
        public static int FindNextSubwordEndOffset(TextDocument doc, int offset)
        {
            int myoffset = offset + 1;

            if (!OffsetIsWithinBounds (doc, myoffset)) {
                return myoffset;
            }

            char c = doc.GetCharAt (myoffset);
            // skip whitespace
            while (char.IsWhiteSpace (c)) {
                if (OffsetIsWithinBounds (doc, ++myoffset)) {
                    c = doc.GetCharAt (myoffset);
                } else {
                    return offset;
                }
            }
            var initialClass = ViWordFindStrategy.GetCharacterClass (c);
            while (ViWordFindStrategy.GetCharacterClass (c) == initialClass && 0 <= myoffset && doc.TextLength-1 > myoffset) {
                c = doc.GetCharAt (++myoffset);
            }

            return System.Math.Max (offset, myoffset - 1);
        }
Esempio n. 30
0
        public static int FindNextWordEndOffset(TextDocument doc, int offset)
        {
            int myoffset = offset + 1;

            if (!OffsetIsWithinBounds (doc, myoffset)) {
                return myoffset;
            }

            char c = doc.GetCharAt (myoffset);
            // skip whitespace
            while (char.IsWhiteSpace (c)) {
                if (OffsetIsWithinBounds (doc, ++myoffset)) {
                    c = doc.GetCharAt (myoffset);
                } else {
                    return offset;
                }
            }

            while (!char.IsWhiteSpace (c) && 0 <= myoffset && doc.TextLength-1 > myoffset) {
                c = doc.GetCharAt (++myoffset);
            }

            return System.Math.Max (offset, myoffset - 1);
        }
 public ExtensibleTextEditor(SourceEditorView view, ISourceEditorOptions options, Mono.TextEditor.TextDocument doc) : base(doc, options)
 {
     Initialize(view);
 }
        static IEnumerable <KeyValuePair <char, int> > GetTextWithoutCommentsAndStrings(Mono.TextEditor.TextDocument doc, int start, int end)
        {
            bool isInString = false, isInChar = false;
            bool isInLineComment = false, isInBlockComment = false;

            for (int pos = start; pos < end; pos++)
            {
                char ch = doc.GetCharAt(pos);
                switch (ch)
                {
                case '\r':
                case '\n':
                    isInLineComment = false;
                    break;

                case '/':
                    if (isInBlockComment)
                    {
                        if (pos > 0 && doc.GetCharAt(pos - 1) == '*')
                        {
                            isInBlockComment = false;
                        }
                    }
                    else if (!isInString && !isInChar && pos + 1 < doc.TextLength)
                    {
                        char nextChar = doc.GetCharAt(pos + 1);
                        if (nextChar == '/')
                        {
                            isInLineComment = true;
                        }
                        if (!isInLineComment && nextChar == '*')
                        {
                            isInBlockComment = true;
                        }
                    }
                    break;

                case '"':
                    if (!(isInChar || isInLineComment || isInBlockComment))
                    {
                        isInString = !isInString;
                    }
                    break;

                case '\'':
                    if (!(isInString || isInLineComment || isInBlockComment))
                    {
                        isInChar = !isInChar;
                    }
                    break;

                default:
                    if (!(isInString || isInChar || isInLineComment || isInBlockComment))
                    {
                        yield return(new KeyValuePair <char, int> (ch, pos));
                    }
                    break;
                }
            }
        }
Esempio n. 33
0
		static MonoDevelop.Ide.FindInFiles.SearchResult GetJumpTypePartSearchResult (IUnresolvedTypeDefinition part)
		{
			var provider = new MonoDevelop.Ide.FindInFiles.FileProvider (part.Region.FileName);
			var doc = new Mono.TextEditor.TextDocument ();
			doc.Text = provider.ReadString ();
			int position = doc.LocationToOffset (part.Region.BeginLine, part.Region.BeginColumn);
			while (position + part.Name.Length < doc.TextLength) {
				if (doc.GetTextAt (position, part.Name.Length) == part.Name)
					break;
				position++;
			}
			return new MonoDevelop.Ide.FindInFiles.SearchResult (provider, position, part.Name.Length);
		}
Esempio n. 34
0
		/// <summary>
		/// This method gets the line indentation.
		/// </summary>
		/// <param name="doc">
		/// The <see cref="Document"/> the line belongs to.
		/// </param>
		/// <returns>
		/// The indentation of the line (all whitespace chars up to the first non ws char).
		/// </returns>
		public string GetIndentation (TextDocument doc)
		{
			var result = new StringBuilder ();
			int offset = Offset;
			int max = System.Math.Min (offset + LengthIncludingDelimiter, doc.TextLength);
			for (int i = offset; i < max; i++) {
				char ch = doc.GetCharAt (i);
				if (ch != ' ' && ch != '\t')
					break;
				result.Append (ch);
			}
			return result.ToString ();
		}
Esempio n. 35
0
		public void SetDocument (TextDocument doc)
		{
			line = column = 1;
			offsetVersion = doc.Version;
			caretOffset = 0;
		}
Esempio n. 36
0
		void UnderLineError (Document doc, Error info)
		{
			var line = doc.GetLine (info.Region.BeginLine);
			// If the line is already underlined
			if (errors.Any (em => em.LineSegment == line))
				return;
			ErrorMarker error = new ErrorMarker (textEditor.Document, info, line);
			errors.Add (error);
			doc.AddMarker (line, error);
		}
Esempio n. 37
0
		void RemoveErrorUnderlines (Document doc)
		{
			errors.ForEach (err => doc.RemoveMarker (err));
			errors.Clear ();
		}
Esempio n. 38
0
		public ErrorMarker (TextDocument doc, Error info, DocumentLine line)
		{
			Info = info;
			LineSegment = line;
			// may be null if no line is assigned to the error.
			Wave = true;
			
			StartCol = Info.Region.BeginColumn;
			if (line != null) {
				var startOffset = line.Offset;
				if (startOffset + StartCol - 1 >= 0) {
					while (StartCol < line.Length) {
						char ch = doc.GetCharAt (startOffset + StartCol - 1);
						if (!char.IsWhiteSpace (ch))
							break;
						StartCol++;
					}
				}
			}

			if (Info.Region.EndColumn > StartCol) {
				EndCol = Info.Region.EndColumn;
			} else {
				if (line == null) {
					EndCol = StartCol + 1;
					return;
				}
				var start = line.Offset + StartCol - 1;
				int o = start + 1;
				while (o < line.EndOffset) {
					char ch = doc.GetCharAt (o);
					if (!(char.IsLetterOrDigit (ch) || ch == '_'))
						break;
					o++;
				}
				EndCol = Info.Region.BeginColumn + o - start + 1;
			}
		}
Esempio n. 39
0
		static InsertionPoint GetInsertionPosition (TextDocument doc, int line, int column)
		{
			int bodyEndOffset = doc.LocationToOffset (line, column) + 1;
			DocumentLine curLine = doc.GetLine (line);
			if (curLine != null) {
				if (bodyEndOffset < curLine.Offset + curLine.Length) {
					// case1: positition is somewhere inside the start line
					return new InsertionPoint (new DocumentLocation (line, column + 1), NewLineInsertion.Eol, NewLineInsertion.BlankLine);
				}
			}
			
			// -> if position is at line end check next line
			DocumentLine nextLine = doc.GetLine (line + 1);
			if (nextLine == null) // check for 1 line case.
				return new InsertionPoint (new DocumentLocation (line, column + 1), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine);
			
			for (int i = nextLine.Offset; i < nextLine.Offset + nextLine.Length; i++) {
				char ch = doc.GetCharAt (i);
				if (!char.IsWhiteSpace (ch)) {
					// case2: next line contains non ws chars.
					return new InsertionPoint (new DocumentLocation (line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.BlankLine);
				}
			}
			// case3: whitespace line
			return new InsertionPoint (new DocumentLocation (line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.None);
		}
Esempio n. 40
0
		static void CheckStartPoint (TextDocument doc, InsertionPoint point, bool isEndPoint)
		{
			DocumentLine line = doc.GetLine (point.Location.Line);
			if (line == null)
				return;
			if (doc.GetLineIndent (line).Length + 1 == point.Location.Column) {
				int lineNr = point.Location.Line;
				while (lineNr > 1 && doc.GetLineIndent (lineNr - 1).Length == doc.GetLine (lineNr - 1).Length) {
					lineNr--;
				}
				line = doc.GetLine (lineNr);
				point.Location = new DocumentLocation (lineNr, doc.GetLineIndent (line).Length + 1);
			}
			
			if (doc.GetLineIndent (line).Length + 1 < point.Location.Column)
				point.LineBefore = NewLineInsertion.Eol;
			if (point.Location.Column < line.Length + 1)
				point.LineAfter = isEndPoint ? NewLineInsertion.Eol : NewLineInsertion.BlankLine;
		}
 public HiddenTextEditorViewContent()
 {
     document = new Mono.TextEditor.TextDocument();
     data     = new Mono.TextEditor.TextEditorData(document);
     Name     = "";
 }
Esempio n. 42
0
 public DocAdapt(Mono.TextEditor.TextDocument doc)
 {
     this.doc = doc;
 }
Esempio n. 43
0
 public TestViewContent()
 {
     document = new Mono.TextEditor.TextDocument();
     data     = new TextEditorData(document);
     Name     = "";
 }