/// <summary>
        /// Finds any intellisense declarations relative to the current caret position.
        /// </summary>
        /// <param name="lineNum">Caret line</param>
        /// <param name="colNum">Caret column</param>
        /// <param name="reason">Reason for parse</param>
        /// <returns>IntellisenseDeclarations</returns>
        public IntellisenseDeclarations Find(int lineNum, int colNum, ParseReason reason)
        {
            string line = lineView.GetTextUptoPosition(lineNum, colNum);
            bool isImportStatement = line.StartsWith(ImportKeyword);
            var declarations = (isImportStatement) ? new ImportIntellisenseDeclarations() : new IntellisenseDeclarations();

            if (line.EndsWith(".") || reason == ParseReason.MemberSelect)
            {
                if (isImportStatement) line = line.Remove(0, ImportKeyword.Length).Trim(); // remove import keyword

                // Member Select: it's easier to check if the line ends in a . rather than checking
                // the parse reason, because the parse reason may not technically be correct.
                // for example "Syst[ctrl+space]" is a complete word, while "System[.]" is
                // a member lookup; however, "System.[ctrl+space]" is a member lookup but it gets
                // reported as a complete word because of the shortcut used.
                // So it's easier just to say any lines ending in "." are member lookups, and everything
                // else is complete word.
                AddMemberLookupDeclarations(declarations, line, lineNum);

                return declarations;
            }

            // Everything else (complete word)
            return GetScopedIntellisenseDeclarations(lineNum);
        }
        public IntellisenseDeclarations Find(CaretLocation caretLocation, ParseReason parseReason)
        {
            if (!caretLocation.IsValid)
                throw new ArgumentException("Caret location has not been provided, cannot continue.");

            return Find(caretLocation.Line.Value, caretLocation.Column.Value, parseReason);
        }
Beispiel #3
0
        public void FloatVariableDeclaration()
        {
            var results = RunCompiler(
//@"f as single" // does not work
                @"f = 1.0f"
                );

            var      mToken   = results.GetMappedToken(0, 0);
            TextSpan ts       = new TextSpan();
            TextSpan expected = new TextSpan();

            expected.iStartLine  = 0;
            expected.iEndLine    = 0;
            expected.iStartIndex = 0;
            expected.iEndIndex   = 1;

            Assert.NotNull(mToken);
            Assert.AreEqual(2, mToken.Nodes.Count);
            Assert.IsInstanceOf(typeof(MappedReferenceExpression), (mToken.Nodes[1]));
            Assert.AreEqual("(local variable) f as single", mToken.GetDataTiptext(out ts));
            Assert.AreEqual(ts, expected);

            mToken.Goto(out ts);
            TokenInfo   ti = new TokenInfo();
            ParseReason pr = new ParseReason();

            mToken.GetDeclarations(ti, pr);
        }
Beispiel #4
0
        public void BoolTypeReference()
        {
            var results = RunCompiler(
                @"a as bool"
                );

            var      mToken   = results.GetMappedToken(0, 5);
            TextSpan ts       = new TextSpan();
            TextSpan expected = new TextSpan();

            expected.iStartLine  = 0;
            expected.iEndLine    = 0;
            expected.iStartIndex = 5;
            expected.iEndIndex   = 9;


            Assert.NotNull(mToken);
            Assert.AreEqual(2, mToken.Nodes.Count);
            Assert.IsInstanceOf(typeof(MappedTypeReference), (mToken.Nodes[1]));
            Assert.AreEqual("struct bool", mToken.GetDataTiptext(out ts));
            Assert.AreEqual(ts, expected);

            mToken.Goto(out ts);
            TokenInfo   ti = new TokenInfo();
            ParseReason pr = new ParseReason();

            mToken.GetDeclarations(ti, pr);
        }
Beispiel #5
0
        public void BoolTypeReference()
        {
            var results = RunCompiler(
            @"a as bool"
                );

            var mToken = results.GetMappedToken(0, 5);
            TextSpan ts = new TextSpan();
            TextSpan expected = new TextSpan();
            expected.iStartLine = 0;
            expected.iEndLine = 0;
            expected.iStartIndex = 5;
            expected.iEndIndex = 9;

            Assert.NotNull(mToken);
            Assert.AreEqual(2, mToken.Nodes.Count);
            Assert.IsInstanceOf(typeof(MappedTypeReference), (mToken.Nodes[1]));
            Assert.AreEqual("struct bool", mToken.GetDataTiptext(out ts));
            Assert.AreEqual(ts, expected);

            mToken.Goto(out ts);
            TokenInfo ti = new TokenInfo();
            ParseReason pr = new ParseReason();
            mToken.GetDeclarations(ti, pr);
        }
        // ParseReason.CompleteWord
        // ParseReason.DisplayMemberList
        // ParseReason.MemberSelect
        // ParseReason.MemberSelectAndHilightBraces
        public override Microsoft.VisualStudio.Package.Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            IList<Declaration> declarations;
            switch (reason)
            {
                case ParseReason.CompleteWord:
                    var tokenInfo = GetTokenInfoOfFirstTokenOnLine(view, line, col);

                    if (tokenInfo.Token == (int)GherkinTerm.Step)
                        declarations = resolver.FindMembers(StepProvider, Grammar, line, col);
                    else
                        declarations = resolver.FindCompletions(StepProvider, Grammar, line, col);
                    break;

                case ParseReason.DisplayMemberList:
                case ParseReason.MemberSelect:
                case ParseReason.MemberSelectAndHighlightBraces:
                    declarations = resolver.FindMembers(StepProvider, Grammar, line, col);
                    break;
                default:
                    throw new ArgumentException("reason");
            }

            return new Declarations(declarations);
        }
