public bool InsightRefreshOnComma(ITextEditor editor, char ch, out IInsightWindow insightWindow) { // Show MethodInsightWindow or IndexerInsightWindow NRefactoryResolver r = new NRefactoryResolver(languageProperties); Location cursorLocation = editor.Caret.Position; if (r.Initialize(ParserService.GetParseInformation(editor.FileName), cursorLocation.Y, cursorLocation.X)) { TextReader currentMethod = r.ExtractCurrentMethod(editor.Document.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 == '(' || c == '[') { var insightProvider = new MethodInsightProvider { LookupOffset = offset }; var insightItems = insightProvider.ProvideInsight(editor); insightWindow = ShowInsight(editor, insightItems, ResolveCallParameters(editor, call), ch); return(insightWindow != null); } else { Core.LoggingService.Warn("Expected '(' or '[' at start position"); } } } } insightWindow = null; return(false); }
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 bool HandleKeyPress(CodeEditor editor, char key) { var sdDocument = editor.Document; var textAreaControl = editor.ActiveTextAreaControl; var textArea = textAreaControl.TextArea; // Do not show completion window for now if we're in a comment. if (IsInComment(editor)) { return(false); } if (key == '(') { // Show MethodInsight window editor.ShowInsightWindow(new CSMethodInsightProvider(editor, textArea.Caret.Offset)); } else if (key == ')') { editor.CloseInsightWindow(); } else if (key == ',') { var parseInfo = ((CSDocument)editor.TextDocument).ParseInfo; var resolver = new NRefactoryResolver(LanguageProperties.CSharp); if (resolver.Initialize(parseInfo, textArea.Caret.Line + 1, textArea.Caret.Column + 1)) { var textReader = resolver.ExtractCurrentMethod(textArea.Document.TextContent); // Find the function name from current offset (go backwards) and save all commas on this bracket level. int bracketCount = -1; int offset = textArea.Caret.Offset; var commaOffsets = new List <int>(); var document = textArea.Document; commaOffsets.Add(offset); while (offset >= 0) { char currentChar = document.GetCharAt(offset); if (currentChar == '(') { bracketCount++; } else if (currentChar == ')') { bracketCount--; } else if (currentChar == ',' && bracketCount == -1) { commaOffsets.Insert(0, offset); } if (bracketCount == 0) { break; } else { offset--; } } // Show MethodInsight window if (offset >= 0) { editor.ShowInsightWindow(new CSMethodInsightProvider(editor, offset, commaOffsets)); } } } else if (key == '.') { editor.ShowCompletionWindow(FCSCompletionProvider, key); } else if (char.IsLetter(key)) { // Delete selected text (which will be overwritten anyways) before starting completion. if (textAreaControl.SelectionManager.HasSomethingSelected) { // allow code completion when overwriting an identifier int cursor = textAreaControl.SelectionManager.SelectionCollection[0].Offset; int endOffset = textAreaControl.SelectionManager.SelectionCollection[0].EndOffset; // but block code completion when overwriting only part of an identifier if (endOffset < sdDocument.TextLength && char.IsLetterOrDigit(sdDocument.GetCharAt(endOffset))) { return(false); } textAreaControl.SelectionManager.RemoveSelectedText(); textAreaControl.Caret.Position = sdDocument.OffsetToPosition(cursor); } var document = editor.TextDocument as CSDocument; var finder = document.ExpressionFinder; try { var expressionResult = finder.FindExpression(editor.Document.TextContent, editor.ActiveTextAreaControl.Caret.Offset); if (expressionResult.Context != ExpressionContext.IdentifierExpected) { editor.ShowCompletionWindow(FCtrlSpaceCompletionProvider, key); } } catch (Exception e) { Debug.WriteLine(e.Message); } } 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 bool InsightRefreshOnComma(ITextEditor editor, char ch, out IInsightWindow insightWindow) { // Show MethodInsightWindow or IndexerInsightWindow NRefactoryResolver r = new NRefactoryResolver(languageProperties); Location cursorLocation = editor.Caret.Position; if (r.Initialize(ParserService.GetParseInformation(editor.FileName), cursorLocation.Y, cursorLocation.X)) { TextReader currentMethod = r.ExtractCurrentMethod(editor.Document.Text); if (currentMethod != null) { ILexer lexer = ParserFactory.CreateLexer(language, currentMethod); Token token; InspectedCall call = new InspectedCall(Location.Empty, null); call.parent = call; // HACK MINI PARSER // The following code tries to find the current nested call until the caret position (= cursorLocation) is // reached. call.commas contains all commas up to the caret position. // DOES NOT HANDLE GENERICS CORRECTLY! This is sufficient for overload "search", because if we miss one // overload it does not matter. But if we highlight the wrong parameter (see below) it DOES MATTER! 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 == '(' || c == '[') { var insightProvider = new MethodInsightProvider { LookupOffset = offset }; var insightItems = insightProvider.ProvideInsight(editor); // find highlighted parameter // see mini parser description above; the number of recognized parameters is the index // of the current parameter! var parameters = ResolveCallParameters(editor, call); highlightedParameter = parameters.Count; insightWindow = ShowInsight(editor, insightItems, parameters, ch); return(insightWindow != null); } else { LoggingService.Warn("Expected '(' or '[' at start position"); } } } } insightWindow = null; return(false); }
public bool InsightRefreshOnComma(ITextEditor editor, char ch, out IInsightWindow insightWindow) { // Show MethodInsightWindow or IndexerInsightWindow NRefactoryResolver r = new NRefactoryResolver(languageProperties); Location cursorLocation = editor.Caret.Position; if (r.Initialize(ParserService.GetParseInformation(editor.FileName), cursorLocation.Y, cursorLocation.X)) { TextReader currentMethod = r.ExtractCurrentMethod(editor.Document.Text); if (currentMethod != null) { ILexer lexer = ParserFactory.CreateLexer(language, currentMethod); Token token; InspectedCall call = new InspectedCall(Location.Empty, null); call.parent = call; // HACK MINI PARSER // The following code tries to find the current nested call until the caret position (= cursorLocation) is // reached. call.commas contains all commas up to the caret position. // DOES NOT HANDLE GENERICS CORRECTLY! This is sufficient for overload "search", because if we miss one // overload it does not matter. But if we highlight the wrong parameter (see below) it DOES MATTER! 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 == '(' || c == '[') { var insightProvider = new MethodInsightProvider { LookupOffset = offset }; var insightItems = insightProvider.ProvideInsight(editor); // find highlighted parameter // see mini parser description above; the number of recognized parameters is the index // of the current parameter! var parameters = ResolveCallParameters(editor, call); highlightedParameter = parameters.Count; insightWindow = ShowInsight(editor, insightItems, parameters, ch); return insightWindow != null; } else { Core.LoggingService.Warn("Expected '(' or '[' at start position"); } } } } insightWindow = null; return false; }
protected bool InsightRefreshOnComma(CodeEditorControl editor, char ch) { // Show MethodInsightWindow or IndexerInsightWindow NRefactoryResolver r = new NRefactoryResolver(ScriptControl.Parser.ProjectParser.CurrentProjectContent, languageProperties); Location cursorLocation = new Location(editor.ActiveViewControl.Caret.Position.X + 1, editor.ActiveViewControl.Caret.Position.Y + 1); if (r.Initialize(editor.ActiveViewControl.FileName, cursorLocation.Y, cursorLocation.X)) { TextReader currentMethod = r.ExtractCurrentMethod(ScriptControl.Parser.ProjectParser.GetFileContents(editor.FileName)); 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); string docText = ScriptControl.Parser.ProjectParser.GetFileContents(editor.FileName); offset = docText.LastIndexOf('('); //int offset = editor.ActiveViewControl.Document.PointToIntPos(new TextPoint(call.start.X,call.start.Y));//, call.start); if (offset >= 0 && offset < docText.Length) { char c = (char)docText.Substring(offset, 1).ToCharArray(0, 1)[0]; 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 bool InsightRefreshOnComma(ITextEditor editor, char ch, out IInsightWindow insightWindow) { // Show MethodInsightWindow or IndexerInsightWindow NRefactoryResolver r = new NRefactoryResolver(languageProperties); Location cursorLocation = editor.Caret.Position; if (r.Initialize(ParserService.GetParseInformation(editor.FileName), cursorLocation.Y, cursorLocation.X)) { TextReader currentMethod = r.ExtractCurrentMethod(editor.Document.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 == '(' || c == '[') { var insightProvider = new MethodInsightProvider { LookupOffset = offset }; var insightItems = insightProvider.ProvideInsight(editor); insightWindow = ShowInsight(editor, insightItems, ResolveCallParameters(editor, call), ch); return insightWindow != null; } else { Core.LoggingService.Warn("Expected '(' or '[' at start position"); } } } } insightWindow = null; return false; }