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 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; }
public virtual bool CtrlSpace(SharpDevelopTextAreaControl editor) { CtrlSpaceCompletionDataProvider provider = new CtrlSpaceCompletionDataProvider(); provider.AllowCompleteExistingExpression = true; editor.ShowCompletionWindow(provider, '\0'); return(true); }
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 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); }
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; } }
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); }
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; }
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); } }
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; }
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 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; }
public override bool HandleKeyword(SharpDevelopTextAreaControl editor, string word) { switch (word) { case "using": if (IsInComment(editor)) return false; ParseInformation parseInfo = ParserService.GetParseInformation(editor.FileName); if (parseInfo != null) { IClass innerMostClass = parseInfo.MostRecentCompilationUnit.GetInnermostClass(editor.ActiveTextAreaControl.Caret.Line + 1, editor.ActiveTextAreaControl.Caret.Column + 1); if (innerMostClass == null) { editor.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(ExpressionContext.Namespace), ' '); } return true; } return false; 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); } }