Beispiel #7
0
        //public override TextSpan CommentLines(TextSpan span, string lineComment) {
        //    // Calculate minimal position of non-space char
        //    // at lines in selected span.
        //    var minNonEmptyPosition = 0;

        //    for (var i = span.iStartLine; i <= span.iEndLine; ++i) {
        //        var line = base.GetLine(i);

        //        if (line.Trim().Length <= 0)
        //            continue;

        //        var spaceLen = line.Replace(line.TrimStart(), "").Length;
        //        spaceLen = line.Length - line.TrimStart().Length;
        //        //line.TrimStart();

        //        if (minNonEmptyPosition == 0 || spaceLen < minNonEmptyPosition)
        //            minNonEmptyPosition = spaceLen;
        //    }

        //    // insert line comment at calculated position.
        //    var editMgr = new EditArray(this, null, true, "CommentLines");

        //    for (var i = span.iStartLine; i <= span.iEndLine; ++i) {
        //        var text = base.GetLine(i);

        //        if (minNonEmptyPosition <= text.Length && text.Trim().Length > 0) {
        //            var commentSpan = new TextSpan();

        //            commentSpan.iStartLine = commentSpan.iEndLine = i;
        //            commentSpan.iStartIndex = commentSpan.iEndIndex = minNonEmptyPosition;

        //            editMgr.Add(new EditSpan(commentSpan, lineComment));
        //        }
        //    }

        //    editMgr.ApplyEdits();

        //    // adjust original span to fit comment symbols
        //    span.iEndIndex += lineComment.Length;
        //    return span;
        //}

        public override AuthoringSink CreateAuthoringSink(ParseReason reason, int line, int col)
        {
            //throw new NotImplementedException("Ooops");
            //AuthoringSink as1 = new AuthoringSink(reason, line, col, 100);
            //as1.ProcessHiddenRegions = true;
            //return as1;
            return(base.CreateAuthoringSink(reason, line, col));
        }
 public override Declarations GetDeclarations(MVTI.IVsTextView view,
                                              int line,
                                              int col,
                                              TokenInfo info,
                                              ParseReason reason)
 {
     return null;
 }
Beispiel #9
0
 public override Declarations GetDeclarations(IVsTextView view,
                                              int line,
                                              int col,
                                              TokenInfo info,
                                              ParseReason reason)
 {
     return(null);
 }
Beispiel #10
0
        public override ParseRequest BeginParse(int line, int idx, TokenInfo info, ParseReason reason, IVsTextView view, ParseResultHandler callback)
        {
            //return base.BeginParse(line, idx, info, reason, view, callback);

            switch (reason)
            {
            case ParseReason.Autos:
                break;

            case ParseReason.Check:
                m_parse_reason = ParseReason.Check;
                NSUtil.DebugPrintAlways("NSSource BeginParse Check");
                //m_scanner.m_fullscan = 3;
                //Recolorize(0,LineCount);
                //m_scanner.m_fullscan = false;
                //Recolorize(0, this.LineCount);
                break;

            //return null;
            case ParseReason.CodeSpan:
                break;

            case ParseReason.CompleteWord:
                break;

            case ParseReason.DisplayMemberList:
                break;

            case ParseReason.Goto:
                break;

            case ParseReason.MemberSelect:
                break;

            case ParseReason.MemberSelectAndHighlightBraces:
                break;

            case ParseReason.MethodTip:
                break;

            case ParseReason.None:
                break;

            case ParseReason.QuickInfo:
                break;

            case ParseReason.HighlightBraces:
            case ParseReason.MatchBraces:
                Trace.Assert(false);
                break;

            default:
                break;
            }

            return(base.BeginParse(line, idx, info, reason, view, callback));
            //return null;
        }
Beispiel #11
0
        public override Declarations GetDeclarations(IVsTextView view,
                                                     int line,
                                                     int col,
                                                     TokenInfo info,
                                                     ParseReason reason)
        {
            var ret = new EpochDeclarations();

            return(ret);
        }
Beispiel #12
0
        public Declarations GetDeclarations(TokenInfo info, ParseReason reason)
        {
            var node = Nodes.Where(n => n.Declarations.GetCount() > 0).FirstOrDefault();

            if (node == null)
            {
                return(new BooDeclarations());
            }
            return(node.Declarations);
        }
Beispiel #13
0
        internal Declarations GetDeclarations(int line, int col, TokenInfo info, ParseReason reason)
        {
            var token = fileNode.GetAdjacentMappedToken(line, col);

            if (token == null)
            {
                return(new BooDeclarations());
            }
            return(token.GetDeclarations(info, reason));
        }
        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            Debug.WriteLine("GetDeclarations token type: {0}", info.Type);

            string t = null;

            if (info.Type != TokenType.Delimiter)
            {
                info.Type = TokenType.Keyword;
                view.GetTextStream(line, col - (info.EndIndex - info.StartIndex + 1), line, col, out t);

                Debug.WriteLine("GetDeclarations text: {0}", t);
            }

            return new AphidDeclarations(this, t);
        }
        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            System.Diagnostics.Debug.Print("GetDeclarations line({0}), col({1}), TokenInfo(type {2} at {3}-{4} triggers {5}), reason({6})",
                line, col, info.Type, info.StartIndex, info.EndIndex, info.Trigger, reason);

            IList<Declaration> declarations = module.GetAttributesAt(line + 1, info.StartIndex);
            PythonDeclarations pythonDeclarations = new PythonDeclarations(declarations, language);

            //Show snippets according to current language context
            if (IsContextRightForSnippets(line, info)) {
                ((PythonLanguage)language).AddSnippets(ref pythonDeclarations);
            }

            //Sort statement completion items in alphabetical order
            pythonDeclarations.Sort();
            return pythonDeclarations;
        }
Beispiel #16
0
        public override Declarations GetDeclarations(IVsTextView view, int lineNum, int col, TokenInfo info, ParseReason reason)
        {
            string line = source.GetLine(lineNum);

            if (line.StartsWith(ImportKeyword))
            {
                // handle this separately from normal intellisense, because:
                //  a) the open import statement will have broken the document
                //  b) we don't need the doc anyway, all imports would be external to the current file
                // only problem is, the top level namespaces (i.e. System, Boo, Microsoft) should be
                // usable from within code too, so we need some way of parsing and caching them and
                // making them available everywhere
                return GetImportIntellisenseDeclarations(line);
            }

            return GetScopedIntellisenseDeclarations(lineNum);
        }
        // ParseReason.CompleteWord
        // ParseReason.DisplayMemberList
        // ParseReason.MemberSelect
        // ParseReason.MemberSelectAndHilightBraces
        public override Microsoft.VisualStudio.Package.Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            IList<Declaration> declarations;
            switch (reason) {
                case ParseReason.CompleteWord:
                    declarations = resolver.FindCompletions(null, line, col);
                    break;
                case ParseReason.DisplayMemberList:
                case ParseReason.MemberSelect:
                case ParseReason.MemberSelectAndHighlightBraces:
                    declarations = resolver.FindMembers(null, line, col);
                    break;
                default:
                    throw new ArgumentException("reason");
            }

            return new Babel.Declarations(declarations);
        }
