public static ResolveResult GetResolveResult (MonoDevelop.Ide.Gui.Document doc)
		{
			ITextEditorResolver textEditorResolver = doc.GetContent<ITextEditorResolver> ();
			if (textEditorResolver != null)
				return textEditorResolver.GetLanguageItem (doc.Editor.Caret.Offset);
			return null;
		}
Ejemplo n.º 2
0
        public static EditorData GetEditorData(MonoDevelop.Ide.Gui.Document doc = null)
        {
            var ed = new EditorData();

            if (doc == null)
                doc = IdeApp.Workbench.ActiveDocument;

            if (doc == null ||
                doc.FileName == FilePath.Null)
                return null;

            var editor = doc.GetContent<ITextBuffer>();
            if (editor == null)
                return null;

            int line, column;
            editor.GetLineColumnFromPosition(editor.CursorPosition, out line, out column);
            ed.CaretLocation = new CodeLocation(column, line);
            ed.CaretOffset = editor.CursorPosition;

            var ast = doc.ParsedDocument as ParsedDModule;
            if(ast==null)
                return null;

            ed.SyntaxTree = ast.DDom as DModule;
            ed.ModuleCode = editor.Text;

            if (ed.SyntaxTree == null)
                return null;

            var Project = doc.Project as DProject;
            // Encapsule editor data for resolving
            ed.ParseCache = Project != null ?
                Project.ParseCache :
                ParseCacheList.Create(DCompilerService.Instance.GetDefaultCompiler().ParseCache);

            return ed;
        }
Ejemplo n.º 3
0
		public static void QueueQuickFixAnalysis (MonoDevelop.Ide.Gui.Document doc, DomLocation loc, Action<List<ContextAction>> callback)
		{
			System.Threading.ThreadPool.QueueUserWorkItem (delegate {
				try {
					string disabledNodes = PropertyService.Get ("ContextActions." + doc.Editor.Document.MimeType, "") ?? "";
					
					var availableFixes = new List<ContextAction> (contextActions.Where (fix => disabledNodes.IndexOf (fix.Type.FullName) < 0 && fix.Action.IsValid (doc, loc)).Select (fix => fix.Action));
					var ext = doc.GetContent<MonoDevelop.AnalysisCore.Gui.ResultsEditorExtension> ();
					if (ext != null) {
						foreach (var result in ext.GetResultsAtOffset (doc.Editor.LocationToOffset (loc.Line, loc.Column))) {
							var fresult = result as FixableResult;
							if (fresult == null)
								continue;
							foreach (var action in FixOperationsHandler.GetActions (doc, fresult)) {
								availableFixes.Add (new AnalysisContextAction (result, action));
							}
						}
					}
					
					callback (availableFixes);
				} catch (Exception ex) {
					LoggingService.LogError ("Error in analysis service", ex);
				}
			});
		}	
Ejemplo n.º 4
0
		string GetTextWithDirective (MonoDevelop.Ide.Gui.Document document, bool insertDirective)
		{
			string tag = Text;
			
			if (!tag.Contains ("{0}"))
				return tag;
			
			if (Type.AssemblyName.StartsWith ("System.Web.UI.WebControls", StringComparison.Ordinal))
				return string.Format (tag, "asp");
			
			//register the assembly and look up the class
			//FIXME: only do this on the insert, not the preview - or remove it afterwards
			RegisterReference (document.Project);
			
			var database = document.Compilation;
			
			var cls = database.FindType (Type.Load ());
			if (cls == null)
				return tag;

			var ed = document.GetContent<WebFormsEditorExtension> ();
			if (ed == null)
				return tag;

			var assemName = SystemAssemblyService.ParseAssemblyName (Type.AssemblyName);

			WebFormsPageInfo.RegisterDirective directive;
			string prefix = ed.ReferenceManager.GetTagPrefixWithNewDirective (cls, assemName.Name, null, out directive);
			
			if (prefix == null)
				return tag;
			
			tag = string.Format (tag, prefix);
			
			if (directive != null && insertDirective)
				ed.ReferenceManager.AddRegisterDirective (directive, document.Editor, true);
			
			return tag;
		}
		internal static HighlightUsagesExtension GetHighlightUsageExtension (MonoDevelop.Ide.Gui.Document doc)
		{
			return doc.GetContent <HighlightUsagesExtension> ();
		}
