public override bool TryFix(ConstructFixer fixer, SyntaxNode syntaxTree, Ide.Gui.Document document, int location, ref int newOffset) { foreach (var breakStatementSyntax in syntaxTree.FindToken(location).Parent.AncestorsAndSelf().OfType <BreakStatementSyntax> ()) { if (breakStatementSyntax.SemicolonToken.IsMissing) { var insertionOffset = breakStatementSyntax.Span.End - 1; newOffset = insertionOffset; newOffset++; document.Editor.InsertText(insertionOffset, ";"); return(true); } } foreach (var breakStatementSyntax in syntaxTree.FindToken(location).Parent.AncestorsAndSelf().OfType <ContinueStatementSyntax> ()) { if (breakStatementSyntax.SemicolonToken.IsMissing) { var insertionOffset = breakStatementSyntax.Span.End - 1; newOffset = insertionOffset; newOffset++; document.Editor.InsertText(insertionOffset, ";"); return(true); } } return(false); }
internal static async Task <List <TextLink> > GetTextLinksAsync(Ide.Gui.Document doc, int caretOffset, ISymbol symbol) { var links = new List <TextLink> (); var link = new TextLink("name"); var documents = ImmutableHashSet.Create(doc.DocumentContext.AnalysisDocument); foreach (var loc in symbol.Locations) { if (loc.IsInSource && FilePath.PathComparer.Equals(loc.SourceTree.FilePath, doc.FileName)) { link.AddLink(new TextSegment(loc.SourceSpan.Start, loc.SourceSpan.Length)); } } foreach (var mref in await SymbolFinder.FindReferencesAsync(symbol, doc.DocumentContext.AnalysisDocument.Project.Solution, documents, default(CancellationToken))) { foreach (var loc in mref.Locations) { var span = loc.Location.SourceSpan; var segment = new TextSegment(span.Start, span.Length); if (segment.Offset <= caretOffset && caretOffset <= segment.EndOffset) { link.Links.Insert(0, segment); } else { link.AddLink(segment); } } } links.Add(link); return(links); }
public DocumentJitter() { IdeApp.Workbench.ActiveDocumentChanged += Workbench_ActiveDocumentChanged; doc = IdeApp.Workbench.ActiveDocument; //Update(); }
public override bool TryFix(ConstructFixer fixer, SyntaxNode syntaxTree, Ide.Gui.Document document, int location, ref int newOffset) { foreach (var invocationExpression in syntaxTree.FindToken(location).Parent.AncestorsAndSelf().OfType <InvocationExpressionSyntax> ()) { if (invocationExpression != null) { if (!invocationExpression.ArgumentList.OpenParenToken.IsMissing && invocationExpression.ArgumentList.CloseParenToken.IsMissing) { var insertionOffset = invocationExpression.Span.End - 1; newOffset = insertionOffset; var text = ")"; newOffset++; var expressionStatement = invocationExpression.Parent as ExpressionStatementSyntax; if (expressionStatement != null) { if (expressionStatement.SemicolonToken.IsMissing) { text = ");"; } newOffset++; } document.Editor.InsertText(insertionOffset, text); return(true); } } } return(false); }
static async Task <Tuple <CodeActionEditorExtension, Projects.Solution> > GatherFixesNoDispose <T> (string input, Action <ResultsEditorExtension, TaskCompletionSource <T> > callback, params int[] caretLocations) { await Ide.Composition.CompositionManager.InitializeAsync(); TestWorkbenchWindow tww = new TestWorkbenchWindow(); TestViewContent content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; var doc = new Ide.Gui.Document(tww); var text = input; content.Text = text; var project = Projects.Services.ProjectService.CreateProject("C#"); project.Name = "test"; project.FileName = "test.csproj"; project.Files.Add(new ProjectFile(content.ContentName, BuildAction.Compile)); var solution = new Projects.Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); content.Project = project; doc.SetProject(project); using (var monitor = new ProgressMonitor()) await TypeSystemService.Load(solution, monitor); var resultsExt = new ResultsEditorExtension(); resultsExt.Initialize(doc.Editor, doc); content.Contents.Add(resultsExt); var compExt = new CodeActionEditorExtension(); compExt.Initialize(doc.Editor, doc); content.Contents.Add(compExt); var tcs = new TaskCompletionSource <T> (); var cts = new CancellationTokenSource(); cts.CancelAfter(60 * 1000); cts.Token.Register(() => tcs.TrySetCanceled()); resultsExt.TasksUpdated += delegate { callback(resultsExt, tcs); }; await doc.UpdateParseDocument(); await Task.Run(() => tcs.Task); return(Tuple.Create(compExt, solution)); }
internal static async Task <ISymbol> GetSymbolAtCaret(Ide.Gui.Document doc, CancellationToken cancelToken = default) { if (doc == null || doc.Editor == null) { return(null); } var info = await RefactoringSymbolInfo.GetSymbolInfoAsync(doc.DocumentContext, doc.Editor, cancelToken); return(info.Symbol ?? info.DeclaredSymbol); }
internal static async Task <ISymbol> GetSymbolAtCaret(Ide.Gui.Document doc) { if (doc == null) { return(null); } var info = await RefactoringSymbolInfo.GetSymbolInfoAsync(doc, doc.Editor); return(info.Symbol ?? info.DeclaredSymbol); }
// CorrectIndenting is completely unused in the entire MonoDevelopment code environment - doesn't have to be implemented /// <summary> /// Used for formatting selected code /// </summary> public override void OnTheFlyFormat(Ide.Gui.Document _doc, int startOffset, int endOffset) { var doc = _doc.Editor.Document; DFormattingPolicy policy = null; TextStylePolicy textStyle = null; if (_doc.HasProject) { policy = _doc.Project.Policies.Get <DFormattingPolicy>(Indentation.DTextEditorIndentation.mimeTypes); textStyle = _doc.Project.Policies.Get <TextStylePolicy>(Indentation.DTextEditorIndentation.mimeTypes); } else { policy = PolicyService.GetDefaultPolicy <DFormattingPolicy> (Indentation.DTextEditorIndentation.mimeTypes); textStyle = PolicyService.GetDefaultPolicy <TextStylePolicy> (Indentation.DTextEditorIndentation.mimeTypes); } if (IndentCorrectionOnly) { using (doc.OpenUndoGroup()) using (var r = doc.CreateReader()) D_Parser.Formatting.Indent.IndentEngineWrapper.CorrectIndent(r, startOffset, endOffset, doc.Replace, policy.Options, new TextStyleAdapter(textStyle) { KeepAlignmentSpaces = policy.KeepAlignmentSpaces }); return; } var dpd = _doc.ParsedDocument as ParsedDModule; if (dpd == null) { return; } var formattingVisitor = new DFormattingVisitor(policy.Options, new DocAdapt(doc), dpd.DDom, new TextStyleAdapter(textStyle)); formattingVisitor.CheckFormattingBoundaries = true; var dl = doc.OffsetToLocation(startOffset); formattingVisitor.FormattingStartLocation = new CodeLocation(dl.Column, dl.Line); dl = doc.OffsetToLocation(endOffset); formattingVisitor.FormattingEndLocation = new CodeLocation(dl.Column, dl.Line); formattingVisitor.WalkThroughAst(); using (doc.OpenUndoGroup()) formattingVisitor.ApplyChanges(doc.Replace); }
protected bool TryGetDocument(out Document analysisDocument, out Ide.Gui.Document doc) { doc = IdeApp.Workbench.ActiveDocument; if (doc == null || doc.FileName == null || doc.Editor == null) { analysisDocument = null; return(false); } analysisDocument = doc.DocumentContext?.AnalysisDocument; return(doc != null); }
static Projects.Project DetermineRealProject(Ide.Gui.Document doc) { // try to search for a shared project var allProjects = IdeApp.Workspace.GetAllItems <SharedAssetsProject> (); var projects = new List <SharedAssetsProject> (allProjects.Where(p => p.IsFileInProject(doc.FileName))); if (projects.Count > 0) { return(projects [0]); } return(doc.Project); }
public override IEnumerable <CodeAction> GetActions(Ide.Gui.Document document, object refactoringContext, ICSharpCode.NRefactory.TextLocation loc, System.Threading.CancellationToken cancellationToken) { if (!DLanguageBinding.IsDFile(document.FileName)) { yield break; } var imports = GetSolutions(document); //it may be a bit too slow foreach (var i in imports) { yield return(new InnerAction(i)); } }
static async Task <RefactoringSymbolInfo> GetNamedTypeAtCaret(Ide.Gui.Document doc) { if (doc == null) { return(null); } var info = await RefactoringSymbolInfo.GetSymbolInfoAsync(doc, doc.Editor); if (info.Node?.Parent.IsKind(SyntaxKind.SimpleBaseType) != true) { return(null); } return(info); }
/// <summary> /// Looks for open documents that are showing the detail for the service that is being removed and updates the content to show the gallery instead /// </summary> static void EnsureServiceDetailTabIsClosed(DotNetProject project, string serviceId) { Ide.Gui.Document view = null; var servicesView = LocateServiceView(project, out view); if (servicesView != null) { var docObject = view.GetDocumentObject(); var serviceNode = docObject as ConnectedServiceNode; if (serviceNode != null && serviceNode.Id == serviceId) { servicesView.UpdateContent(null); view.Window.SelectWindow(); } } }
public static CodeGenerator CreateGenerator(Ide.Gui.Document doc) { MimeTypeExtensionNode node; if (!generators.TryGetValue(doc.Editor.MimeType, out node)) { return(null); } var result = (CodeGenerator)node.CreateInstance(); result.UseSpaceIndent = doc.Editor.TabsToSpaces; result.EolMarker = doc.Editor.EolMarker; result.TabSize = doc.Editor.Options.TabSize; result.Compilation = doc.Compilation; return(result); }
internal static async Task Run(Ide.Gui.Document doc) { var selectionRange = doc.Editor.CaretOffset; var analysisDocument = doc.DocumentContext.AnalysisDocument; if (analysisDocument == null) { return; } var parsedDocument = await analysisDocument.GetSyntaxTreeAsync(); if (parsedDocument == null) { return; } var unit = parsedDocument.GetRoot(); if (unit == null) { return; } var selectionAnnotation = ExpandSelectionHandler.GetSelectionAnnotation(doc.Editor); if (selectionAnnotation.Stack.Count == 0) { return; } selectionAnnotation.Stack.Pop(); if (selectionAnnotation.Stack.Count > 0) { var node = selectionAnnotation.Stack.Peek(); doc.Editor.SetSelection(node.SpanStart, node.Span.End); } else { doc.Editor.ClearSelection(); } }
internal static async void Run(Ide.Gui.Document doc) { var selectionRange = doc.Editor.SelectionRange; var analysisDocument = doc.DocumentContext.AnalysisDocument; if (analysisDocument == null) { return; } var model = await analysisDocument.GetSemanticModelAsync(); if (model == null) { return; } var unit = model.SyntaxTree.GetRoot(); var node = unit.FindNode(Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(selectionRange.Offset, selectionRange.EndOffset)); if (node == null) { return; } if (doc.Editor.IsSomethingSelected) { while (node != null && ShrinkSelectionHandler.IsSelected(doc.Editor, node.Span)) { node = node.Parent; } } if (node != null) { var selectionAnnotation = GetSelectionAnnotation(doc.Editor); selectionAnnotation.Stack.Push(node); doc.Editor.SetSelection(node.SpanStart, node.Span.End); } }
public override void InsertCompletionText(CompletionListWindow window, ref KeyActions ka, Gdk.Key closeChar, char keyChar, Gdk.ModifierType modifier) { if (customCompletionText == null) { if (Node != null && !string.IsNullOrEmpty(Node.Name)) { base.InsertCompletionText(window, ref ka, closeChar, keyChar, modifier); } return; } Ide.Gui.Document guiDoc = null; var ed = window.CompletionWidget as SourceEditor.SourceEditorView; foreach (var gdoc in Ide.IdeApp.Workbench.Documents) { if (gdoc.Editor.Document == ed.Document) { guiDoc = gdoc; break; } } if (guiDoc == null) { return; } var f = new Formatting.DCodeFormatter(); var insertionOffset = window.CodeCompletionContext.TriggerOffset; ed.Document.Insert(insertionOffset, customCompletionText, ICSharpCode.NRefactory.Editor.AnchorMovementType.AfterInsertion); guiDoc.UpdateParseDocument(); f.OnTheFlyFormat(guiDoc, insertionOffset, insertionOffset + customCompletionText.Length); }
public FindMemberOverloadsHandler (Ide.Gui.Document doc, IMember entity) { this.doc = doc; this.entity = entity; }
public FindDerivedSymbolsHandler(Ide.Gui.Document doc, IMember entity) { //this.doc = doc; this.entity = entity; }
protected override void Format(TextEditor editor, Ide.Gui.Document document, int start, int end) { OnTheFlyFormatter.Format(editor, document, start, end); }
protected static async Task AssertExpectedCodeFixes(ExpectedCodeFixes expected, Ide.Gui.Document doc) { var fixes = await doc.GetContent <CodeActionEditorExtension> ().GetCurrentFixesAsync(CancellationToken.None); var fixActions = fixes.CodeFixActions.SelectMany(x => x.Fixes).OrderBy(f => f.Action.Message).ToArray(); Assert.AreEqual(expected.CodeFixData.Length, fixActions.Length); for (int j = 0; j < expected.CodeFixData.Length; ++j) { Assert.AreEqual(expected.CodeFixData [j].Message, fixActions [j].Action.Message); } var fixRefactorings = fixes.CodeRefactoringActions.SelectMany(x => x.Actions).OrderBy(f => f.Message).ToArray(); Assert.AreEqual(expected.CodeRefactoringData.Length, fixRefactorings.Length); for (int j = 0; j < expected.CodeRefactoringData.Length; ++j) { Assert.AreEqual(expected.CodeRefactoringData [j].Message, fixRefactorings [j].Message); } }
public override void Run(Ide.Gui.Document document, ICSharpCode.NRefactory.TextLocation loc) { ApplySolution(Title, document); }
public FindMemberOverloadsHandler(Ide.Gui.Document doc, IMember entity) { this.doc = doc; this.entity = entity; }
public FindDerivedSymbolsHandler (Ide.Gui.Document doc, IMember entity) { this.doc = doc; this.entity = entity; }
// CorrectIndenting is completely unused in the entire MonoDevelopment code environment - doesn't have to be implemented /// <summary> /// Used for format selected code /// </summary> public override void OnTheFlyFormat(Ide.Gui.Document doc, int startOffset, int endOffset) { //base.OnTheFlyFormat(doc, startOffset, endOffset); }
public FindExtensionMethodHandler (Ide.Gui.Document doc, ITypeDefinition entity) { this.doc = doc; this.entity = entity; }
protected abstract void Format(TextEditor editor, Ide.Gui.Document document, SnapshotPoint start, SnapshotPoint end);
protected static void AssertExpectedDiagnostics(IEnumerable <ExpectedDiagnostic> expected, Ide.Gui.Document doc) { var ext = doc.GetContent <ResultsEditorExtension> (); var actualDiagnostics = ext.QuickTasks; var expectedDiagnostics = expected.ToArray(); Assert.AreEqual(expectedDiagnostics.Length, actualDiagnostics.Length); for (int i = 0; i < expectedDiagnostics.Length; ++i) { AssertExpectedDiagnostic(expectedDiagnostics [i], ext, i); } }
//public static Task<bool> InsertMemberWithCursor (string operation, ITypeSymbol type, Location part, SyntaxNode newMember, bool implementExplicit = false) //{ // //TODO: Add dialog for inserting position // AddNewMember (type, part, newMember, implementExplicit); // return Task.FromResult (true); //} // // public static int CalculateBodyIndentLevel (IUnresolvedTypeDefinition declaringType) // { // if (declaringType == null) // return 0; // int indentLevel = 1; // while (declaringType.DeclaringTypeDefinition != null) { // indentLevel++; // declaringType = declaringType.DeclaringTypeDefinition; // } // var file = declaringType.UnresolvedFile as CSharpUnresolvedFile; // if (file == null) // return indentLevel; // var scope = file.GetUsingScope (declaringType.Region.Begin); // while (scope != null && !string.IsNullOrEmpty (scope.NamespaceName)) { // indentLevel++; // // skip virtual scopes. // while (scope.Parent != null && scope.Parent.Region == scope.Region) // scope = scope.Parent; // scope = scope.Parent; // } // return indentLevel; // } public static MonoDevelop.Ide.TypeSystem.CodeGenerator CreateCodeGenerator(this Ide.Gui.Document doc) { return(MonoDevelop.Ide.TypeSystem.CodeGenerator.CreateGenerator(doc)); }
/// <summary> /// Searches for open documents and locates the ConnectedServicesViewContent for the given project /// </summary> internal static ConnectedServicesViewContent LocateServiceView(DotNetProject project) { Ide.Gui.Document view = null; return(LocateServiceView(project, out view)); }
protected void RegisterExtensionCallback <T> (Ide.Gui.Document doc, Action <T> registerCallback) where T : TextEditorExtension { var ext = doc.GetContent <T> (); registerCallback(ext); }
public static CodeGenerator CreateCodeGenerator(this Ide.Gui.Document doc) { return(CodeGenerator.CreateGenerator(doc)); }
/// <summary> /// Searches for open documents and locates the ConnectedServicesViewContent for the given project /// </summary> internal static ConnectedServicesViewContent LocateServiceView(DotNetProject project, out Ide.Gui.Document documentView) { documentView = null; foreach (var view in IdeApp.Workbench.Documents) { var servicesView = view.PrimaryView.GetContent <ConnectedServicesViewContent> (); if (servicesView != null && servicesView.Project == project) { documentView = view; return(servicesView); } } return(null); }