Exemple #1
0
        IList <ResolveResult> ResolveCallParameters(ITextEditor editor, InspectedCall call)
        {
            List <ResolveResult> rr = new List <ResolveResult>();
            int    offset           = LocationToOffset(editor, call.start);
            string documentText     = editor.Document.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.Caret.Offset;
            if (offset < newOffset)
            {
                string text = editor.Document.GetText(offset + 1, newOffset - (offset + 1));
                rr.Add(ParserService.Resolve(new ExpressionResult(text), editor.Caret.Line, editor.Caret.Column, editor.FileName, documentText));
            }
            return(rr);
        }
Exemple #2
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 InspectedCall(Location start, InspectedCall parent)
 {
     this.start  = start;
     this.parent = parent;
 }
        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);
        }
		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 InspectedCall(Location start, InspectedCall parent)
			{
				this.start = start;
				this.parent = parent;
			}
		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;
		}
Exemple #10
0
        protected IList <ResolveResult> ResolveCallParameters(CodeEditorControl editor, InspectedCall call)
        {
            List <ResolveResult> rr = new List <ResolveResult>();
            int offset = LocationToOffset(editor, call.start);

            string documentText = ScriptControl.Parser.ProjectParser.GetFileContents(editor.FileName);

            offset = documentText.LastIndexOf('(');
            int newOffset;

            foreach (Location loc in call.commas)
            {
                newOffset = LocationToOffset(editor, loc);
                if (newOffset < 0)
                {
                    break;
                }
                TextPoint start = editor.ActiveViewControl.Document.IntPosToPoint(offset);
                TextPoint end   = editor.ActiveViewControl.Document.IntPosToPoint(newOffset);

                TextRange tr   = new TextRange(start.X, start.Y, end.X, end.Y);
                string    text = editor.ActiveViewControl.Document.GetRange(tr);             //.GetText(offset+1,newOffset-(offset+1));
                rr.Add(ScriptControl.Parser.ProjectParser.GetResolver().Resolve(new ExpressionResult(text), loc.Line, loc.Column, editor.ActiveViewControl.FileName, documentText));
            }
            // the last argument is between the last comma and the caret position
            newOffset = editor.ActiveViewControl.Caret.Offset;
            if (offset < newOffset)
            {
                TextPoint start = editor.ActiveViewControl.Document.IntPosToPoint(offset);
                TextPoint end   = editor.ActiveViewControl.Document.IntPosToPoint(newOffset);

                TextRange tr = new TextRange(start.X, start.Y, end.X, end.Y);

                string text = editor.ActiveViewControl.Document.GetRange(tr);                //(offset+1,newOffset-(offset+1));
                rr.Add(ScriptControl.Parser.ProjectParser.GetResolver().Resolve(new ExpressionResult(text),
                                                                                editor.ActiveViewControl.Caret.Position.Y + 1,
                                                                                editor.ActiveViewControl.Caret.Position.X + 1,
                                                                                editor.ActiveViewControl.FileName, documentText));
            }
            return(rr);
        }
Exemple #11
0
        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;
		}