Ejemplo n.º 6
0
		public static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, MonoDevelop.Ide.Gui.Document data, int startOffset, int endOffset)
		{
			if (data.ParsedDocument == null)
				return;
			var ext = data.GetContent<CSharpCompletionTextEditorExtension> ();
			if (ext == null)
				return;
			var seg = ext.typeSystemSegmentTree.GetMemberSegmentAt (startOffset);
			if (seg == null)
				return;
			var member = seg.Entity;
			if (member == null || member.Region.IsEmpty || member.BodyRegion.End.IsEmpty)
				return;
			
			// Build stub
			int formatStartOffset;
			var text = BuildStub (data, seg, endOffset, out formatStartOffset);
			int formatLength = endOffset - seg.Offset;
			// Get changes from formatting visitor
			var changes = GetFormattingChanges (policyParent, mimeTypeChain, data, text);
			if (changes == null)
				return;

			// Do the actual formatting
//			var originalVersion = data.Editor.Document.Version;
			int caretOffset = data.Editor.Caret.Offset;

			int realTextDelta = seg.Offset - formatStartOffset;
			int startDelta = 1;
			using (var undo = data.Editor.OpenUndoGroup ()) {
				try {
					changes.ApplyChanges (formatStartOffset + startDelta, Math.Max (0, formatLength - startDelta - 1), delegate (int replaceOffset, int replaceLength, string insertText) {
						int translatedOffset = realTextDelta + replaceOffset;
						data.Editor.Document.CommitLineUpdate (data.Editor.OffsetToLineNumber (translatedOffset));
						data.Editor.Replace (translatedOffset, replaceLength, insertText);
					}, (replaceOffset, replaceLength, insertText) => {
						int translatedOffset = realTextDelta + replaceOffset;
						if (translatedOffset < 0 || translatedOffset + replaceLength > data.Editor.Length)
							return true;
						return data.Editor.GetTextAt (translatedOffset, replaceLength) == insertText;
					});
				} catch (Exception e) {
					LoggingService.LogError ("Error in on the fly formatter", e);
				}

//				var currentVersion = data.Editor.Document.Version;
//				data.Editor.Caret.Offset = originalVersion.MoveOffsetTo (currentVersion, caretOffset, ICSharpCode.NRefactory.Editor.AnchorMovementType.Default);
			}
		}
Ejemplo n.º 7
0
		public void Insert (MonoDevelop.Ide.Gui.Document document)
		{
			var handler = document.GetContent<ICodeTemplateHandler> ();
			if (handler != null) {
				handler.InsertTemplate (this, document);
			} else {
				InsertTemplateContents (document);
			}	
		}
Ejemplo n.º 8
0
		public static void QueueQuickFixAnalysis (MonoDevelop.Ide.Gui.Document doc, TextLocation loc, Action<List<MonoDevelop.CodeActions.CodeAction>> callback)
		{
			System.Threading.ThreadPool.QueueUserWorkItem (delegate {
				try {
					var result = new List<MonoDevelop.CodeActions.CodeAction> ();

					var ext = doc.GetContent<MonoDevelop.AnalysisCore.Gui.ResultsEditorExtension> ();
					if (ext != null) {
						foreach (var r in ext.GetResultsAtOffset (doc.Editor.LocationToOffset (loc)).OrderBy (r => r.Level)) {
							var fresult = r as FixableResult;
							if (fresult == null)
								continue;
							foreach (var action in FixOperationsHandler.GetActions (doc, fresult)) {
								result.Add (new AnalysisContextActionProvider.AnalysisCodeAction (action, r));
							}
						}
					}
					result.AddRange (GetValidActions (doc, loc).Result);
					callback (result);
				} catch (Exception ex) {
					LoggingService.LogError ("Error in analysis service", ex);
				}
			});
		}	
		public override bool ExtendsEditor (MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
		{
			//can only attach if there is not already an attached BaseXmlEditorExtension
			return doc.GetContent<BaseXmlEditorExtension> () == null;
		}
Ejemplo n.º 10
0
		public static void QueueQuickFixAnalysis (MonoDevelop.Ide.Gui.Document doc, TextLocation loc, CancellationToken token, Action<List<MonoDevelop.CodeActions.CodeAction>> callback)
		{
			var ext = doc.GetContent<MonoDevelop.AnalysisCore.Gui.ResultsEditorExtension> ();
			var issues = ext != null ? ext.GetResultsAtOffset (doc.Editor.LocationToOffset (loc), token).OrderBy (r => r.Level).ToList () : new List<Result> ();

			ThreadPool.QueueUserWorkItem (delegate {
				try {
					var result = new List<MonoDevelop.CodeActions.CodeAction> ();
					foreach (var r in issues) {
						if (token.IsCancellationRequested)
							return;
						var fresult = r as FixableResult;
						if (fresult == null)
							continue;
						foreach (var action in FixOperationsHandler.GetActions (doc, fresult)) {
							result.Add (new AnalysisContextActionProvider.AnalysisCodeAction (action, r) {
								DocumentRegion = action.DocumentRegion
							});
						}
					}
					result.AddRange (GetValidActions (doc, loc).Result);
					callback (result);
				} catch (Exception ex) {
					LoggingService.LogError ("Error in analysis service", ex);
				}
			});
		}