Beispiel #18
0
        // ParseReason.CompleteWord
        // ParseReason.DisplayMemberList
        // ParseReason.MemberSelect
        // ParseReason.MemberSelectAndHilightBraces
        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            //IList<Declaration> declarations;
            //switch (reason) {
            //    case ParseReason.CompleteWord:
            //        declarations = resolver.FindCompletions(parseResult, line, col);
            //        break;
            //    case ParseReason.DisplayMemberList:
            //    case ParseReason.MemberSelect:
            //    case ParseReason.MemberSelectAndHighlightBraces:
            //        declarations = resolver.FindMembers(parseResult, line, col);
            //        break;
            //    default:
            //        throw new ArgumentException("reason");
            //}

            //return new Declarations(declarations);
            return null;
        }
Beispiel #19
0
        public override void Completion(IVsTextView textView, TokenInfo info,
                                        ParseReason reason)
        {
            bool oldValue = LanguageService.Preferences.EnableAsyncCompletion;

            if (reason == ParseReason.MemberSelect ||
                reason == ParseReason.MemberSelectAndHighlightBraces)
            {
                if (info.Token == (int)CMakeToken.VariableStart ||
                    info.Token == (int)CMakeToken.VariableStartEnv)
                {
                    // Disable asynchronous parsing for member selection requests
                    // involving variables.  It doesn't work properly when a parameter
                    // information tool tip is visible.
                    LanguageService.Preferences.EnableAsyncCompletion = false;
                }
            }
            base.Completion(textView, info, reason);
            LanguageService.Preferences.EnableAsyncCompletion = oldValue;
        }
Beispiel #20
0
        public void Attribute()
        {
            var results = RunCompiler(
            @"[System.Serializable]
            class Class:
            def constructor():
            pass"
                );

            var mToken = results.GetMappedToken(0, 1);
            Assert.NotNull(mToken);
            Assert.AreEqual(2, mToken.Nodes.Count);
            Assert.IsInstanceOf(typeof(MappedAttribute), (mToken.Nodes[1]));
            Assert.AreEqual(Formats.BooType, mToken.Nodes[1].Format);
            //            Assert.AreEqual("class System.Serializable", mToken.Nodes[1].QuickInfoTip);
            TextSpan ts = new TextSpan();

            mToken.Goto(out ts);
            TokenInfo ti = new TokenInfo();
            ParseReason pr = new ParseReason();
            mToken.GetDeclarations(ti, pr);
        }
Beispiel #21
0
        public void Attribute()
        {
            var results = RunCompiler(
                @"[System.Serializable]
class Class:
	def constructor():
		pass"
                );

            var mToken = results.GetMappedToken(0, 1);

            Assert.NotNull(mToken);
            Assert.AreEqual(2, mToken.Nodes.Count);
            Assert.IsInstanceOf(typeof(MappedAttribute), (mToken.Nodes[1]));
            Assert.AreEqual(Formats.BooType, mToken.Nodes[1].Format);
//            Assert.AreEqual("class System.Serializable", mToken.Nodes[1].QuickInfoTip);
            TextSpan ts = new TextSpan();

            mToken.Goto(out ts);
            TokenInfo   ti = new TokenInfo();
            ParseReason pr = new ParseReason();

            mToken.GetDeclarations(ti, pr);
        }
Beispiel #22
0
 public AuthoringSink(ParseReason reason, int line, int col){
   this.reason = reason;
   this.Errors = new ArrayList();
   this.Line = line;
   this.Column = col;
   this.Names = new StringCollection();
   this.SourceLocations = new ArrayList();
   this.MethodCalls = new MethodCalls();
   this.Spans = new ArrayList();
 }
Beispiel #23
0
        }         // func GetDataTipText

        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            // todo: check corrent token
            return(declarations);
        }         // func GetDeclarations
Beispiel #24
0
        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            Debug.WriteLine("GetDeclarations token type: {0}", info.Type);

            string t = null;

            if (info.Type != TokenType.Delimiter)
            {
                info.Type = TokenType.Keyword;
                view.GetTextStream(line, col - (info.EndIndex - info.StartIndex + 1), line, col, out t);

                Debug.WriteLine("GetDeclarations text: {0}", t);
            }

            return(new AphidDeclarations(this, t));
        }
Beispiel #25
0
 /// <include file='doc\LanguageService.uex' path='docs/doc[@for="ParseRequest.ParseRequest1"]/*' />
 public ParseRequest(int line, int col, TokenInfo info, string src, string fname, ParseReason reason, IVsTextView view, AuthoringSink sink) {
     this.Line = line;
     this.Col = col;
     this.FileName = fname;
     this.Text = src;
     this.Reason = reason;
     this.View = view;
     this.Sink = sink;
     this.TokenInfo = info;
 }
Beispiel #26
0
 /// <include file='doc\LanguageService.uex' path='docs/doc[@for="AuthoringSink.AuthoringSink"]/*' />
 public AuthoringSink(ParseReason reason, int line, int col, int maxErrors) {
     this.reason = reason;
     this.errors = new ArrayList();
     this.line = line;
     this.col = col;
     this.Names = new StringCollection();
     this.SourceLocations = new ArrayList();
     this.MethodCalls = new MethodCalls();
     this.Spans = new ArrayList();
     this.Braces = new ArrayList();
     this.hiddenRegions = new ArrayList();
     this.errorCounts = new int[4];
     this.maxErrors = maxErrors;
 }
Beispiel #27
0
        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            System.Diagnostics.Debug.Print("GetDeclarations line({0}), col({1}), TokenInfo(type {2} at {3}-{4} triggers {5}), reason({6})",
                                           line, col, info.Type, info.StartIndex, info.EndIndex, info.Trigger, reason);

            IList <Declaration> declarations       = module.GetAttributesAt(line + 1, info.StartIndex);
            FoxProDeclarations  FoxProDeclarations = new FoxProDeclarations(declarations, language);

            //Show snippets according to current language context
            if (IsContextRightForSnippets(line, info))
            {
                ((FoxProLanguage)language).AddSnippets(ref FoxProDeclarations);
            }

            //Sort statement completion items in alphabetical order
            FoxProDeclarations.Sort();
            return(FoxProDeclarations);
        }
