Exemple #1
0
        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);
        }
		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;
		}
		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;
		}
        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);
        }