public ImportSymbolCompletionData (CSharpCompletionTextEditorExtension ext, INamedTypeSymbol type, bool useFullName) : base (null, type.Name) { this.ext = ext; this.useFullName = useFullName; this.type = type; this.DisplayFlags |= DisplayFlags.IsImportCompletion; }
public ImportSymbolCompletionData (CSharpCompletionTextEditorExtension ext, RoslynCodeCompletionFactory factory, ISymbol type, bool useFullName) : base (null, factory, type) { this.completionExt = ext; this.useFullName = useFullName; this.type = type; this.DisplayFlags |= DisplayFlags.IsImportCompletion; }
static Document Setup (string input) { var tww = new TestWorkbenchWindow (); var content = new TestViewContent (); var project = new DotNetAssemblyProject ("C#"); project.Name = "test"; project.References.Add (new ProjectReference (ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")); project.References.Add (new ProjectReference (ReferenceType.Package, "System.Core")); project.FileName = "test.csproj"; TypeSystemService.LoadProject (project); TypeSystemService.GetProjectContentWrapper (project).ReconnectAssemblyReferences (); content.Project = project; tww.ViewContent = content; content.ContentName = "a.cs"; content.GetTextEditorData ().Document.MimeType = "text/x-csharp"; var doc = new Document (tww); var text = input; int endPos = text.IndexOf ('$'); if (endPos >= 0) text = text.Substring (0, endPos) + text.Substring (endPos + 1); content.Text = text; content.CursorPosition = Math.Max (0, endPos); var compExt = new CSharpCompletionTextEditorExtension (); compExt.Initialize (doc); content.Contents.Add (compExt); doc.UpdateParseDocument (); return doc; }
public IndexerParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IType type, IEnumerable<IProperty> indexers, AstNode resolvedExpression) : base (ext, startOffset) { compilation = ext.UnresolvedFileCompilation; file = ext.CSharpUnresolvedFile; // this.resolvedExpression = resolvedExpression; this.indexers = new List<IProperty> (indexers); }
public DelegateDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IType delegateType) : base (ext, startOffset) { compilation = ext.UnresolvedFileCompilation; file = ext.CSharpUnresolvedFile; // this.delegateType = delegateType; this.delegateMethod = delegateType.GetDelegateInvokeMethod (); }
public AbstractParameterDataProvider (CSharpCompletionTextEditorExtension ext, int startOffset) { if (ext == null) throw new ArgumentNullException ("ext"); this.ext = ext; this.startOffset = startOffset; }
public DelegateDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IType delegateType) { this.startOffset = startOffset; // this.ext = ext; this.delegateType = delegateType; this.delegateMethod = delegateType.GetDelegateInvokeMethod (); }
public async Task TestBug58473() { var text = @"$"; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } var project = Ide.Services.ProjectService.CreateDotNetProject("C#"); project.Name = "test"; project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("mscorlib")); project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")); project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("System.Core")); project.FileName = "test.csproj"; project.Files.Add(new ProjectFile("/a.cs", BuildAction.Compile)); var solution = new MonoDevelop.Projects.Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); using (var monitor = new ProgressMonitor()) await TypeSystemService.Load(solution, monitor); var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; content.Project = project; content.Text = text; content.CursorPosition = Math.Max(0, endPos); var doc = new MonoDevelop.Ide.Gui.Document(tww); doc.SetProject(project); var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc.Editor, doc); content.Contents.Add(compExt); await doc.UpdateParseDocument(); var ctx = new CodeCompletionContext(); var tmp = IdeApp.Preferences.EnableAutoCodeCompletion; IdeApp.Preferences.EnableAutoCodeCompletion.Set(false); var list = await compExt.HandleCodeCompletionAsync(ctx, CompletionTriggerInfo.CodeCompletionCommand); Assert.IsNotNull(list); IdeApp.Preferences.EnableAutoCodeCompletion.Set(tmp); project.Dispose(); }
protected override void Initialize() { CurrentPath = new PathEntry[] { new PathEntry(GettextCatalog.GetString("No selection")) { Tag = null } }; isPathSet = false; // Delay the execution of UpdateOwnerProjects since it may end calling DocumentContext.AttachToProject, // which shouldn't be called while the extension chain is being initialized. Gtk.Application.Invoke(delegate { UpdateOwnerProjects(); Editor_CaretPositionChanged(null, null); }); Editor.TextChanging += Editor_TextChanging; DocumentContext.DocumentParsed += DocumentContext_DocumentParsed; ext = DocumentContext.GetContent <CSharpCompletionTextEditorExtension> (); ext.TypeSegmentTreeUpdated += HandleTypeSegmentTreeUpdated; IdeApp.Workspace.FileAddedToProject += HandleProjectChanged; IdeApp.Workspace.FileRemovedFromProject += HandleProjectChanged; IdeApp.Workspace.WorkspaceItemUnloaded += HandleWorkspaceItemUnloaded; IdeApp.Workspace.WorkspaceItemLoaded += HandleWorkspaceItemLoaded; IdeApp.Workspace.ItemAddedToSolution += HandleProjectChanged; IdeApp.Workspace.ActiveConfigurationChanged += HandleActiveConfigurationChanged; SubscribeCaretPositionChange(); }
static Document Setup (string input) { TestWorkbenchWindow tww = new TestWorkbenchWindow (); var content = new TestViewContent (); tww.ViewContent = content; content.ContentName = "a.cs"; content.GetTextEditorData ().Document.MimeType = "text/x-csharp"; Document doc = new Document (tww); var text = input; int endPos = text.IndexOf ('$'); if (endPos >= 0) text = text.Substring (0, endPos) + text.Substring (endPos + 1); content.Text = text; content.CursorPosition = System.Math.Max (0, endPos); var compExt = new CSharpCompletionTextEditorExtension (); compExt.Initialize (doc); content.Contents.Add (compExt); doc.UpdateParseDocument (); return doc; }
static Document Setup(string input) { var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "a.cs"; content.GetTextEditorData().Document.MimeType = "text/x-csharp"; var doc = new Document(tww); var text = input; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } content.Text = text; content.CursorPosition = Math.Max(0, endPos); var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc); content.Contents.Add(compExt); doc.UpdateParseDocument(); return(doc); }
static CSharpTextEditorIndentation Setup (string input, out TestViewContent content) { TestWorkbenchWindow tww = new TestWorkbenchWindow (); content = new TestViewContent (); content.Data.Options.IndentStyle = IndentStyle.Auto; tww.ViewContent = content; content.ContentName = "a.cs"; content.GetTextEditorData ().Document.MimeType = "text/x-csharp"; Document doc = new Document (tww); var text = input; int endPos = text.IndexOf ('$'); if (endPos >= 0) text = text.Substring (0, endPos) + text.Substring (endPos + 1); content.Text = text; content.CursorPosition = System.Math.Max (0, endPos); var compExt = new CSharpCompletionTextEditorExtension (); compExt.Initialize (doc); content.Contents.Add (compExt); var ext = new CSharpTextEditorIndentation (); CSharpTextEditorIndentation.OnTheFlyFormatting = true; ext.Initialize (doc); content.Contents.Add (ext); doc.UpdateParseDocument (); return ext; }
public async Task TestBug60365() { var tww = new TestWorkbenchWindow(); TestViewContent content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; var doc = new MonoDevelop.Ide.Gui.Document(tww); var text = "@c$"; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } content.Text = text; content.CursorPosition = System.Math.Max(0, endPos); var project = MonoDevelop.Projects.Services.ProjectService.CreateProject("C#"); project.Name = "test"; project.FileName = "test.csproj"; project.Files.Add(new ProjectFile(content.ContentName, BuildAction.Compile)); var solution = new MonoDevelop.Projects.Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); using (var monitor = new ProgressMonitor()) await TypeSystemService.Load(solution, monitor); content.Project = project; doc.SetProject(project); var ext = new CSharpCompletionTextEditorExtension(); ext.Initialize(doc.Editor, doc); var listWindow = new CompletionListWindow(); var widget = new TestCompletionWidget(ext.Editor, ext.DocumentContext); listWindow.CompletionWidget = widget; listWindow.CodeCompletionContext = widget.CurrentCodeCompletionContext; var list = await ext.HandleCodeCompletionAsync(widget.CurrentCodeCompletionContext, new CompletionTriggerInfo (CompletionTriggerReason.CharTyped, 'c')); var ka = KeyActions.Complete; list.First(d => d.CompletionText == "class").InsertCompletionText(listWindow, ref ka, KeyDescriptor.Tab); Assert.AreEqual("@class", content.Text); content.Contents.Add(ext); await doc.UpdateParseDocument(); TypeSystemService.Unload(solution); }
public IndexerParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IType type, AstNode resolvedExpression) { this.startOffset = startOffset; // this.ext = ext; this.resolvedExpression = resolvedExpression; indexers = new List<IProperty> (type.GetProperties (p => p.IsIndexer)); }
public RoslynCodeCompletionFactory (CSharpCompletionTextEditorExtension ext, SemanticModel semanticModel) { if (ext == null) throw new ArgumentNullException ("ext"); if (semanticModel == null) throw new ArgumentNullException ("semanticModel"); this.semanticModel = semanticModel; this.ext = ext; }
async Task <Document> CreateDocument(string input) { var text = input; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } if (solution != null) { TypeSystemService.Unload(solution); solution.Dispose(); } var project = Services.ProjectService.CreateDotNetProject("C#"); project.Name = "test"; project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("mscorlib")); project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")); project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("System.Core")); project.FileName = "test.csproj"; project.Files.Add(new ProjectFile("/a.cs", BuildAction.Compile)); solution = new MonoDevelop.Projects.Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); using (var monitor = new ProgressMonitor()) await TypeSystemService.Load(solution, monitor); var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; content.Project = project; content.Text = text; content.CursorPosition = Math.Max(0, endPos); var doc = new Document(tww); doc.SetProject(project); var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc.Editor, doc); content.Contents.Add(compExt); await doc.UpdateParseDocument(); return(doc); }
public override void Initialize () { CurrentPath = new PathEntry[] { new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = null } }; isPathSet = false; UpdatePath (null, null); caret = Document.Editor.Caret; caret.PositionChanged += UpdatePath; ext = Document.GetContent<CSharpCompletionTextEditorExtension> (); ext.TypeSegmentTreeUpdated += HandleTypeSegmentTreeUpdated; }
async Task <ISymbol> GetMemberToDocument(CancellationToken cancellationToken = default(CancellationToken)) { var parsedDocument = DocumentContext.ParsedDocument; if (parsedDocument == null) { return(null); } var partialDoc = await CSharpCompletionTextEditorExtension.WithFrozenPartialSemanticsAsync(DocumentContext.AnalysisDocument, cancellationToken).ConfigureAwait(false); var semanticModel = await partialDoc.GetSemanticModelAsync(); if (semanticModel == null) { return(null); } var caretOffset = Editor.CaretOffset; var offset = caretOffset; var root = semanticModel.SyntaxTree.GetRoot(); while (offset < Editor.Length) { var node = root.FindNode(TextSpan.FromBounds(offset, offset)); if (node == null || node.GetLastToken().SpanStart < caretOffset) { offset++; continue; } var fieldDeclarationSyntax = node as FieldDeclarationSyntax; if (fieldDeclarationSyntax != null) { node = fieldDeclarationSyntax.Declaration.Variables.First(); } var eventDeclaration = node as EventFieldDeclarationSyntax; if (eventDeclaration != null) { node = eventDeclaration.Declaration.Variables.First(); } if (node.Span.Contains(caretOffset)) { return(null); } var declaredSymbol = semanticModel.GetDeclaredSymbol(node); if (declaredSymbol != null) { return(declaredSymbol); } offset = node.FullSpan.End + 1; } return(null); }
public NewOverrideCompletionData (CSharpCompletionTextEditorExtension ext, int declarationBegin, IUnresolvedTypeDefinition type, IMember member) : base (null) { this.ext = ext; this.type = type; this.member = member; this.declarationBegin = declarationBegin; this.GenerateBody = true; this.Icon = member.GetStockIcon (); this.DisplayText = ambience.GetString (member, OutputFlags.IncludeParameters | OutputFlags.IncludeParameterName | OutputFlags.IncludeGenerics | OutputFlags.HideExtensionsParameter| OutputFlags.IncludeAccessor); this.CompletionText = member.EntityType == EntityType.Indexer ? "this" : member.Name; }
public override void Initialize() { CurrentPath = new PathEntry[] { new PathEntry(GettextCatalog.GetString("No selection")) { Tag = null } }; isPathSet = false; UpdatePath(null, null); caret = Document.Editor.Caret; caret.PositionChanged += UpdatePath; ext = Document.GetContent <CSharpCompletionTextEditorExtension> (); ext.TypeSegmentTreeUpdated += HandleTypeSegmentTreeUpdated; }
public override void Initialize () { CurrentPath = new PathEntry[] { new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = null } }; isPathSet = false; UpdateOwnerProjects (); UpdatePath (null, null); caret = Document.Editor.Caret; caret.PositionChanged += UpdatePath; ext = Document.GetContent<CSharpCompletionTextEditorExtension> (); ext.TypeSegmentTreeUpdated += HandleTypeSegmentTreeUpdated; IdeApp.Workspace.FileAddedToProject += HandleProjectChanged; IdeApp.Workspace.FileRemovedFromProject += HandleProjectChanged; }
/// <summary> /// Builds a compileable stub file out of an entity. /// </summary> /// <returns> /// A string representing the stub /// </returns> /// <param name='memberStartOffset'> /// The offset where the member starts in the returned text. /// </param> static string BuildStub (MonoDevelop.Ide.Gui.Document data, CSharpCompletionTextEditorExtension.TypeSystemTreeSegment seg, int startOffset, int endOffset, out int memberStartOffset) { var pf = data.ParsedDocument.ParsedFile as CSharpUnresolvedFile; if (pf == null) { memberStartOffset = 0; return null; } var sb = new StringBuilder (); int closingBrackets = 0; // use the member start location to determine the using scope, because this information is in sync, the position in // the file may have changed since last parse run (we have up 2 date locations from the type segment tree). var scope = pf.GetUsingScope (seg.Entity.Region.Begin); while (scope != null && !string.IsNullOrEmpty (scope.NamespaceName)) { // Hack: some syntax errors lead to invalid namespace names. if (scope.NamespaceName.EndsWith ("<invalid>")) { scope = scope.Parent; continue; } sb.Append ("namespace Stub {"); sb.Append (data.Editor.EolMarker); closingBrackets++; while (scope.Parent != null && scope.Parent.Region == scope.Region) scope = scope.Parent; scope = scope.Parent; } var parent = seg.Entity.DeclaringTypeDefinition; while (parent != null) { sb.Append ("class " + parent.Name + " {"); sb.Append (data.Editor.EolMarker); closingBrackets++; parent = parent.DeclaringTypeDefinition; } memberStartOffset = sb.Length; sb.Append (data.Editor.GetTextBetween (seg.Offset, endOffset)); // Insert at least caret column eol markers otherwise the reindent of the generated closing bracket // could interfere with the current indentation. var endLocation = data.Editor.OffsetToLocation (endOffset); for (int i = 0; i <= endLocation.Column; i++) { sb.Append (data.Editor.EolMarker); } sb.Append (data.Editor.EolMarker); sb.Append (new string ('}', closingBrackets)); return sb.ToString (); }
public MethodParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IEnumerable<IMethod> m) : base (ext, startOffset) { HashSet<string> alreadyAdded = new HashSet<string> (); foreach (var method in m) { if (method.IsConstructor) continue; string str = ambience.GetString (method, OutputFlags.IncludeParameters | OutputFlags.GeneralizeGenerics | OutputFlags.IncludeGenerics); if (alreadyAdded.Contains (str)) continue; alreadyAdded.Add (str); methods.Add (method); } methods.Sort (MethodComparer); }
public static CSharpCompletionTextEditorExtension.CSharpCompletionDataList CreateProvider (string text) { int cursorPosition; SemanticModel semanticModel; Document document; var engine = CodeCompletionBugTests.CreateEngine (text, out cursorPosition, out semanticModel, out document, null); var ext = new CSharpCompletionTextEditorExtension (); var list = new CSharpCompletionTextEditorExtension.CSharpCompletionDataList (); var result = CodeCompletionBugTests.CreateProvider (text); list.AddRange (result); ext.AddImportCompletionData (result, list, new RoslynCodeCompletionFactory (ext, semanticModel), semanticModel, cursorPosition); return list; }
static async Task <Tuple <CSharpCompletionTextEditorExtension, TestViewContent> > Setup(string input) { TestWorkbenchWindow tww = new TestWorkbenchWindow(); TestViewContent content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; var doc = new MonoDevelop.Ide.Gui.Document(tww); var text = input; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } content.Text = text; content.CursorPosition = System.Math.Max(0, endPos); var project = Services.ProjectService.CreateProject("C#"); project.Name = "test"; project.FileName = "test.csproj"; project.Files.Add(new ProjectFile(content.ContentName, BuildAction.Compile)); project.Policies.Set(PolicyService.InvariantPolicies.Get <CSharpFormattingPolicy> (), CSharpFormatter.MimeType); var solution = new MonoDevelop.Projects.Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); using (var monitor = new ProgressMonitor()) await TypeSystemService.Load(solution, monitor); content.Project = project; doc.SetProject(project); var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc.Editor, doc); content.Contents.Add(compExt); await doc.UpdateParseDocument(); TypeSystemService.Unload(solution); return(Tuple.Create(compExt, content)); }
public override void Initialize() { CurrentPath = new PathEntry[] { new PathEntry(GettextCatalog.GetString("No selection")) { Tag = null } }; isPathSet = false; UpdateOwnerProjects(); UpdatePath(null, null); caret = Document.Editor.Caret; caret.PositionChanged += UpdatePath; ext = Document.GetContent <CSharpCompletionTextEditorExtension> (); ext.TypeSegmentTreeUpdated += HandleTypeSegmentTreeUpdated; IdeApp.Workspace.FileAddedToProject += HandleProjectChanged; IdeApp.Workspace.FileRemovedFromProject += HandleProjectChanged; }
public static CSharpCompletionTextEditorExtension.CSharpCompletionDataList CreateProvider(string text) { int cursorPosition; SemanticModel semanticModel; Document document; var engine = CodeCompletionBugTests.CreateEngine(text, out cursorPosition, out semanticModel, out document, null); var ext = new CSharpCompletionTextEditorExtension(); var list = new CSharpCompletionTextEditorExtension.CSharpCompletionDataList(); var result = CodeCompletionBugTests.CreateProvider(text); list.AddRange(result); ext.AddImportCompletionData(result, list, new RoslynCodeCompletionFactory(ext, semanticModel), semanticModel, cursorPosition); return(list); }
static string ResolveExpression(Document doc, string content, int offset) { var editor = doc.Editor; ResolveResult result; int startOffset; AstNode node; var loc = editor.OffsetToLocation(offset); if (!doc.TryResolveAt(loc, out result, out node)) { return(null); } return(CSharpCompletionTextEditorExtension.ResolveExpression(doc.Editor, result, node, out startOffset)); }
public ConstructorParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IType type) : base (startOffset, ext) { this.type = type; var ctx = ext.CSharpParsedFile.GetTypeResolveContext (ext.Compilation, ext.Document.Editor.Caret.Location) as CSharpTypeResolveContext; var lookup = new MemberLookup (ctx.CurrentTypeDefinition, ext.Compilation.MainAssembly); bool isProtectedAllowed = ctx.CurrentTypeDefinition != null && type.GetDefinition () != null ? ctx.CurrentTypeDefinition.IsDerivedFrom (type.GetDefinition ()) : false; foreach (var method in type.GetConstructors ()) { Console.WriteLine ("constructor:" + method); if (!lookup.IsAccessible (method, isProtectedAllowed)) { Console.WriteLine ("skip !!!"); continue; } methods.Add (method); } }
public override void Initialize () { CurrentPath = new PathEntry[] { new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = null } }; isPathSet = false; // Delay the execution of UpdateOwnerProjects since it may end calling Document.AttachToProject, // which shouldn't be called while the extension chain is being initialized. Gtk.Application.Invoke (delegate { UpdateOwnerProjects (); UpdatePath (null, null); }); caret = Document.Editor.Caret; caret.PositionChanged += UpdatePath; ext = Document.GetContent<CSharpCompletionTextEditorExtension> (); ext.TypeSegmentTreeUpdated += HandleTypeSegmentTreeUpdated; IdeApp.Workspace.FileAddedToProject += HandleProjectChanged; IdeApp.Workspace.FileRemovedFromProject += HandleProjectChanged; IdeApp.Workspace.WorkspaceItemUnloaded += HandleWorkspaceItemUnloaded; IdeApp.Workspace.WorkspaceItemLoaded += HandleWorkspaceItemLoaded;; }
static Document Setup(string input) { var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); var project = new DotNetAssemblyProject("C#"); project.Name = "test"; project.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")); project.References.Add(new ProjectReference(ReferenceType.Package, "System.Core")); project.FileName = "test.csproj"; var wrapper = TypeSystemService.LoadProject(project); wrapper.EnsureReferencesAreLoaded(); wrapper.ReconnectAssemblyReferences(); content.Project = project; tww.ViewContent = content; content.ContentName = "a.cs"; content.GetTextEditorData().Document.MimeType = "text/x-csharp"; var doc = new Document(tww); var text = input; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } content.Text = text; content.CursorPosition = Math.Max(0, endPos); var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc); content.Contents.Add(compExt); doc.UpdateParseDocument(); return(doc); }
public EventCreationCompletionData (CSharpCompletionTextEditorExtension ext, string varName, IType delegateType, IEvent evt, string parameterList, IUnresolvedMember callingMember, IUnresolvedTypeDefinition declaringType) : base (null) { if (string.IsNullOrEmpty (varName)) { this.DisplayText = "Handle" + (evt != null ? evt.Name : ""); } else { this.DisplayText = "Handle" + Char.ToUpper (varName[0]) + varName.Substring (1) + (evt != null ? evt.Name : ""); } if (declaringType != null && declaringType.Members.Any (m => m.Name == this.DisplayText)) { for (int i = 1; i < 10000; i++) { if (!declaringType.Members.Any (m => m.Name == this.DisplayText + i)) { this.DisplayText = this.DisplayText + i.ToString (); break; } } } this.editor = ext.TextEditorData; this.parameterList = parameterList; this.callingMember = callingMember; this.Icon = "md-newmethod"; this.initialOffset = editor.Caret.Offset; }
public override void Initialize() { CurrentPath = new PathEntry[] { new PathEntry(GettextCatalog.GetString("No selection")) { Tag = null } }; isPathSet = false; // Delay the execution of UpdateOwnerProjects since it may end calling Document.AttachToProject, // which shouldn't be called while the extension chain is being initialized. Gtk.Application.Invoke(delegate { UpdateOwnerProjects(); UpdatePath(null, null); }); caret = Document.Editor.Caret; caret.PositionChanged += UpdatePath; ext = Document.GetContent <CSharpCompletionTextEditorExtension> (); ext.TypeSegmentTreeUpdated += HandleTypeSegmentTreeUpdated; IdeApp.Workspace.FileAddedToProject += HandleProjectChanged; IdeApp.Workspace.FileRemovedFromProject += HandleProjectChanged; IdeApp.Workspace.WorkspaceItemUnloaded += HandleWorkspaceItemUnloaded; IdeApp.Workspace.WorkspaceItemLoaded += HandleWorkspaceItemLoaded;; }
static CSharpTextEditorIndentation Setup(string input, out TestViewContent content) { TestWorkbenchWindow tww = new TestWorkbenchWindow(); content = new TestViewContent(); content.Data.Options.IndentStyle = IndentStyle.Auto; tww.ViewContent = content; content.ContentName = "a.cs"; content.GetTextEditorData().Document.MimeType = "text/x-csharp"; Document doc = new Document(tww); var text = input; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } content.Text = text; content.CursorPosition = System.Math.Max(0, endPos); var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc); content.Contents.Add(compExt); var ext = new CSharpTextEditorIndentation(); CSharpTextEditorIndentation.OnTheFlyFormatting = true; ext.Initialize(doc); content.Contents.Add(ext); doc.UpdateParseDocument(); return(ext); }
public ConstructorParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IType type) : base (startOffset, ext) { this.type = type; var ctx = ext.CSharpParsedFile.GetTypeResolveContext (ext.Compilation, ext.Document.Editor.Caret.Location) as CSharpTypeResolveContext; var lookup = new MemberLookup (ctx.CurrentTypeDefinition, ext.Compilation.MainAssembly); bool isProtectedAllowed = false; var typeDefinition = type.GetDefinition (); if (ctx.CurrentTypeDefinition != null && typeDefinition != null) { isProtectedAllowed = ctx.CurrentTypeDefinition.IsDerivedFrom (ctx.CurrentTypeDefinition.Compilation.Import (typeDefinition)); } foreach (var method in type.GetConstructors ()) { if (!lookup.IsAccessible (method, isProtectedAllowed)) { continue; } if (!method.IsBrowsable ()) continue; methods.Add (method); } methods.Sort ((l, r) => l.GetEditorBrowsableState ().CompareTo (r.GetEditorBrowsableState ())); }
public ConstructorParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IType type, AstNode skipInitializer = null) : base (startOffset, ext) { this.type = type; var ctx = ext.CSharpUnresolvedFile.GetTypeResolveContext (ext.UnresolvedFileCompilation, ext.Editor.CaretLocation) as CSharpTypeResolveContext; var lookup = new MemberLookup (ctx.CurrentTypeDefinition, ext.Compilation.MainAssembly); bool isProtectedAllowed = false; var typeDefinition = type.GetDefinition (); if (ctx.CurrentTypeDefinition != null && typeDefinition != null) { isProtectedAllowed = ctx.CurrentTypeDefinition.IsDerivedFrom (ctx.CurrentTypeDefinition.Compilation.Import (typeDefinition)); } foreach (var method in type.GetConstructors ()) { if (!lookup.IsAccessible (method, isProtectedAllowed)) { continue; } if (!method.IsBrowsable ()) continue; if (skipInitializer != null && skipInitializer.Parent.StartLocation == method.Region.Begin) continue; methods.Add (method); } methods.Sort (MethodComparer); }
public static TooltipInformation CreateTooltipInformation (CSharpCompletionTextEditorExtension ext, ICompilation compilation, CSharpUnresolvedFile file, IParameterizedMember entity, int currentParameter, bool smartWrap) { return CreateTooltipInformation (compilation, file, ext.TextEditorData, ext.FormattingPolicy, entity, currentParameter, smartWrap); }
static async Task<Tuple<CSharpCompletionTextEditorExtension,TestViewContent>> Setup (string input) { TestWorkbenchWindow tww = new TestWorkbenchWindow (); TestViewContent content = new TestViewContent (); tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; var doc = new MonoDevelop.Ide.Gui.Document (tww); var text = input; int endPos = text.IndexOf ('$'); if (endPos >= 0) text = text.Substring (0, endPos) + text.Substring (endPos + 1); content.Text = text; content.CursorPosition = System.Math.Max (0, endPos); var project = Services.ProjectService.CreateProject ("C#"); project.Name = "test"; project.FileName = "test.csproj"; project.Files.Add (new ProjectFile (content.ContentName, BuildAction.Compile)); project.Policies.Set (PolicyService.InvariantPolicies.Get<CSharpFormattingPolicy> (), CSharpFormatter.MimeType); var solution = new MonoDevelop.Projects.Solution (); solution.AddConfiguration ("", true); solution.DefaultSolutionFolder.AddItem (project); using (var monitor = new ProgressMonitor ()) await TypeSystemService.Load (solution, monitor); content.Project = project; doc.SetProject (project); var compExt = new CSharpCompletionTextEditorExtension (); compExt.Initialize (doc.Editor, doc); content.Contents.Add (compExt); await doc.UpdateParseDocument (); TypeSystemService.Unload (solution); return Tuple.Create (compExt, content); }
private static async Task CheckAutoBracket(string mid, string expected) { var prefix = @" class FooBar { public static void Main (string[] args) { Console.WriteLine (" ; var suffix = ");\n\t}\n}\n"; var text = prefix + mid + "@" + suffix; int endPos = text.IndexOf('@'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } var project = Ide.Services.ProjectService.CreateDotNetProject("C#"); project.Name = "test"; project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("mscorlib")); project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")); project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("System.Core")); project.FileName = "test.csproj"; project.Files.Add(new ProjectFile("/a.cs", BuildAction.Compile)); var solution = new MonoDevelop.Projects.Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); using (var monitor = new ProgressMonitor()) await TypeSystemService.Load(solution, monitor); var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; content.Project = project; content.Text = text; content.CursorPosition = Math.Max(0, endPos); var doc = new MonoDevelop.Ide.Gui.Document(tww); doc.SetProject(project); var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc.Editor, doc); content.Contents.Add(compExt); await doc.UpdateParseDocument(); var ctx = new CodeCompletionContext(); var handler = new CSharpAutoInsertBracketHandler(); char ch = mid [mid.Length - 1]; handler.Handle(doc.Editor, doc, Ide.Editor.Extension.KeyDescriptor.FromGtk((Gdk.Key)ch, ch, Gdk.ModifierType.None)); var newText = doc.Editor.GetTextAt(prefix.Length, doc.Editor.Length - prefix.Length - suffix.Length); Assert.AreEqual(expected, newText); project.Dispose(); }
async Task <ISymbol> GetMemberToDocument(CancellationToken cancellationToken = default(CancellationToken)) { var parsedDocument = DocumentContext.ParsedDocument; if (parsedDocument == null) { return(null); } try { var analysisDoc = DocumentContext.AnalysisDocument; if (analysisDoc == null) { return(null); } var partialDoc = await CSharpCompletionTextEditorExtension.WithFrozenPartialSemanticsAsync(analysisDoc, cancellationToken).ConfigureAwait(false); var semanticModel = await partialDoc.GetSemanticModelAsync(); if (semanticModel == null) { return(null); } var caretOffset = Editor.CaretOffset; var offset = caretOffset; var root = semanticModel.SyntaxTree.GetRoot(); var tokenAtCaret = root.FindTrivia(offset - 1, true); if (!tokenAtCaret.IsKind(SyntaxKind.SingleLineCommentTrivia)) { return(null); } while (offset < Editor.Length) { var node = root.FindNode(TextSpan.FromBounds(offset, offset)); if (node == null || node.GetLastToken().SpanStart < caretOffset) { offset++; continue; } var fieldDeclarationSyntax = node as FieldDeclarationSyntax; if (fieldDeclarationSyntax != null) { node = fieldDeclarationSyntax.Declaration.Variables.First(); } var eventDeclaration = node as EventFieldDeclarationSyntax; if (eventDeclaration != null) { node = eventDeclaration.Declaration.Variables.First(); } if (node.Span.Contains(caretOffset)) { return(null); } var declaredSymbol = semanticModel.GetDeclaredSymbol(node); if (declaredSymbol != null) { return(declaredSymbol); } offset = node.FullSpan.End + 1; } return(null); } catch (Exception e) { LoggingService.LogError("Error wihle getting member to document.", e); return(null); } }
static CSharpTextEditorIndentation Setup(string input, out TestViewContent content) { TestWorkbenchWindow tww = new TestWorkbenchWindow(); content = new TestViewContent(); content.Data.Options.IndentStyle = IndentStyle.Auto; tww.ViewContent = content; content.ContentName = "a.cs"; content.GetTextEditorData().Document.MimeType = "text/x-csharp"; Document doc = new Document(tww); var sb = new StringBuilder(); int cursorPosition = 0, selectionStart = -1, selectionEnd = -1; for (int i = 0; i < input.Length; i++) { var ch = input [i]; switch (ch) { case '$': cursorPosition = sb.Length; break; case '<': if (i + 1 < input.Length) { if (input [i + 1] == '-') { selectionStart = sb.Length; i++; break; } } goto default; case '-': if (i + 1 < input.Length) { var next = input [i + 1]; if (next == '>') { selectionEnd = sb.Length; i++; break; } } goto default; default: sb.Append(ch); break; } } content.Text = sb.ToString(); content.CursorPosition = cursorPosition; var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc); content.Contents.Add(compExt); var ext = new CSharpTextEditorIndentation(); CSharpTextEditorIndentation.OnTheFlyFormatting = true; ext.Initialize(doc); content.Contents.Add(ext); doc.UpdateParseDocument(); if (selectionStart >= 0 && selectionEnd >= 0) { content.GetTextEditorData().SetSelection(selectionStart, selectionEnd); } return(ext); }
public TemplateParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IEnumerable<IType> types) { this.startOffset = startOffset; // this.ext = ext; this.types = new List<IType> (types); }
static bool IsBracketAlreadyInserted (CSharpCompletionTextEditorExtension ext, IMethodSymbol method) { var Editor = ext.Editor; int offset = Editor.CaretOffset; while (offset < Editor.Length) { char ch = Editor.GetCharAt (offset); if (!char.IsLetterOrDigit (ch)) break; offset++; } while (offset < Editor.Length) { char ch = Editor.GetCharAt (offset); if (!char.IsWhiteSpace (ch)) return ch == '(' || ch == '<' && RequireGenerics (method); offset++; } return false; }
public override async Task <BraceMatchingResult?> GetMatchingBracesAsync(IReadonlyTextDocument editor, DocumentContext context, int offset, CancellationToken cancellationToken = default(CancellationToken)) { if (context.ParsedDocument == null) { return(await fallback.GetMatchingBracesAsync(editor, context, offset, cancellationToken)); } var analysisDocument = context.AnalysisDocument; if (analysisDocument == null) { return(null); } var partialDoc = await CSharpCompletionTextEditorExtension.WithFrozenPartialSemanticsAsync(analysisDocument, cancellationToken).ConfigureAwait(false); var root = await partialDoc.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); if (offset < 0 || root.Span.End <= offset) { return(null); } var token = root.FindToken(offset); var tokenSpan = token.Span; if (offset < tokenSpan.Start || offset > tokenSpan.End) { return(null); } for (int i = 0; i < tokenPairs.Length / 2; i++) { var open = tokenPairs [i * 2]; var close = tokenPairs [i * 2 + 1]; SyntaxToken match; if (token.IsKind(open)) { if (TryFindMatchingToken(token, out match, open, close)) { return(new BraceMatchingResult(new TextSegment(tokenSpan.Start, tokenSpan.Length), new TextSegment(match.Span.Start, match.Span.Length), true)); } } else if (token.IsKind(close)) { if (TryFindMatchingToken(token, out match, open, close)) { return(new BraceMatchingResult(new TextSegment(match.Span.Start, match.Span.Length), new TextSegment(tokenSpan.Start, tokenSpan.Length), false)); } } } if (token.IsKind(SyntaxKind.StringLiteralToken)) { if (token.IsVerbatimStringLiteral()) { if (offset <= tokenSpan.Start) { return(new BraceMatchingResult(new TextSegment(tokenSpan.Start, 2), new TextSegment(tokenSpan.End - 1, 1), true)); } if (offset >= tokenSpan.End - 1) { return(new BraceMatchingResult(new TextSegment(tokenSpan.Start, 2), new TextSegment(tokenSpan.End - 1, 1), false)); } } else { if (offset <= tokenSpan.Start) { return(new BraceMatchingResult(new TextSegment(tokenSpan.Start, 1), new TextSegment(tokenSpan.End - 1, 1), true)); } if (offset >= tokenSpan.End - 1) { return(new BraceMatchingResult(new TextSegment(tokenSpan.Start, 1), new TextSegment(tokenSpan.End - 1, 1), false)); } } } if (token.IsKind(SyntaxKind.CharacterLiteralToken)) { if (offset <= tokenSpan.Start) { return(new BraceMatchingResult(new TextSegment(tokenSpan.Start, 1), new TextSegment(tokenSpan.End - 1, 1), true)); } if (offset >= tokenSpan.End - 1) { return(new BraceMatchingResult(new TextSegment(tokenSpan.Start, 1), new TextSegment(tokenSpan.End - 1, 1), false)); } } return(null); }
internal static bool InsertSemicolon (CSharpCompletionTextEditorExtension ext, int exprStart) { var Editor = ext.Editor; int offset = exprStart; while (offset > 0) { char ch = Editor.GetCharAt (offset); if (!char.IsWhiteSpace (ch)) { if (ch != '{' && ch != '}' && ch != ';') return false; break; } offset--; } offset = Editor.CaretOffset; while (offset < Editor.Length) { char ch = Editor.GetCharAt (offset); if (!char.IsLetterOrDigit (ch)) break; offset++; } while (offset < Editor.Length) { char ch = Editor.GetCharAt (offset); if (!char.IsWhiteSpace (ch)) return char.IsLetter (ch) || ch == '}'; offset++; } return true; }
public ArrayTypeParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, ArrayType arrayType) : base (ext, startOffset) { this.arrayType = arrayType; }
protected MethodParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext) : base (ext, startOffset) { compilation = ext.UnresolvedFileCompilation; file = ext.CSharpUnresolvedFile; }
static async Task Simulate(string input, Action <TestViewContent, EditorFormattingServiceTextEditorExtension> act, CSharpFormattingPolicy formattingPolicy = null, EolMarker eolMarker = EolMarker.Unix) { TestWorkbenchWindow tww = new TestWorkbenchWindow(); var content = new TestViewContent(); content.Data.Options = new CustomEditorOptions { IndentStyle = IndentStyle.Auto }; tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; var doc = new Document(tww); var sb = new StringBuilder(); int cursorPosition = 0, selectionStart = -1, selectionEnd = -1; for (int i = 0; i < input.Length; i++) { var ch = input [i]; switch (ch) { case '$': cursorPosition = sb.Length; break; case '<': if (i + 1 < input.Length) { if (input [i + 1] == '-') { selectionStart = sb.Length; i++; break; } } goto default; case '-': if (i + 1 < input.Length) { var next = input [i + 1]; if (next == '>') { selectionEnd = sb.Length; i++; break; } } goto default; default: sb.Append(ch); break; } } content.Text = sb.ToString(); content.CursorPosition = cursorPosition; var project = Services.ProjectService.CreateProject("C#"); project.Name = "test"; project.FileName = "test.csproj"; project.Files.Add(new ProjectFile(content.ContentName, BuildAction.Compile)); var textStylePolicy = Projects.Policies.PolicyService.InvariantPolicies.Get <TextStylePolicy> ().WithTabsToSpaces(false) .WithEolMarker(eolMarker); project.Policies.Set(textStylePolicy, content.Data.MimeType); project.Policies.Set(formattingPolicy ?? Projects.Policies.PolicyService.InvariantPolicies.Get <CSharpFormattingPolicy> (), content.Data.MimeType); var solution = new MonoDevelop.Projects.Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); using (var monitor = new ProgressMonitor()) await TypeSystemService.Load(solution, monitor); content.Project = project; doc.SetProject(project); var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc.Editor, doc); content.Contents.Add(compExt); var ext = new EditorFormattingServiceTextEditorExtension(); ext.Initialize(doc.Editor, doc); content.Contents.Add(ext); await doc.UpdateParseDocument(); if (selectionStart >= 0 && selectionEnd >= 0) { content.GetTextEditorData().SetSelection(selectionStart, selectionEnd); } using (var testCase = new Ide.TextEditorExtensionTestCase(doc, content, tww, null, false)) { act(content, ext); } }
public MethodParameterDataProvider (CSharpCompletionTextEditorExtension ext, IMethod method) : base (ext, 0) { methods.Add (method); }