Beispiel #28
0
 public AdaSink(ParseReason reason, int line, int col, int maxErrors) : base(reason, line, col, maxErrors)
 {
 }
Beispiel #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="textView"></param>
 /// <param name="info"></param>
 /// <param name="reason"></param>
 public override void Completion(IVsTextView textView, TokenInfo info, ParseReason reason)
 {
     base.Completion(textView, info, reason);
 }
Beispiel #30
0
        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            // Declarations x = new Declarations();
            Debug.WriteLine("GetDeclarations");
            if (_targets != null)
            {
                CompletionNode[] nodes = _cdb.GetCandidateList(_targets, false);
                if (nodes != null)
                {
                    return(new SQDeclarations(nodes, _line, _start, _end));
                }
            }

            return(new SQDeclarations(null, _line, _start, _end));
        }
Beispiel #31
0
    public ParseRequest(int line, int col, TokenInfo info, string text, string fname, ParseReason reason, IVsTextView view){
      this.Line = line; this.Col = col;
      this.FileName = fname;
      this.Text = text; this.Reason = reason;
      this.View = view;
      this.Sink = new AuthoringSink(reason, line, col);
      this.TokenInfo = info;
#if LookForMemoryLeaks
      System.GC.Collect();
      this.UsedMemoryAtStartOfRequest = System.GC.GetTotalMemory(true);
#endif
    }
Beispiel #32
0
        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            // Check that the text view is not null.
            if (null == view)
            {
                throw new ArgumentNullException("view");
            }

            // In order to get the correct text for this line we have to figure out if this line
            // contains part of the read-only region of the buffer because this region is not
            // supposed to be used (it is the output of the engine).
            // Use the function exposed by the console window to get the text of the line
            // without the part inside the read-only region.
            string lineText = PythonConsole.TextOfLine(line, col, true);

            if (null == lineText)
            {
                // there is no text to parse, so there is no delaration to return.
                // Return an empty Declarations object.
                return(new MethodDeclarations());
            }

            // Get the text buffer.
            IVsTextLines buffer;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                view.GetBuffer(out buffer));

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

            scanner.SetSource(lineText, 0);

            // Now use the scanner to parse this line and build the list of the tokens.
            List <TokenInfo> tokens       = new List <TokenInfo>();
            TokenInfo        lastToken    = null;
            TokenInfo        currentToken = new TokenInfo();
            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 TokenInfo();
            }

            // Now that we have the tokens we can use them to find the text to pass to the
            // IronPython engine to evaluate the expression.
            if (0 == tokens.Count)
            {
                // If the list of tokens is empty, then return an emty set of declarations.
                return(new MethodDeclarations());
            }

            // Check if the last token is the one that generated the parse request.
            if (tokens[tokens.Count - 1].Trigger == TokenTriggers.None)
            {
                tokens.RemoveAt(tokens.Count - 1);
                if (0 == tokens.Count)
                {
                    return(new MethodDeclarations());
                }
            }

            // Remove the token that generated the request
            if (tokens[tokens.Count - 1].Trigger != TokenTriggers.None)
            {
                tokens.RemoveAt(tokens.Count - 1);
                if (0 == tokens.Count)
                {
                    return(new MethodDeclarations());
                }
            }

            // Now build the string to pass to the engine.
            int    startIndex    = tokens[0].StartIndex;
            int    len           = tokens[tokens.Count - 1].EndIndex - startIndex + 1;
            string engineCommand = string.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                "dir({0})",
                lineText.Substring(startIndex, len));

            MethodDeclarations declarations = new MethodDeclarations();

            try
            {
                IEnumerable members = Engine.Evaluate(engineCommand) as IEnumerable;
                if (null != members)
                {
                    foreach (string member in members)
                    {
                        declarations.AddMethod(member);
                    }
                }
            }
            catch (Exception)
            {
                // Do nothing
            }
            return(declarations);
        }
Beispiel #33
0
 public AuthoringScope ParseSource(string text, int line, int col, string fname, AuthoringSink asink, ParseReason reason){
   this.currentAst = null;
   Compilation compilation = this.GetCompilationFor(fname); 
   Debug.Assert(compilation != null, "no compilation for: "+fname);
   this.currentSymbolTable = compilation.TargetModule;
   switch (reason){
     case ParseReason.CollapsibleRegions:
     case ParseReason.CompleteWord:
     case ParseReason.MatchBraces:
     case ParseReason.HighlightBraces:
     case ParseReason.MemberSelect:
     case ParseReason.MemberSelectExplicit:
     case ParseReason.MethodTip: 
     case ParseReason.QuickInfo:
     case ParseReason.Autos:{
       return this.ParsePartialCompilationUnit(fname, text, line, col, asink, reason);
     }
     case ParseReason.Check:{
       ErrorNodeList errors = new ErrorNodeList();
       this.ParseAndAnalyzeCompilationUnit(fname, text, line, col, errors, compilation, asink);
       this.ReportErrors(fname, errors, asink);
       return this.GetAuthoringScope();
     }
   }
   return null;
 }
 // ParseReason.CompleteWord
 // ParseReason.DisplayMemberList
 // ParseReason.MemberSelect
 // ParseReason.MemberSelectAndHilightBraces
 public override Microsoft.VisualStudio.Package.Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
 {
     return(new Declarations(new List <Declaration>()));
 }
