public override bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch) { if (this.CompletionPossible(editor, ch)) { ResourceResolveResult result = ResourceResolverService.Resolve(editor, ch); if (result != null) { IResourceFileContent content; if ((content = result.ResourceFileContent) != null) { // If the resolved resource set is the local ICSharpCode.Core resource set // (this may happen through the ICSharpCodeCoreNRefactoryResourceResolver), // we will have to merge in the host resource set (if available) // for the code completion window. if (result.ResourceSetReference.ResourceSetName == ICSharpCodeCoreResourceResolver.ICSharpCodeCoreLocalResourceSetName) { IResourceFileContent hostContent = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceSet(editor.FileName).ResourceFileContent; if (hostContent != null) { content = new MergedResourceFileContent(content, new IResourceFileContent[] { hostContent }); } } editor.ShowCompletionWindow(new ResourceCodeCompletionDataProvider(content, this.OutputVisitor, result.CallingClass != null ? result.CallingClass.Name+"." : null), ch); return true; } } } return false; }
protected IList <ResolveResult> ResolveCallParameters(SharpDevelopTextAreaControl editor, InspectedCall call) { List <ResolveResult> rr = new List <ResolveResult>(); int offset = LocationToOffset(editor, call.start); string documentText = editor.Text; int newOffset; foreach (Location loc in call.commas) { newOffset = LocationToOffset(editor, loc); if (newOffset < 0) { break; } string text = editor.Document.GetText(offset + 1, newOffset - (offset + 1)); rr.Add(ParserService.Resolve(new ExpressionResult(text), loc.Line, loc.Column, editor.FileName, documentText)); } // the last argument is between the last comma and the caret position newOffset = editor.ActiveTextAreaControl.Caret.Offset; if (offset < newOffset) { string text = editor.Document.GetText(offset + 1, newOffset - (offset + 1)); rr.Add(ParserService.Resolve(new ExpressionResult(text), editor.ActiveTextAreaControl.Caret.Line + 1, editor.ActiveTextAreaControl.Caret.Column + 1, editor.FileName, documentText)); } return(rr); }
public SharpSnippetCompilerControl() { InitializeComponent(); textEditor = new SharpDevelopTextAreaControl(); textEditor.Dock = DockStyle.Fill; this.Controls.Add(textEditor); }
public virtual bool CtrlSpace(SharpDevelopTextAreaControl editor) { CtrlSpaceCompletionDataProvider provider = new CtrlSpaceCompletionDataProvider(); provider.AllowCompleteExistingExpression = true; editor.ShowCompletionWindow(provider, '\0'); return(true); }
public QuickClassBrowserPanel(SharpDevelopTextAreaControl textAreaControl) { InitializeComponent(); this.membersComboBox.MaxDropDownItems = 20; base.Dock = DockStyle.Top; this.textAreaControl = textAreaControl; this.textAreaControl.ActiveTextAreaControl.Caret.PositionChanged += new EventHandler(CaretPositionChanged); }
protected int LocationToOffset(SharpDevelopTextAreaControl editor, Location loc) { if (loc.IsEmpty || loc.Line - 1 >= editor.Document.TotalNumberOfLines) { return(-1); } LineSegment seg = editor.Document.GetLineSegment(loc.Line - 1); return(seg.Offset + Math.Min(loc.Column, seg.Length) - 1); }
public TextEditorDisplayBindingWrapper() { textAreaControl = CreateSharpDevelopTextAreaControl(); textAreaControl.RightToLeft = RightToLeft.No; textAreaControl.Document.DocumentChanged += new DocumentEventHandler(TextAreaChangedEvent); textAreaControl.ActiveTextAreaControl.Caret.CaretModeChanged += new EventHandler(CaretModeChanged); textAreaControl.ActiveTextAreaControl.Enter += new EventHandler(CaretUpdate); textAreaControl.ActiveTextAreaControl.Caret.PositionChanged += CaretUpdate; watcher = new FileChangeWatcher(this); }
public TextEditorDisplayBindingWrapper(OpenedFile file) : base(file) { this.TabPageText = "${res:FormsDesigner.DesignTabPages.SourceTabPage}"; textEditorControl = CreateSharpDevelopTextAreaControl(); textEditorControl.RightToLeft = RightToLeft.No; textEditorControl.Document.DocumentChanged += new DocumentEventHandler(TextAreaChangedEvent); textEditorControl.ActiveTextAreaControl.Caret.CaretModeChanged += new EventHandler(CaretModeChanged); textEditorControl.ActiveTextAreaControl.Enter += new EventHandler(CaretUpdate); textEditorControl.ActiveTextAreaControl.Caret.PositionChanged += CaretUpdate; textEditorControl.FileName = file.FileName; }
public bool CtrlSpace(SharpDevelopTextAreaControl editor) { string ext = Path.GetExtension(editor.FileName); foreach (string extension in extensions) { if (ext.Equals(extension, StringComparison.OrdinalIgnoreCase)) { if (binding == null) { binding = (ICodeCompletionBinding)codon.AddIn.CreateObject(codon.Properties["class"]); } return binding.CtrlSpace(editor); } } return false; }
public bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch) { string ext = Path.GetExtension(editor.FileName); foreach (string extension in extensions) { if (ext.Equals(extension, StringComparison.InvariantCultureIgnoreCase)) { if (binding == null) { binding = (ICodeCompletionBinding)codon.AddIn.CreateObject(codon.Properties["class"]); } return binding.HandleKeyPress(editor, ch); } } return false; }
protected IMember GetCurrentMember(SharpDevelopTextAreaControl editor) { ICSharpCode.TextEditor.Caret caret = editor.ActiveTextAreaControl.Caret; NRefactoryResolver r = new NRefactoryResolver(ParserService.CurrentProjectContent, languageProperties); if (r.Initialize(editor.FileName, caret.Line + 1, caret.Column + 1)) { return(r.CallingMember); } else { return(null); } }
public override bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch) { if (ch == ':') { if (editor.ActiveTextAreaControl.Caret.Offset >= 5 && editor.Document.GetText(editor.ActiveTextAreaControl.Caret.Offset-5, 5) == "${res") { IResourceFileContent content = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreLocalResourceSet(editor.FileName).ResourceFileContent; #if DEBUG if (content != null) { LoggingService.Debug("ResourceToolkit: Found local ICSharpCode.Core resource file: "+content.FileName); } #endif IResourceFileContent hostContent = ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceSet(editor.FileName).ResourceFileContent; if (hostContent != null) { #if DEBUG LoggingService.Debug("ResourceToolkit: Found host ICSharpCode.Core resource file: "+hostContent.FileName); #endif if (content != null) { content = new MergedResourceFileContent(content, new IResourceFileContent[] { hostContent }); } else { content = hostContent; } } if (content != null) { editor.ShowCompletionWindow(new ResourceCodeCompletionDataProvider(content, null, null), ch); return true; } } } else if (ch == '$') { // Provide ${res: as code completion // in an ICSharpCode.Core application if (ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreHostResourceSet(editor.FileName).ResourceFileContent != null || ICSharpCodeCoreResourceResolver.GetICSharpCodeCoreLocalResourceSet(editor.FileName).ResourceFileContent != null) { editor.ShowCompletionWindow(new ICSharpCodeCoreTagCompletionDataProvider(), ch); return true; } } return false; }
public override bool HandleKeyword(SharpDevelopTextAreaControl editor, string word) { switch (word.ToLowerInvariant()) { case "import": editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.Importable), ' '); return true; case "as": case "isa": if (IsInComment(editor)) return false; editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.Type), ' '); return true; default: return base.HandleKeyword(editor, word); } }
public bool CtrlSpace(SharpDevelopTextAreaControl editor) { string ext = Path.GetExtension(editor.FileName); foreach (string extension in extensions) { if (ext.Equals(extension, StringComparison.OrdinalIgnoreCase)) { if (binding == null) { binding = (ICodeCompletionBinding)codon.AddIn.CreateObject(codon.Properties["class"]); } return(binding.CtrlSpace(editor)); } } return(false); }
public bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch) { string ext = Path.GetExtension(editor.FileName); foreach (string extension in extensions) { if (ext.Equals(extension, StringComparison.InvariantCultureIgnoreCase)) { if (binding == null) { binding = (ICodeCompletionBinding)codon.AddIn.CreateObject(codon.Properties["class"]); } return(binding.HandleKeyPress(editor, ch)); } } return(false); }
public override bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch) { if (ch == '[') { int cursor = editor.ActiveTextAreaControl.Caret.Offset; for (int i = cursor - 1; i > 0; i--) { char c = editor.Document.GetCharAt(i); if (c == '\n' || c == '(' || c == ',') { // -> Attribute completion editor.ShowCompletionWindow(new AttributesDataProvider(ExpressionFinder.BooAttributeContext.Instance), ch); return true; } if (!char.IsWhiteSpace(c)) break; } } return base.HandleKeyPress(editor, ch); }
protected void ShowInsight(SharpDevelopTextAreaControl editor, MethodInsightDataProvider dp, ICollection <ResolveResult> parameters, char charTyped) { int paramCount = parameters.Count; dp.SetupDataProvider(editor.FileName, editor.ActiveTextAreaControl.TextArea); List <IMethodOrProperty> methods = dp.Methods; if (methods.Count == 0) { return; } bool overloadIsSure; if (methods.Count == 1) { overloadIsSure = true; dp.DefaultIndex = 0; } else { IReturnType[] argumentTypes = new IReturnType[paramCount + 1]; int i = 0; foreach (ResolveResult rr in parameters) { if (rr != null) { argumentTypes[i] = rr.ResolvedType; } i++; } IMethodOrProperty result = Dom.CSharp.OverloadResolution.FindOverload( methods, argumentTypes, true, false, out overloadIsSure); dp.DefaultIndex = methods.IndexOf(result); } editor.ShowInsightWindow(dp); if (overloadIsSure) { IMethodOrProperty method = methods[dp.DefaultIndex]; if (paramCount < method.Parameters.Count) { IParameter param = method.Parameters[paramCount]; ProvideContextCompletion(editor, param.ReturnType, charTyped); } } }
protected bool ProvideContextCompletion(SharpDevelopTextAreaControl editor, IReturnType expected, char charTyped) { if (expected == null) { return(false); } IClass c = expected.GetUnderlyingClass(); if (c == null) { return(false); } if (c.ClassType == ClassType.Enum) { CtrlSpaceCompletionDataProvider cdp = new CtrlSpaceCompletionDataProvider(); cdp.ForceNewExpression = true; ContextCompletionDataProvider cache = new ContextCompletionDataProvider(cdp); cache.activationKey = charTyped; cache.GenerateCompletionData(editor.FileName, editor.ActiveTextAreaControl.TextArea, charTyped); ICompletionData[] completionData = cache.CompletionData; Array.Sort(completionData); for (int i = 0; i < completionData.Length; i++) { CodeCompletionData ccd = completionData[i] as CodeCompletionData; if (ccd != null && ccd.Class != null) { if (ccd.Class.FullyQualifiedName == expected.FullyQualifiedName) { cache.DefaultIndex = i; break; } } } if (cache.DefaultIndex >= 0) { if (charTyped != ' ') { cdp.InsertSpace = true; } editor.ShowCompletionWindow(cache, charTyped); return(true); } } return(false); }
bool DoCaseCompletion(SharpDevelopTextAreaControl editor) { ICSharpCode.TextEditor.Caret caret = editor.ActiveTextAreaControl.Caret; NRefactoryResolver r = new NRefactoryResolver(ParserService.CurrentProjectContent, LanguageProperties.CSharp); if (r.Initialize(editor.FileName, caret.Line + 1, caret.Column + 1)) { AST.INode currentMember = r.ParseCurrentMember(editor.Text); if (currentMember != null) { CaseCompletionSwitchFinder ccsf = new CaseCompletionSwitchFinder(caret.Line + 1, caret.Column + 1); currentMember.AcceptVisitor(ccsf, null); if (ccsf.bestStatement != null) { r.RunLookupTableVisitor(currentMember); ResolveResult rr = r.ResolveInternal(ccsf.bestStatement.SwitchExpression, ExpressionContext.Default); if (rr != null && rr.ResolvedType != null) { return ProvideContextCompletion(editor, rr.ResolvedType, ' '); } } } } return false; }
public PNTabItem(string moduleName) { InitializeComponent(); DeclarationNode = new TreeNode("Declaration"); ModelNode = new TreeNode("Models"); TreeNode treeNode8 = new TreeNode("Petri Nets Model", new TreeNode[] { DeclarationNode, ModelNode }); MenuButton_SetError.Visible = false; //treeNode8.Name = "Root"; treeNode8.Text = "Petri Nets"; this.TreeView_Structure.Nodes.AddRange(new TreeNode[] { treeNode8 }); //AssertionNode.Name = "Declaration"; DeclarationNode.StateImageIndex = 0; //AssertionNode.Text = "Declaration"; ModelNode.Name = "Models"; ModelNode.StateImageIndex = 1; //ModelNode.Text = "Processes"; AddEventHandlerForButtons(); textEditorControl = new SharpDevelopTextAreaControl(); textEditorControl.Dock = DockStyle.Fill; textEditorControl.ContextMenuStrip = EditorContextMenuStrip; textEditorControl.BorderStyle = BorderStyle.Fixed3D; textEditorControl.Visible = true; this.splitContainer1.Panel2.Controls.Add(textEditorControl); this.TabText = Resources.Document_ + counter; counter++; textEditorControl.FileNameChanged += new EventHandler(_EditorControl_FileNameChanged); textEditorControl.TextChanged += new EventHandler(textEditorControl_TextChanged); textEditorControl.Tag = this; this.Padding = new Padding(2, 2, 2, 2); this.DockableAreas = DockAreas.Document; secondaryViewContentCollection = new SecondaryViewContentCollection(this); InitFiles(); file = FileService.CreateUntitledOpenedFile(TabText, new byte[] { }); file.CurrentView = this; textEditorControl.FileName = file.FileName; files.Clear(); files.Add(file); this.SetSyntaxLanguage(moduleName); textEditorControl.Document.FoldingManager.FoldingStrategy = new FoldingStrategy(); // Highlight the matching bracket or not... this.textEditorControl.ShowMatchingBracket = true; this.textEditorControl.BracketMatchingStyle = BracketMatchingStyle.Before; HostCallbackImplementation.Register(this); CodeCompletionKeyHandler.Attach(this, textEditorControl); ToolTipProvider.Attach(this, textEditorControl); pcRegistry = new ProjectContentRegistry(); // Default .NET 2.0 registry // Persistence lets SharpDevelop.Dom create a cache file on disk so that // future starts are faster. // It also caches XML documentation files in an on-disk hash table, thus // reducing memory usage. pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(), "CSharpCodeCompletion")); myProjectContent = new DefaultProjectContent(); myProjectContent.Language = LanguageProperties.CSharp; this.TreeView_Structure.HideSelection = false; splitContainer1.SplitterDistance = 100; addProcessToolStripMenuItem.PerformClick(); this.TreeView_Structure.ExpandAll(); Button_AddNewNail.Visible = false; //show the declaration TreeView_Structure.SelectedNode = DeclarationNode; TreeView_Structure_NodeMouseDoubleClick(null, new TreeNodeMouseClickEventArgs(DeclarationNode, MouseButtons.Left, 2, 0, 0)); }
bool ShowNewCompletion(SharpDevelopTextAreaControl editor) { CSharpExpressionFinder ef = CreateExpressionFinder(editor.FileName); int cursor = editor.ActiveTextAreaControl.Caret.Offset; string documentToCursor = editor.Document.GetText(0, cursor); ExpressionResult expressionResult = ef.FindExpression(documentToCursor, cursor); LoggingService.Debug("ShowNewCompletion: expression is " + expressionResult); if (expressionResult.Context.IsObjectCreation) { LineSegment currentLine = editor.Document.GetLineSegmentForOffset(cursor); string lineText = editor.Document.GetText(currentLine.Offset, cursor - currentLine.Offset); // when the new follows an assignment, improve code-completion by detecting the // type of the variable that is assigned to if (lineText.Replace(" ", "").EndsWith("=new")) { int pos = lineText.LastIndexOf('='); ExpressionContext context = FindExactContextForNewCompletion(editor, documentToCursor, currentLine, pos); if (context != null) expressionResult.Context = context; } editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(expressionResult.Context), ' '); return true; } return false; }
protected void ShowInsight(SharpDevelopTextAreaControl editor, MethodInsightDataProvider dp, ICollection <ResolveResult> parameters, char charTyped) { int paramCount = parameters.Count; dp.SetupDataProvider(editor.FileName, editor.ActiveTextAreaControl.TextArea); List <IMethodOrProperty> methods = dp.Methods; if (methods.Count == 0) { return; } bool overloadIsSure; if (methods.Count == 1) { overloadIsSure = true; dp.DefaultIndex = 0; } else { IReturnType[] parameterTypes = new IReturnType[paramCount + 1]; int i = 0; foreach (ResolveResult rr in parameters) { if (rr != null) { parameterTypes[i] = rr.ResolvedType; } i++; } IReturnType[][] tmp; int[] ranking = MemberLookupHelper.RankOverloads(methods, parameterTypes, true, out overloadIsSure, out tmp); bool multipleBest = false; int bestRanking = -1; int best = 0; for (i = 0; i < ranking.Length; i++) { if (ranking[i] > bestRanking) { bestRanking = ranking[i]; best = i; multipleBest = false; } else if (ranking[i] == bestRanking) { multipleBest = true; } } if (multipleBest) { overloadIsSure = false; } dp.DefaultIndex = best; } editor.ShowInsightWindow(dp); if (overloadIsSure) { IMethodOrProperty method = methods[dp.DefaultIndex]; if (paramCount < method.Parameters.Count) { IParameter param = method.Parameters[paramCount]; ProvideContextCompletion(editor, param.ReturnType, charTyped); } } }
protected bool InsightRefreshOnComma(SharpDevelopTextAreaControl editor, char ch) { // Show MethodInsightWindow or IndexerInsightWindow NRefactoryResolver r = new NRefactoryResolver(ParserService.CurrentProjectContent, languageProperties); Location cursorLocation = new Location(editor.ActiveTextAreaControl.Caret.Column + 1, editor.ActiveTextAreaControl.Caret.Line + 1); if (r.Initialize(editor.FileName, cursorLocation.Y, cursorLocation.X)) { TextReader currentMethod = r.ExtractCurrentMethod(editor.Text); if (currentMethod != null) { ILexer lexer = ParserFactory.CreateLexer(language, currentMethod); Token token; InspectedCall call = new InspectedCall(Location.Empty, null); call.parent = call; while ((token = lexer.NextToken()) != null && token.kind != eofToken && token.Location < cursorLocation) { if (token.kind == commaToken) { call.commas.Add(token.Location); } else if (token.kind == openParensToken || token.kind == openBracketToken || token.kind == openBracesToken) { call = new InspectedCall(token.Location, call); } else if (token.kind == closeParensToken || token.kind == closeBracketToken || token.kind == closeBracesToken) { call = call.parent; } } int offset = LocationToOffset(editor, call.start); if (offset >= 0 && offset < editor.Document.TextLength) { char c = editor.Document.GetCharAt(offset); if (c == '(') { ShowInsight(editor, new MethodInsightDataProvider(offset, true), ResolveCallParameters(editor, call), ch); return(true); } else if (c == '[') { ShowInsight(editor, new IndexerInsightDataProvider(offset, true), ResolveCallParameters(editor, call), ch); return(true); } else { LoggingService.Warn("Expected '(' or '[' at start position"); } } } } return(false); }
public virtual bool CtrlSpace(SharpDevelopTextAreaControl editor) { CtrlSpaceCompletionDataProvider provider = new CtrlSpaceCompletionDataProvider(); provider.AllowCompleteExistingExpression = true; editor.ShowCompletionWindow(provider, '\0'); return true; }
public virtual bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch) { switch (ch) { case '(': if (enableMethodInsight && CodeCompletionOptions.InsightEnabled) { editor.ShowInsightWindow(new MethodInsightDataProvider()); return true; } else { return false; } case '[': if (enableIndexerInsight && CodeCompletionOptions.InsightEnabled) { editor.ShowInsightWindow(new IndexerInsightDataProvider()); return true; } else { return false; } case '<': if (enableXmlCommentCompletion) { editor.ShowCompletionWindow(new CommentCompletionDataProvider(), ch); return true; } else { return false; } case '.': if (enableDotCompletion) { editor.ShowCompletionWindow(new CodeCompletionDataProvider(), ch); return true; } else { return false; } case ' ': if (!CodeCompletionOptions.KeywordCompletionEnabled) return false; string word = editor.GetWordBeforeCaret(); if (word != null) return HandleKeyword(editor, word); else return false; default: return false; } }
protected IList<ResolveResult> ResolveCallParameters(SharpDevelopTextAreaControl editor, InspectedCall call) { List<ResolveResult> rr = new List<ResolveResult>(); int offset = LocationToOffset(editor, call.start); string documentText = editor.Text; int newOffset; foreach (Location loc in call.commas) { newOffset = LocationToOffset(editor, loc); if (newOffset < 0) break; string text = editor.Document.GetText(offset+1,newOffset-(offset+1)); rr.Add(ParserService.Resolve(new ExpressionResult(text), loc.Line, loc.Column, editor.FileName, documentText)); } // the last argument is between the last comma and the caret position newOffset = editor.ActiveTextAreaControl.Caret.Offset; if (offset < newOffset) { string text = editor.Document.GetText(offset+1,newOffset-(offset+1)); rr.Add(ParserService.Resolve(new ExpressionResult(text), editor.ActiveTextAreaControl.Caret.Line + 1, editor.ActiveTextAreaControl.Caret.Column + 1, editor.FileName, documentText)); } return rr; }
protected IMember GetCurrentMember(SharpDevelopTextAreaControl editor) { ICSharpCode.TextEditor.Caret caret = editor.ActiveTextAreaControl.Caret; NRefactoryResolver r = new NRefactoryResolver(languageProperties); if (r.Initialize(ParserService.GetParseInformation(editor.FileName), caret.Line + 1, caret.Column + 1)) { return r.CallingMember; } else { return null; } }
public virtual bool HandleKeyword(SharpDevelopTextAreaControl editor, string word) { // DefaultCodeCompletionBinding does not support Keyword handling, but this // method can be overridden return(false); }
protected void ShowInsight(SharpDevelopTextAreaControl editor, MethodInsightDataProvider dp, ICollection<ResolveResult> parameters, char charTyped) { int paramCount = parameters.Count; dp.SetupDataProvider(editor.FileName, editor.ActiveTextAreaControl.TextArea); List<IMethodOrProperty> methods = dp.Methods; if (methods.Count == 0) return; bool overloadIsSure; if (methods.Count == 1) { overloadIsSure = true; dp.DefaultIndex = 0; } else { IReturnType[] argumentTypes = new IReturnType[paramCount + 1]; int i = 0; foreach (ResolveResult rr in parameters) { if (rr != null) { argumentTypes[i] = rr.ResolvedType; } i++; } IMethodOrProperty result = Dom.CSharp.OverloadResolution.FindOverload( methods, argumentTypes, true, false, out overloadIsSure); dp.DefaultIndex = methods.IndexOf(result); } editor.ShowInsightWindow(dp); if (overloadIsSure) { IMethodOrProperty method = methods[dp.DefaultIndex]; if (paramCount < method.Parameters.Count) { IParameter param = method.Parameters[paramCount]; ProvideContextCompletion(editor, param.ReturnType, charTyped); } } }
protected bool ProvideContextCompletion(SharpDevelopTextAreaControl editor, IReturnType expected, char charTyped) { if (expected == null) return false; IClass c = expected.GetUnderlyingClass(); if (c == null) return false; if (c.ClassType == ClassType.Enum) { CtrlSpaceCompletionDataProvider cdp = new CtrlSpaceCompletionDataProvider(); ContextCompletionDataProvider cache = new ContextCompletionDataProvider(cdp); cache.activationKey = charTyped; cache.GenerateCompletionData(editor.FileName, editor.ActiveTextAreaControl.TextArea, charTyped); ICompletionData[] completionData = cache.CompletionData; Array.Sort(completionData, DefaultCompletionData.Compare); for (int i = 0; i < completionData.Length; i++) { CodeCompletionData ccd = completionData[i] as CodeCompletionData; if (ccd != null && ccd.Class != null) { if (ccd.Class.FullyQualifiedName == expected.FullyQualifiedName) { cache.DefaultIndex = i; break; } } } if (cache.DefaultIndex >= 0) { if (charTyped != ' ') cdp.InsertSpace = true; editor.ShowCompletionWindow(cache, charTyped); return true; } } return false; }
protected bool InsightRefreshOnComma(SharpDevelopTextAreaControl editor, char ch) { // Show MethodInsightWindow or IndexerInsightWindow NRefactoryResolver r = new NRefactoryResolver(languageProperties); Location cursorLocation = new Location(editor.ActiveTextAreaControl.Caret.Column + 1, editor.ActiveTextAreaControl.Caret.Line + 1); if (r.Initialize(ParserService.GetParseInformation(editor.FileName), cursorLocation.Y, cursorLocation.X)) { TextReader currentMethod = r.ExtractCurrentMethod(editor.Text); if (currentMethod != null) { ILexer lexer = ParserFactory.CreateLexer(language, currentMethod); Token token; InspectedCall call = new InspectedCall(Location.Empty, null); call.parent = call; while ((token = lexer.NextToken()) != null && token.Kind != eofToken && token.Location < cursorLocation) { if (token.Kind == commaToken) { call.commas.Add(token.Location); } else if (token.Kind == openParensToken || token.Kind == openBracketToken || token.Kind == openBracesToken) { call = new InspectedCall(token.Location, call); } else if (token.Kind == closeParensToken || token.Kind == closeBracketToken || token.Kind == closeBracesToken) { call = call.parent; } } int offset = LocationToOffset(editor, call.start); if (offset >= 0 && offset < editor.Document.TextLength) { char c = editor.Document.GetCharAt(offset); if (c == '(') { ShowInsight(editor, new MethodInsightDataProvider(offset, true), ResolveCallParameters(editor, call), ch); return true; } else if (c == '[') { ShowInsight(editor, new IndexerInsightDataProvider(offset, true), ResolveCallParameters(editor, call), ch); return true; } else { LoggingService.Warn("Expected '(' or '[' at start position"); } } } } return false; }
public override bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch) { CSharpExpressionFinder ef = new CSharpExpressionFinder(editor.FileName); int cursor = editor.ActiveTextAreaControl.Caret.Offset; ExpressionContext context = null; if (ch == '(') { if (CodeCompletionOptions.KeywordCompletionEnabled) { switch (editor.GetWordBeforeCaret().Trim()) { case "for": case "lock": context = ExpressionContext.Default; break; case "using": context = ExpressionContext.TypeDerivingFrom(ParserService.CurrentProjectContent.GetClass("System.IDisposable"), false); break; case "catch": context = ExpressionContext.TypeDerivingFrom(ParserService.CurrentProjectContent.GetClass("System.Exception"), false); break; case "foreach": case "typeof": case "sizeof": case "default": context = ExpressionContext.Type; break; } } if (context != null) { if (IsInComment(editor)) return false; editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(context), ch); return true; } else if (EnableMethodInsight && CodeCompletionOptions.InsightEnabled) { editor.ShowInsightWindow(new MethodInsightDataProvider()); return true; } return false; } else if (ch == '[') { LineSegment line = editor.Document.GetLineSegmentForOffset(cursor); if (TextUtilities.FindPrevWordStart(editor.Document, cursor) <= line.Offset) { // [ is first character on the line // -> Attribute completion editor.ShowCompletionWindow(new AttributesDataProvider(ParserService.CurrentProjectContent), ch); return true; } } else if (ch == ',' && CodeCompletionOptions.InsightRefreshOnComma && CodeCompletionOptions.InsightEnabled) { if (InsightRefreshOnComma(editor, ch)) return true; } else if(ch == '=') { LineSegment curLine = editor.Document.GetLineSegmentForOffset(cursor); string documentText = editor.Text; int position = editor.ActiveTextAreaControl.Caret.Offset - 2; if (position > 0 && (documentText[position + 1] == '+')) { ExpressionResult result = ef.FindFullExpression(documentText, position); if(result.Expression != null) { ResolveResult resolveResult = ParserService.Resolve(result, editor.ActiveTextAreaControl.Caret.Line + 1, editor.ActiveTextAreaControl.Caret.Column + 1, editor.FileName, documentText); if (resolveResult != null && resolveResult.ResolvedType != null) { IClass underlyingClass = resolveResult.ResolvedType.GetUnderlyingClass(); if (underlyingClass != null && underlyingClass.IsTypeInInheritanceTree(ParserService.CurrentProjectContent.GetClass("System.MulticastDelegate"))) { EventHandlerCompletitionDataProvider eventHandlerProvider = new EventHandlerCompletitionDataProvider(result.Expression, resolveResult); eventHandlerProvider.InsertSpace = true; editor.ShowCompletionWindow(eventHandlerProvider, ch); } } } } else if (position > 0) { ExpressionResult result = ef.FindFullExpression(documentText, position); if(result.Expression != null) { ResolveResult resolveResult = ParserService.Resolve(result, editor.ActiveTextAreaControl.Caret.Line + 1, editor.ActiveTextAreaControl.Caret.Column + 1, editor.FileName, documentText); if (resolveResult != null && resolveResult.ResolvedType != null) { if (ProvideContextCompletion(editor, resolveResult.ResolvedType, ch)) { return true; } } } } } else if (ch == ';') { LineSegment curLine = editor.Document.GetLineSegmentForOffset(cursor); // don't return true when inference succeeds, otherwise the ';' won't be added to the document. TryDeclarationTypeInference(editor, curLine); } return base.HandleKeyPress(editor, ch); }
/// <summary> /// Determines if the specified character should trigger resource resolve attempt and possibly code completion at the current position. /// </summary> protected override bool CompletionPossible(SharpDevelopTextAreaControl editor, char ch) { return ch == '(' || ch == '['; }
public virtual bool HandleKeyword(SharpDevelopTextAreaControl editor, string word) { // DefaultCodeCompletionBinding does not support Keyword handling, but this // method can be overridden return false; }
public virtual bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch) { switch (ch) { case '(': if (enableMethodInsight && CodeCompletionOptions.InsightEnabled) { editor.ShowInsightWindow(new MethodInsightDataProvider()); return(true); } else { return(false); } case '[': if (enableIndexerInsight && CodeCompletionOptions.InsightEnabled) { editor.ShowInsightWindow(new IndexerInsightDataProvider()); return(true); } else { return(false); } case '<': if (enableXmlCommentCompletion) { editor.ShowCompletionWindow(new CommentCompletionDataProvider(), ch); return(true); } else { return(false); } case '.': if (enableDotCompletion) { editor.ShowCompletionWindow(new CodeCompletionDataProvider(), ch); return(true); } else { return(false); } case ' ': if (!CodeCompletionOptions.KeywordCompletionEnabled) { return(false); } string word = editor.GetWordBeforeCaret(); if (word != null) { return(HandleKeyword(editor, word)); } else { return(false); } default: return(false); } }
public override bool HandleKeyPress(SharpDevelopTextAreaControl editor, char ch) { CSharpExpressionFinder ef = CreateExpressionFinder(editor.FileName); int cursor = editor.ActiveTextAreaControl.Caret.Offset; ExpressionContext context = null; if (ch == '(') { if (context != null) { if (IsInComment(editor)) return false; editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(context), ch); return true; } else if (EnableMethodInsight && CodeCompletionOptions.InsightEnabled) { editor.ShowInsightWindow(new MethodInsightDataProvider()); return true; } return false; } else if (ch == '[') { LineSegment line = editor.Document.GetLineSegmentForOffset(cursor); if (TextUtilities.FindPrevWordStart(editor.Document, cursor) <= line.Offset) { // [ is first character on the line // -> Attribute completion editor.ShowCompletionWindow(new AttributesDataProvider(ParserService.CurrentProjectContent), ch); return true; } } else if (ch == ',' && CodeCompletionOptions.InsightRefreshOnComma && CodeCompletionOptions.InsightEnabled) { if (InsightRefreshOnComma(editor, ch)) return true; } else if(ch == '=') { LineSegment curLine = editor.Document.GetLineSegmentForOffset(cursor); string documentText = editor.Text; int position = editor.ActiveTextAreaControl.Caret.Offset - 2; if (position > 0 && (documentText[position + 1] == '+')) { ExpressionResult result = ef.FindFullExpression(documentText, position); if(result.Expression != null) { ResolveResult resolveResult = ParserService.Resolve(result, editor.ActiveTextAreaControl.Caret.Line + 1, editor.ActiveTextAreaControl.Caret.Column + 1, editor.FileName, documentText); if (resolveResult != null && resolveResult.ResolvedType != null) { IClass underlyingClass = resolveResult.ResolvedType.GetUnderlyingClass(); if (underlyingClass != null && underlyingClass.IsTypeInInheritanceTree(ParserService.CurrentProjectContent.GetClass("System.MulticastDelegate", 0))) { EventHandlerCompletitionDataProvider eventHandlerProvider = new EventHandlerCompletitionDataProvider(result.Expression, resolveResult); eventHandlerProvider.InsertSpace = true; editor.ShowCompletionWindow(eventHandlerProvider, ch); } } } } else if (position > 0) { ExpressionResult result = ef.FindFullExpression(documentText, position); if(result.Expression != null) { ResolveResult resolveResult = ParserService.Resolve(result, editor.ActiveTextAreaControl.Caret.Line + 1, editor.ActiveTextAreaControl.Caret.Column + 1, editor.FileName, documentText); if (resolveResult != null && resolveResult.ResolvedType != null) { if (ProvideContextCompletion(editor, resolveResult.ResolvedType, ch)) { return true; } } } } } else if (ch == '.') { editor.ShowCompletionWindow(new CSharpCodeCompletionDataProvider(), ch); return true; } else if (ch == '>') { if (IsInComment(editor)) return false; char prevChar = cursor > 1 ? editor.Document.GetCharAt(cursor - 1) : ' '; if (prevChar == '-') { editor.ShowCompletionWindow(new PointerArrowCompletionDataProvider(), ch); return true; } } if (char.IsLetter(ch) && CodeCompletionOptions.CompleteWhenTyping) { if (editor.ActiveTextAreaControl.SelectionManager.HasSomethingSelected) { // allow code completion when overwriting an identifier cursor = editor.ActiveTextAreaControl.SelectionManager.SelectionCollection[0].Offset; int endOffset = editor.ActiveTextAreaControl.SelectionManager.SelectionCollection[0].EndOffset; // but block code completion when overwriting only part of an identifier if (endOffset < editor.Document.TextLength && char.IsLetterOrDigit(editor.Document.GetCharAt(endOffset))) return false; editor.ActiveTextAreaControl.SelectionManager.RemoveSelectedText(); editor.ActiveTextAreaControl.Caret.Position = editor.Document.OffsetToPosition(cursor); } char prevChar = cursor > 1 ? editor.Document.GetCharAt(cursor - 1) : ' '; bool afterUnderscore = prevChar == '_'; if (afterUnderscore) { cursor--; prevChar = cursor > 1 ? editor.Document.GetCharAt(cursor - 1) : ' '; } if (!char.IsLetterOrDigit(prevChar) && prevChar != '.' && !IsInComment(editor)) { ExpressionResult result = ef.FindExpression(editor.Text, cursor); LoggingService.Debug("CC: Beginning to type a word, result=" + result); if (result.Context != ExpressionContext.IdentifierExpected) { editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(result.Context) { ShowTemplates = true, AllowCompleteExistingExpression = afterUnderscore }, '\0'); } } } return base.HandleKeyPress(editor, ch); }
bool TryDeclarationTypeInference(SharpDevelopTextAreaControl editor, LineSegment curLine) { string lineText = editor.Document.GetText(curLine.Offset, curLine.Length); ILexer lexer = ParserFactory.CreateLexer(SupportedLanguage.CSharp, new System.IO.StringReader(lineText)); Token typeToken = lexer.NextToken(); if (typeToken.kind == CSTokens.Question) { if (lexer.NextToken().kind == CSTokens.Identifier) { Token t = lexer.NextToken(); if (t.kind == CSTokens.Assign) { string expr = lineText.Substring(t.col); LoggingService.Debug("DeclarationTypeInference: >" + expr + "<"); ResolveResult rr = ParserService.Resolve(new ExpressionResult(expr), editor.ActiveTextAreaControl.Caret.Line + 1, t.col, editor.FileName, editor.Document.TextContent); if (rr != null && rr.ResolvedType != null) { ClassFinder context = new ClassFinder(editor.FileName, editor.ActiveTextAreaControl.Caret.Line, t.col); if (CodeGenerator.CanUseShortTypeName(rr.ResolvedType, context)) CSharpAmbience.Instance.ConversionFlags = ConversionFlags.None; else CSharpAmbience.Instance.ConversionFlags = ConversionFlags.UseFullyQualifiedNames; string typeName = CSharpAmbience.Instance.Convert(rr.ResolvedType); editor.Document.Replace(curLine.Offset + typeToken.col - 1, 1, typeName); editor.ActiveTextAreaControl.Caret.Column += typeName.Length - 1; return true; } } } } return false; }
bool IsInComment(SharpDevelopTextAreaControl editor) { CSharpExpressionFinder ef = new CSharpExpressionFinder(editor.FileName); int cursor = editor.ActiveTextAreaControl.Caret.Offset - 1; return ef.FilterComments(editor.Document.GetText(0, cursor + 1), ref cursor) == null; }
public override bool HandleKeyword(SharpDevelopTextAreaControl editor, string word) { // TODO: Assistance writing Methods/Fields/Properties/Events: // use public/static/etc. as keywords to display a list with other modifiers // and possible return types. switch (word) { case "using": if (IsInComment(editor)) return false; // TODO: check if we are inside class/namespace editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.Namespace), ' '); return true; case "as": case "is": if (IsInComment(editor)) return false; editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.Type), ' '); return true; case "override": if (IsInComment(editor)) return false; editor.ShowCompletionWindow(new OverrideCompletionDataProvider(), ' '); return true; case "new": return ShowNewCompletion(editor); case "case": if (IsInComment(editor)) return false; return DoCaseCompletion(editor); case "return": if (IsInComment(editor)) return false; IMember m = GetCurrentMember(editor); if (m != null) { return ProvideContextCompletion(editor, m.ReturnType, ' '); } else { goto default; } default: return base.HandleKeyword(editor, word); } }
ExpressionContext FindExactContextForNewCompletion(SharpDevelopTextAreaControl editor, string documentToCursor, LineSegment currentLine, int pos) { CSharpExpressionFinder ef = CreateExpressionFinder(editor.FileName); // find expression on left hand side of the assignment ExpressionResult lhsExpr = ef.FindExpression(documentToCursor, currentLine.Offset + pos); if (lhsExpr.Expression != null) { ResolveResult rr = ParserService.Resolve(lhsExpr, currentLine.LineNumber, pos, editor.FileName, editor.Text); if (rr != null && rr.ResolvedType != null) { ExpressionContext context; IClass c; if (rr.ResolvedType.IsArrayReturnType) { // when creating an array, all classes deriving from the array's element type are allowed IReturnType elementType = rr.ResolvedType.CastToArrayReturnType().ArrayElementType; c = elementType != null ? elementType.GetUnderlyingClass() : null; context = ExpressionContext.TypeDerivingFrom(elementType, false); } else { // when creating a normal instance, all non-abstract classes deriving from the type // are allowed c = rr.ResolvedType.GetUnderlyingClass(); context = ExpressionContext.TypeDerivingFrom(rr.ResolvedType, true); } if (c != null && context.ShowEntry(c)) { // Try to suggest an entry (List<int> a = new => suggest List<int>). string suggestedClassName = LanguageProperties.CSharp.CodeGenerator.GenerateCode( CodeGenerator.ConvertType( rr.ResolvedType, new ClassFinder(ParserService.GetParseInformation(editor.FileName), editor.ActiveTextAreaControl.Caret.Line + 1, editor.ActiveTextAreaControl.Caret.Column + 1) ), ""); if (suggestedClassName != c.Name) { // create an IClass instance that includes the type arguments in its name context.SuggestedItem = new RenamedClass(c, suggestedClassName); } else { context.SuggestedItem = c; } } return context; } } return null; }
bool ShowNewCompletion(SharpDevelopTextAreaControl editor) { CSharpExpressionFinder ef = new CSharpExpressionFinder(editor.FileName); int cursor = editor.ActiveTextAreaControl.Caret.Offset; ExpressionContext context = ef.FindExpression(editor.Document.GetText(0, cursor) + " T.", cursor + 2).Context; if (context.IsObjectCreation) { editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(context), ' '); return true; } return false; }
protected int LocationToOffset(SharpDevelopTextAreaControl editor, Location loc) { if (loc.IsEmpty || loc.Line - 1 >= editor.Document.TotalNumberOfLines) return -1; LineSegment seg = editor.Document.GetLineSegment(loc.Line - 1); return seg.Offset + Math.Min(loc.Column, seg.Length) - 1; }
// ******************************************************************************************************************************** /// <summary> /// Determines if the specified character should trigger resource resolve attempt and possibly code completion at the current position. /// </summary> protected abstract bool CompletionPossible(SharpDevelopTextAreaControl editor, char ch);