Пример #1
0
            /// <summary>
            /// Gets a list of tokens from the IVsTextLines.
            /// </summary>
            /// <param name="lines">The IVsTextLines of the lines of source to parse.</param>
            /// <param name="service">The language service.</param>
            /// <returns>A list of tokens.</returns>
            public static List <FactTokenInfo> GetTokens(IVsTextLines lines, FactEditorLanguageService service)
            {
                Source source   = service.GetOrCreateSource(lines);
                string lineText = source.GetLine(0);

                // Get the scanner from the language service.
                IScanner scanner = service.GetScanner(lines);

                scanner.SetSource(lineText, 0);

                // Now use the scanner to parse the first line and build the list of the tokens.
                List <FactTokenInfo> tokens       = new List <FactTokenInfo>();
                FactTokenInfo        lastToken    = null;
                FactTokenInfo        currentToken = new FactTokenInfo();
                int state = 0;

                while (scanner.ScanTokenAndProvideInfoAboutIt(currentToken, ref state))
                {
                    if ((null != lastToken) && (currentToken.StartIndex > lastToken.EndIndex + 1))
                    {
                        tokens.Clear();
                    }
                    tokens.Add(currentToken);
                    lastToken    = currentToken;
                    currentToken = new FactTokenInfo();
                }

                return(tokens);
            }
            /// <summary>
            /// Returns a string to be used for a tool tip based on the specified location.
            /// </summary>
            /// <param name="line">[in] The line in the source to look at for a tool tip.</param>
            /// <param name="col">[in] An offset within the line to look at for a tool tip.</param>
            /// <param name="span">A <see cref="T:Microsoft.VisualStudio.TextManager.Interop.TextSpan"></see>
            /// that describes the area over which the cursor can hover before the tool tip is dismissed from view.</param>
            /// <returns>
            /// If successful, returns a string containing the text for the tool tip; otherwise, returns a null value.
            /// </returns>
            public override string GetDataTipText(int line, int col, out TextSpan span)
            {
                // new up the span
                span = new TextSpan();
#if FACTEDITOR_TIPTEXT // Turn this off until it does something useful
                // if the line isn't the first, just return null
                if (line > 0)
                {
                    return(null);
                }

                // get the view of the parse request
                IVsTextView view = m_ParseRequest.View;

                // get the token at the given column index
                FactTokenInfo token = FactTokenHelper.GetTokenAtIndex(col, view, m_LanguageService);

                if (token == null)
                {
                    return(null);
                }

                // populate the span information
                span.iStartLine  = line;
                span.iStartIndex = token.StartIndex;
                span.iEndIndex   = token.EndIndex + 1;

                // if the token does not exist on the model create a document task
                // (that is the squiggly line)
                if (!token.ExistsOnModel)
                {
                    //Source s = m_LanguageService.GetOrCreateSource(view);

                    //if (s != null)
                    //{
                    //    DocumentTask task = s.CreateErrorTaskItem(span, MARKERTYPE.MARKER_SYNTAXERROR, String.Empty);
                    //    task.CanDelete = true;
                    //}
                }

                // return the string to show as the tooltip
                return(String.Format("{0} {1} exist on the model.", token.Value, (token.ExistsOnModel == true) ? "does" : "does not"));
#else // FACTEDITOR_TIPTEXT
                return(null);
#endif // FACTEDITOR_TIPTEXT
            }
Пример #3
0
            /// <summary>
            /// Scan the next token and fills in syntax coloring details about it in tokenInfo.
            /// Implements <see cref="IScanner.ScanTokenAndProvideInfoAboutIt"/>
            /// </summary>
            /// <param name="tokenInfo">Keeps information about the token.</param>
            /// <param name="state">Keeps track of scanner state. In: state after last token. Out: state after current token.</param>
            /// <returns></returns>
            private bool ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state)
            {
                bool foundToken = GetNextToken(m_Offset, tokenInfo, ref state);

                if (foundToken)
                {
                    m_Offset = tokenInfo.EndIndex + 1;

#if FACTEDITOR_TIPTEXT
                    if (tokenInfo is FactTokenInfo)
                    {
                        FactTokenInfo factToken = tokenInfo as FactTokenInfo;
                        factToken.Value         = m_Line.Substring(factToken.StartIndex, factToken.Length);
                        factToken.ExistsOnModel = this.ObjectTypeExists(factToken.Value);
                    }
#endif // FACTEDITOR_TIPTEXT
                }
                return(foundToken);
            }
Пример #4
0
			/// <summary>
			/// Gets a list of tokens from the IVsTextLines.
			/// </summary>
			/// <param name="lines">The IVsTextLines of the lines of source to parse.</param>
			/// <param name="service">The language service.</param>
			/// <returns>A list of tokens.</returns>
			public static List<FactTokenInfo> GetTokens(IVsTextLines lines, FactEditorLanguageService service)
			{
				Source source = service.GetOrCreateSource(lines);
				string lineText = source.GetLine(0);

				// Get the scanner from the language service.
				IScanner scanner = service.GetScanner(lines);
				scanner.SetSource(lineText, 0);

				// Now use the scanner to parse the first line and build the list of the tokens.
				List<FactTokenInfo> tokens = new List<FactTokenInfo>();
				FactTokenInfo lastToken = null;
				FactTokenInfo currentToken = new FactTokenInfo();
				int state = 0;
				while (scanner.ScanTokenAndProvideInfoAboutIt(currentToken, ref state))
				{
					if ((null != lastToken) && (currentToken.StartIndex > lastToken.EndIndex + 1))
					{
						tokens.Clear();
					}
					tokens.Add(currentToken);
					lastToken = currentToken;
					currentToken = new FactTokenInfo();
				}

				return tokens;
			}