Beispiel #35
0
 public virtual AuthoringScope ParsePartialCompilationUnit(string fname, string text, int line, int col, AuthoringSink asink, ParseReason reason){
   Compilation compilation = this.GetCompilationFor(fname);
   if (line >= 0 && (reason == ParseReason.MemberSelect || reason == ParseReason.MemberSelectExplicit || reason == ParseReason.CompleteWord))
     text = this.Truncate(text, line, col);
   Module savedSymbolTable = this.currentSymbolTable;
   compilation.TargetModule = this.currentSymbolTable = new Module();
   this.currentSymbolTable.AssemblyReferences = savedSymbolTable.AssemblyReferences;
   CompilationUnit partialCompilationUnit = this.ParseCompilationUnit(fname, text, new ErrorNodeList(), compilation, asink);
   compilation.TargetModule = this.currentSymbolTable = savedSymbolTable;
   if (reason != ParseReason.HighlightBraces && reason != ParseReason.MatchBraces){
     MemberFinder memberFinder = this.GetMemberFinder(line+1, col+1);
     memberFinder.Visit(partialCompilationUnit);
     Member unresolvedMember = memberFinder.Member;
     memberFinder.Member = null;
     CompilationUnit cu = this.GetCompilationUnitSnippet(compilation, fname);
     if (cu != null){
       if (unresolvedMember == null){
         //Dealing with a construct that is not part of a type definition, such as a using statement
         this.Resolve(partialCompilationUnit);
       }else{
         memberFinder.Visit(cu);
         if (memberFinder.Member != null)
           this.Resolve(unresolvedMember, memberFinder.Member);
         else
           this.Resolve(partialCompilationUnit); //Symbol table is out of date
       }
     }
   }
   return this.GetAuthoringScope();
 }
Beispiel #36
0
        public override Declarations GetDeclarations(IVsTextView view, int line, int col,
                                                     TokenInfo info, ParseReason reason)
        {
            // If the intellisense parse reason was called before the template could be parsed
            if (_templateNode == null)
            {
                return(null);
            }

            AstNode astNode = _templateNode.GetNodeAt(line + 1, col + 1);

            if (astNode == null)
            {
                Debug.Fail("Null AstNode when attempting to provide IntelliSense in NVelocityAuthoringScope.");
                return(null);
            }

            NVelocityDeclarations declarations = new NVelocityDeclarations();

            if (astNode is NVDesignator)
            {
                List <NVLocalNode> localNodes = _templateNode.GetLocalNodesFromScope(line, col);
                localNodes.Sort(new Comparison <NVLocalNode>(
                                    delegate(NVLocalNode x, NVLocalNode y)
                {
                    return(x.Name.CompareTo(y.Name));
                }));
                foreach (NVLocalNode localNode in localNodes)
                {
                    declarations.Add(new NVelocityDeclaration(localNode.Name, localNode, IntelliSenseIcon.Variable));
                }
            }
            else if (astNode is NVSelector)
            {
                NVTypeNode typeNode = ((NVSelector)astNode).GetParentType();
                if (typeNode is NVClassNode)
                {
                    NVClassNode classNode = (NVClassNode)typeNode;

                    Dictionary <string, NVMethodNode> uniqueMethods = new Dictionary <string, NVMethodNode>();
                    foreach (NVMethodNode methodNode in classNode.Methods)
                    {
                        if (!uniqueMethods.ContainsKey(methodNode.Name))
                        {
                            uniqueMethods.Add(methodNode.Name, methodNode);
                        }
                    }

                    List <NVMethodNode> uniqueMethodsList = new List <NVMethodNode>();
                    foreach (KeyValuePair <string, NVMethodNode> pair in uniqueMethods)
                    {
                        uniqueMethodsList.Add(pair.Value);
                    }

                    uniqueMethodsList.Sort(new Comparison <NVMethodNode>(
                                               delegate(NVMethodNode x, NVMethodNode y)
                    {
                        return(x.Name.CompareTo(y.Name));
                    }));
                    foreach (NVMethodNode methodNode in uniqueMethodsList)
                    {
                        declarations.Add(new NVelocityDeclaration(methodNode.Name, methodNode, IntelliSenseIcon.Method));
                    }
                }
                else
                {
                    if (typeNode == null)
                    {
                        declarations.Add(new NVelocityDeclaration("Error: TypeNode is null", null, IntelliSenseIcon.Error));
                    }
                    else
                    {
                        declarations.Add(new NVelocityDeclaration("Error: Unsupported type for NVSelector " + typeNode.GetType().Name,
                                                                  null, IntelliSenseIcon.Error));
                    }
                }
            }
            else if (astNode is NVDirective)
            {
                NVDirective nvDirective = (NVDirective)astNode;
                if ((col + 1) - astNode.Position.StartPos == 1)
                {
                    // TODO: change the if expression so that it checks if the col is between the # and (
                    //       because you can bring up the intellisense list in the middle of the identifier
                    //       and it should display the list of the directives instead of the view components.
                    List <string> directivesList = new List <string>();
                    directivesList.AddRange(new string[]
                    {
                        "if", "elseif", "else", "end", "foreach", "set", "stop", "component",
                        "blockcomponent", "literal", "macro"
                    });
                    directivesList.Sort();

                    foreach (string directive in directivesList)
                    {
                        declarations.Add(new NVelocityDeclaration(directive, null, IntelliSenseIcon.Macro));
                    }
                }
                else if (nvDirective.Name == "component" || nvDirective.Name == "blockcomponent")
                {
                    List <NVClassNode> viewComponents = _templateNode.GetViewComponentsFromScope();
                    viewComponents.Sort(new Comparison <NVClassNode>(
                                            delegate(NVClassNode x, NVClassNode y)
                    {
                        return(x.Name.CompareTo(y.Name));
                    }));
                    foreach (NVClassNode classNode in viewComponents)
                    {
                        declarations.Add(new NVelocityDeclaration(classNode.Name, classNode, IntelliSenseIcon.Class));
                    }
                }
            }
            else if (astNode is XmlElement)
            {
                string xhtmlSchemaFileName = GetXhtmlSchemaFileName();
                if (string.IsNullOrEmpty(xhtmlSchemaFileName))
                {
                    Debug.Fail("Could not find XHTML schema.");
                    return(declarations);
                }
                XhtmlSchemaProvider xhtmlSchemaProvider = new XhtmlSchemaProvider(xhtmlSchemaFileName);

                XmlElement xmlElement = (XmlElement)astNode;
                if (string.IsNullOrEmpty(xmlElement.Name))
                {
                    if (xmlElement.Parent != null)
                    {
                        if (!xmlElement.Parent.IsSelfClosing && !xmlElement.IsComplete && !xmlElement.Parent.IsComplete)
                        {
                            declarations.Add(new NVelocityDeclaration(string.Format("/{0}>", xmlElement.Parent.Name),
                                                                      null, IntelliSenseIcon.XmlElement));
                        }
                    }

                    foreach (string xhtmlElement in xhtmlSchemaProvider.GetElements())
                    {
                        declarations.Add(new NVelocityDeclaration(xhtmlElement, null, IntelliSenseIcon.XmlElement));
                    }
                }
                else
                {
                    // Retrieve attributes
                    List <string> xhtmlAttributes = xhtmlSchemaProvider.GetAttributes(xmlElement.Name);

                    // Remove attributes that are already used
                    foreach (AstNode attribute in xmlElement.Attributes)
                    {
                        if (attribute is XmlAttribute)
                        {
                            XmlAttribute xmlAttribute = (XmlAttribute)attribute;
                            if (xhtmlAttributes.Contains(xmlAttribute.Name))
                            {
                                xhtmlAttributes.Remove(xmlAttribute.Name);
                            }
                        }
                    }

                    // Add the declarations for the attributes to show
                    foreach (string xhtmlAttribute in xhtmlAttributes)
                    {
                        declarations.Add(new NVelocityDeclaration(xhtmlAttribute, null, IntelliSenseIcon.XmlAttribute));
                    }
                }
            }
            else
            {
                declarations.Add(new NVelocityDeclaration("Error: Context unknown, type is " + astNode.GetType().Name,
                                                          null, IntelliSenseIcon.Error));
            }

            return(declarations);
        }
