AsmHighlighter.AsmHighlighterLanguageService.ComputeDataTipOnContext C# (CSharp) Метод

ComputeDataTipOnContext() публичный Метод

public ComputeDataTipOnContext ( IVsTextLines textLines, int line, int col, TextSpan &span, string &tipText ) : int
textLines IVsTextLines
line int
col int
span TextSpan
tipText string
Результат int
        public int ComputeDataTipOnContext(IVsTextLines textLines, int line, int col, ref TextSpan span, out string tipText)
        {
            int result = VSConstants.E_NOTIMPL;

            tipText = "";
            span.iStartLine = line;
            span.iStartIndex = col;
            span.iEndLine = line;
            span.iEndIndex = col;

            if (textLines != null)
            {
                // Parse tokens and search for the token below the selection
                AsmHighlighterScanner scanner = AsmHighlighterScannerFactory.GetScanner(textLines);
                string lineOfCode;
                List<TokenInfo> tokenInfoList = scanner.ParseLine(textLines, line, int.MaxValue, out lineOfCode);

                TokenInfo selectedTokenInfo = null;
                foreach (TokenInfo info in tokenInfoList)
                {
                    if (col >= info.StartIndex && col <= info.EndIndex)
                    {
                        selectedTokenInfo = info;
                        break;
                    }
                }

                // If a valid token was found, handle it
                if (selectedTokenInfo != null)
                {
                    AsmHighlighterToken token = (AsmHighlighterToken)selectedTokenInfo.Token;

                    // Display only tip for REGISTER or IDENTIFIER
                    if ((token & AsmHighlighterToken.IS_REGISTER) != 0 || (token & AsmHighlighterToken.IS_NUMBER) != 0 || token == AsmHighlighterToken.IDENTIFIER)
                    {
                        result = VSConstants.S_OK;

                        tipText = lineOfCode.Substring(selectedTokenInfo.StartIndex,
                                                         selectedTokenInfo.EndIndex - selectedTokenInfo.StartIndex + 1);

                        if ((token & AsmHighlighterToken.IS_REGISTER)!=0)
                        {
                            tipText = tipText.ToLower();
                            if (token == AsmHighlighterToken.REGISTER_FPU)
                            {
                                tipText = tipText.Replace("(", "");
                                tipText = tipText.Replace(")", "");
                            }
                        }

                        span.iStartIndex = selectedTokenInfo.StartIndex;
                        span.iEndIndex = selectedTokenInfo.EndIndex + 1;

                        // If in debugging mode, display the value
                        // (This is a workaround instead of going through the Debugger.ExpressionEvaluator long way...)
                        // TODO: ExpressionEvaluator is not working, this is a workaround to display values
                        if (IsDebugging() && (((token & AsmHighlighterToken.IS_REGISTER) != 0) || token == AsmHighlighterToken.IDENTIFIER))
                        {

                            Expression expression = vs.Debugger.GetExpression(tipText, true, 1000);
                            string valueStr = "";

                            // Make a friendly printable version for float/double and numbers
                            try
                            {
                                if (expression.Type.Contains("double"))
                                {
                                    double value = double.Parse(expression.Value);
                                    valueStr = string.Format("{0:r}", value);
                                }
                                else
                                {
                                    long value = long.Parse(expression.Value);
                                    valueStr = string.Format("0x{0:X8}", value);
                                }
                            }
                            catch
                            {
                            }

                            // Print a printable version only if it's valid
                            if (string.IsNullOrEmpty(valueStr))
                            {
                                tipText = string.Format("{0} = {1}", tipText, expression.Value);
                            }
                            else
                            {
                                tipText = string.Format("{0} = {1} = {2}", tipText, valueStr, expression.Value);
                            }

                        }
                    }
                }
            }
            return result;
        }

Usage Example

Пример #1
0
            public override string GetDataTipText(int line, int col, out TextSpan span)
            {
                IVsTextLines textLines = source.GetTextLines();
                string       tipText   = "";

                span = new TextSpan();
                langService.ComputeDataTipOnContext(textLines, line, col, ref span, out tipText);
                return(tipText);
            }