Beispiel #37
0
 /// <summary>
 /// Called for completions.
 /// </summary>
 public virtual Declarations GetDeclarations(int line, int col, ParseReason reason){
   Scope scope;
   Node node;
   MemberList members = this.GetMembers(line, col, reason, out node, out scope);
   if (members == null) members = new MemberList(); // return empty list then.
   return new Declarations(members, this.helper, node, scope);
 }
 public override Declarations GetDeclarations
     (IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
     => _data.GetDeclarations(view, line, col, info, reason);
Beispiel #39
0
    //  MemberSelectExplicit =>
    //    if node != null then show rele vent stuff only
    //    else show default list
    //  MemberSelect =>
    //    if node != null then show relevent stuff only
    //    dont show anything
    public virtual MemberList GetMembers(int line, int col, ParseReason reason, out Node node, out Scope scope){
      int identContext;
      this.languageService.SearchForNodeAtPosition(line + 1, col + 1, out node, out scope, out identContext);
      if (identContext == IdentifierContexts.NullContext) return null;
      bool doingCompletion = reason == ParseReason.MemberSelect || reason == ParseReason.MemberSelectExplicit || reason == ParseReason.CompleteWord;
      MemberList retList = null;
      QualifiedIdentifier qi = node as QualifiedIdentifier;
      if (qi != null && qi.Identifier.UniqueIdKey == StandardIds.Ctor.UniqueIdKey && (qi.Qualifier is This || qi.Qualifier is Base) && reason == ParseReason.CompleteWord) {
        node = null;
        retList = this.GetMembers(line, col, node, scope);
      } else if ((node as Scope) == scope && scope != null) {
        retList = this.languageService.GetTypesNamespacesAndPrefixes(scope, false, false);
      } else if (node is AttributeNode) {
        retList = this.GetMembers(line, col, (AttributeNode)node, scope);
      } else if (node is ClassExpression) {
        retList = this.GetMembers(line, col, (ClassExpression)node, scope);
      } else if (node is InterfaceExpression) {
        InterfaceExpression ie = (InterfaceExpression)node;
        if (ie.Expression != null && ie.Expression is QualifiedIdentifier)
          retList = this.GetMembers(line, col, ie.Expression as QualifiedIdentifier, scope);
        else
          retList = this.GetMembers(line, col, (InterfaceExpression)node, scope);
      } else if (node is Construct) {
        retList = this.GetMembers(line, col, (Construct)node, scope, doingCompletion);
      } else if (node is UsedNamespace && (node.SourceContext.StartLine == line + 1)) {
        retList = this.languageService.GetNestedNamespaces(((UsedNamespace)node).Namespace, scope);
      } else if (node is AliasDefinition) {
        retList = this.GetMembers(line, col, (AliasDefinition)node, scope);
      } else if (node is Namespace) {
        Namespace ns = (Namespace)node;
        string name = ns.FullName;
        if (name != null && (name.Equals("global:") || name.Length == 0)) {
          Scope iterScope = scope;
          while (iterScope != null && iterScope.OuterScope != null)
            iterScope = iterScope.OuterScope;
          retList = this.languageService.GetNestedNamespacesAndTypes(Identifier.Empty, iterScope);
          goto returnList;
        }
        if (doingCompletion)
          retList = this.FillWithDefaultList(line, col, node, scope);
        else
          retList = this.GetMembers(line, col, ns, scope);
      } else if (node is QualifiedIdentifier) {
        retList = this.GetMembers(line, col, qi, scope);
      } else if (node is TemplateInstance) {
        retList = this.GetMembers(line, col, (TemplateInstance)node, scope);
      } else if (node is TypeExpression) {
        retList = this.GetMembers(line, col, (TypeExpression)node, scope);
      } else if (node is NameBinding) {
        retList = this.GetMembers(line, col, (NameBinding)node, scope, doingCompletion);
      } else if (node is Event || node is Method || node is Property) {
        retList = this.GetMembers(line, col, (Member)node, scope, doingCompletion);
      } else if (node is This) {
        retList = this.GetMembers(line, col, (This)node, scope, doingCompletion);
      } else if (node is Base) {
        retList = this.GetMembers(line, col, (Base)node, scope, doingCompletion);
      } else if (node is Identifier || node is Class || node is Interface) {
        retList = this.FillWithDefaultList(line, col, node, scope);
      }

      if (node == null && (reason == ParseReason.CompleteWord || reason == ParseReason.MemberSelectExplicit)) {
        retList = this.FillWithDefaultList(line, col, node, scope);
      } else if (reason == ParseReason.MethodTip) {
        Class cl = node as Class;
        if (cl != null && cl.IsAssignableTo(SystemTypes.Attribute)) {
          this.suppressAttributeSuffix = true;
          retList = new MemberList();
          MemberList memList = cl.GetConstructors();
          bool showInternal = this.MayAccessInternals(this.languageService.currentSymbolTable, cl);
          if (memList != null) {
            int n = memList.Count;
            for (int i = 0; i < n; ++i) {
              Member mem = memList[i];
              if (mem == null) continue;
              if (mem.IsCompilerControlled) continue;
              if (mem.IsPrivate) continue;
              if (mem.IsFamily || mem.IsFamilyAndAssembly) continue;
              if ((mem.IsAssembly || mem.IsFamilyOrAssembly) && !showInternal) continue;
              retList.Add(mem);
            }
          }
        }
      }

      if (retList != null && reason != ParseReason.MethodTip) {
        retList = this.FilterByContext(retList, identContext);
        this.languageService.AddReleventKeywords(retList, node, scope, identContext);
      }

returnList:
      return retList;
    }
Beispiel #40
0
 /// <include file='doc\LanguageService.uex' path='docs/doc[@for="AuthoringScope.GetDeclarations"]/*' />
 //REVIEW: why pass in the view and the info?
 public abstract Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason);
Beispiel #41
0
        // ParseReason.CompleteWord
        // ParseReason.DisplayMemberList
        // ParseReason.MemberSelect
        // ParseReason.MemberSelectAndHilightBraces
        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            string tokenText;
            var    hr = view.GetTextStream(line, info.StartIndex, line, col, out tokenText);

            IList <Declaration> declarations;

            switch (reason)
            {
            case ParseReason.CompleteWord:
                declarations = resolver.FindCompletions(tokenText, line, col);
                break;

            case ParseReason.DisplayMemberList:
            case ParseReason.MemberSelect:
            case ParseReason.MemberSelectAndHighlightBraces:
                declarations = resolver.FindMembers(parseResult, line, col);
                break;

            default:
                throw new ArgumentException("reason");
            }

            return(new PuppetDeclarations(declarations));
        }
Beispiel #42
0
 /// <include file='doc\LanguageService.uex' path='docs/doc[@for="LanguageService.CreateParseRequest"]/*' />
 public virtual ParseRequest CreateParseRequest(Source s, int line, int idx, TokenInfo info, string sourceText, string fname, ParseReason reason, IVsTextView view) {
     this.isParsing = false; // yes, "false".  It get's set to true in the actual background thread.
     return new ParseRequest(line, idx, info, sourceText, fname, reason, view, s.CreateAuthoringSink(reason, line, idx));
 }
Beispiel #43
0
 public Declarations GetDeclarations
     (IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
 {
     NotImplementedMethod("view", line, col, info, reason);
     return null;
 }
Beispiel #44
0
 public override Declarations GetDeclarations(Microsoft.VisualStudio.TextManager.Interop.IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
 {
     return(new AphidDeclarations());
 }
            /// <summary>
            /// Returns a list of declarations based on the specified reason for parsing.
            /// </summary>
            /// <param name="view">[in] An <see cref="T:Microsoft.VisualStudio.TextManager.Interop.IVsTextView"></see> object that can be used to access the source.</param>
            /// <param name="line">[in] The line number where the parse operation started.</param>
            /// <param name="col">[in] The offset into the line where the parse operation started.</param>
            /// <param name="info">[in] A <see cref="T:Microsoft.VisualStudio.Package.TokenInfo"></see> structure containing information about the token at the specified position.</param>
            /// <param name="reason">[in] The <see cref="T:Microsoft.VisualStudio.Package.ParseReason"></see> value describing what kind of parse operation was completed.</param>
            /// <returns>
            /// If successful returns a <see cref="T:Microsoft.VisualStudio.Package.Declarations"></see> object; otherwise, returns a null value.
            /// </returns>
            public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
            {
                TokenTriggers triggers = info.Trigger;

                if (0 != (triggers & OpenParenthesisTokenTrigger))
                {
                    return(new FactEditorReferenceModeDeclarations(m_LanguageService));
                }
                return(new FactEditorObjectTypeDeclarations(m_LanguageService));
            }
Beispiel #46
0
 public override Declarations GetDeclarations(Microsoft.VisualStudio.TextManager.Interop.IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
 {
     throw new NotImplementedException();
 }
Beispiel #47
0
        // ParseReason.CompleteWord
        // ParseReason.DisplayMemberList
        // ParseReason.MemberSelect
        // ParseReason.MemberSelectAndHilightBraces
        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            //IList<Declaration> declarations;
            //switch (reason) {
            //    case ParseReason.CompleteWord:
            //        declarations = resolver.FindCompletions(parseResult, line, col);
            //        break;
            //    case ParseReason.DisplayMemberList:
            //    case ParseReason.MemberSelect:
            //    case ParseReason.MemberSelectAndHighlightBraces:
            //        declarations = resolver.FindMembers(parseResult, line, col);
            //        break;
            //    default:
            //        throw new ArgumentException("reason");
            //}

            //return new Declarations(declarations);
            return(null);
        }
Beispiel #48
0
 public override Declarations GetDeclarations(IVsTextView view, int lineNum, int col, TokenInfo info, ParseReason reason)
 {
     return declarations.Find(lineNum, col, reason);
 }
Beispiel #49
0
 public override Declarations GetDeclarations(Microsoft.VisualStudio.TextManager.Interop.IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
 {
     return new AphidDeclarations();
 }
Beispiel #50
0
    internal void BeginParse( int line, int idx, TokenInfo info, ParseReason reason, IVsTextView view, ParseResultHandler callback) {
     
      string text = null;
      if (reason == ParseReason.MemberSelect || reason == ParseReason.MethodTip)
        text = this.GetTextUpToLine( line );
      else if (reason == ParseReason.CompleteWord || reason == ParseReason.QuickInfo)
        text = this.GetTextUpToLine( line+1 );
      else
        text = this.GetTextUpToLine( 0 ); // get all the text.      

      string fname = this.GetFilePath();

      this.service.BeginParse(new ParseRequest(line, idx, info, text, fname, reason, view), callback); 
    }
Beispiel #51
0
        /// <summary>
        /// Gets the declarations.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="line">The line.</param>
        /// <param name="col">The col.</param>
        /// <param name="info">The info.</param>
        /// <param name="reason">The reason.</param>
        /// <returns></returns>
        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            if (reason == ParseReason.CompleteWord)
            {
                // Get the declarations from all providers for the scope, Order by Name and project the declarations into Babel.Declarations
                Declaration[] declarations = declarationProviders.SelectMany(provider => provider.GetCompleteWordDeclarations())
                                             .OrderBy(declaration => declaration.Name).Distinct()
                                             .ToArray();

                return(new LuaDeclarations(languageService, declarations));
            }

            if (reason == ParseReason.MemberSelect ||
                reason == ParseReason.MemberSelectAndHighlightBraces)
            {
                // Get the declarations from all providers for the scope, Order by Name and project the declarations into Babel.Declarations
                Declaration[] declarations = declarationProviders.SelectMany(provider => provider.GetMemberSelectDeclarations(qualifiedName))
                                             .OrderBy(declaration => declaration.Name).Distinct(new DeclarationEqualityComparer())
                                             .ToArray();

                return(new LuaDeclarations(languageService, declarations));
            }

            return(new LuaDeclarations(languageService, new Declaration[0]));
        }
        // ParseReason.CompleteWord
        // ParseReason.DisplayMemberList
        // ParseReason.MemberSelect
        // ParseReason.MemberSelectAndHilightBraces
        /*
         * Visual Studio calls this function to get possible declarations and completions
         */
        public override Microsoft.VisualStudio.Package.Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            string currentCommand;
            string startChar;
            //int hResult = view.GetTextStream(line, info.StartIndex, line, info.EndIndex, out currentCommand);
            //int hResult = view.GetTextStream(line, info.StartIndex, line, col, out currentCommand);
            TextSpan[] ts = new TextSpan[1];
            ts[0] = new TextSpan();
            view.GetWordExtent(line, info.StartIndex, (uint)(WORDEXTFLAGS.WORDEXT_FINDTOKEN), ts);
            int hResult = view.GetTextStream(line, ts[0].iStartIndex, line, ts[0].iEndIndex, out currentCommand);
            if (ts[0].iStartIndex > 0)
            {
                view.GetTextStream(line, ts[0].iStartIndex - 1, line, ts[0].iStartIndex, out startChar);
                if (startChar.Equals("#"))
                    currentCommand = startChar;
            }

            ((HLSLResolver)resolver)._source = (HLSLSource)_source;
            if (_source.IsCompletorActive)
                return _source.CompletionSet.Declarations;

            IList<HLSLDeclaration> declarations;
            switch (reason)
            {
                case ParseReason.CompleteWord:
                    declarations = resolver.FindCompletions(currentCommand, line, col);
                    break;
                case ParseReason.DisplayMemberList:
                case ParseReason.MemberSelect:
                case ParseReason.MemberSelectAndHighlightBraces:
                    if(currentCommand.Equals("."))
                        declarations = resolver.FindMembers(parseResult, line, col);
                    else
                        declarations = resolver.FindCompletions(currentCommand, line, col);
                    break;
                default:
                    throw new ArgumentException("reason");
            }

            return new HLSLDeclarations(declarations);
        }
Beispiel #53
0
 public virtual ParseRequest CreateParseRequest(Source s, int line, int idx, TokenInfo info, string sourceText, string fname, ParseReason reason, IVsTextView view);
        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            // Check that the text view is not null.
            if (null == view)
            {
                throw new ArgumentNullException("view");
            }

            // In order to get the correct text for this line we have to figure out if this line
            // contains part of the read-only region of the buffer because this region is not
            // supposed to be used (it is the output of the engine).
            // Use the function exposed by the console window to get the text of the line
            // without the part inside the read-only region.
            string lineText = PythonConsole.TextOfLine(line, col, true);
            if (null == lineText)
            {
                // there is no text to parse, so there is no delaration to return.
                // Return an empty Declarations object.
                return new MethodDeclarations();
            }

            // Get the text buffer.
            IVsTextLines buffer;
            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                view.GetBuffer(out buffer));

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

            // Now use the scanner to parse this line and build the list of the tokens.
            List<TokenInfo> tokens = new List<TokenInfo>();
            TokenInfo lastToken = null;
            TokenInfo currentToken = new TokenInfo();
            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 TokenInfo();
            }

            // Now that we have the tokens we can use them to find the text to pass to the
            // IronPython engine to evaluate the expression.
            if (0 == tokens.Count)
            {
                // If the list of tokens is empty, then return an emty set of declarations.
                return new MethodDeclarations();
            }

            // Check if the last token is the one that generated the parse request.
            if (tokens[tokens.Count - 1].Trigger == TokenTriggers.None)
            {
                tokens.RemoveAt(tokens.Count - 1);
                if (0 == tokens.Count)
                {
                    return new MethodDeclarations();
                }
            }

            // Remove the token that generated the request
            if (tokens[tokens.Count - 1].Trigger != TokenTriggers.None)
            {
                tokens.RemoveAt(tokens.Count - 1);
                if (0 == tokens.Count)
                {
                    return new MethodDeclarations();
                }
            }

            // Now build the string to pass to the engine.
            int startIndex = tokens[0].StartIndex;
            int len = tokens[tokens.Count - 1].EndIndex - startIndex + 1;
            string engineCommand = string.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                "dir({0})",
                lineText.Substring(startIndex, len));

            MethodDeclarations declarations = new MethodDeclarations();
            try
            {
                IEnumerable members = Engine.Evaluate(engineCommand) as IEnumerable;
                if (null != members)
                {
                    foreach (string member in members)
                    {
                        declarations.AddMethod(member);
                    }
                }
            }
            catch (Exception)
            {
                // Do nothing
            }
            return declarations;
        }
Beispiel #55
0
 public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
 {
     if (source == null)
     {
         return(null);
     }
     return(source.GetDeclarations(line, col, info, reason));
 }
Beispiel #56
0
        // ParseReason.CompleteWord
        // ParseReason.DisplayMemberList
        // ParseReason.MemberSelect
        // ParseReason.MemberSelectAndHilightBraces
        public override Microsoft.VisualStudio.Package.Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            IList <Declaration> declarations;

            switch (reason)
            {
            case ParseReason.CompleteWord:
                declarations = resolver.FindCompletions(parseResult, line, col);
                break;

            case ParseReason.DisplayMemberList:
            case ParseReason.MemberSelect:
            case ParseReason.MemberSelectAndHighlightBraces:
                declarations = resolver.FindMembers(parseResult, line, col);
                break;

            default:
                throw new ArgumentException("reason");
            }

            return(new Declarations(declarations));
        }
Beispiel #57
0
 public virtual ParseRequest CreateParseRequest(Source s, int line, int idx, TokenInfo info, string sourceText, string fname, ParseReason reason, IVsTextView view);