void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            int position = session.GetTriggerPoint(session.TextView.TextBuffer).GetPosition(textBuffer.CurrentSnapshot);
            int line     = textBuffer.CurrentSnapshot.GetLineNumberFromPosition(position);
            int column   = position - textBuffer.CurrentSnapshot.GetLineFromPosition(position).Start.Position;

            Microsoft.VisualStudio.IronPythonInference.Modules modules = new Microsoft.VisualStudio.IronPythonInference.Modules();

            IList <Declaration> attributes;

            if (textBuffer.GetReadOnlyExtents(new Span(0, textBuffer.CurrentSnapshot.Length)).Count > 0)
            {
                int start;
                var readWriteText = TextOfLine(textBuffer, line, column, out start, true);
                var module        = modules.AnalyzeModule(new QuietCompilerSink(), textBuffer.GetFileName(), readWriteText);

                attributes = module.GetAttributesAt(1, column - 1);

                foreach (var attribute in GetEngineAttributes(readWriteText, column - start - 1))
                {
                    attributes.Add(attribute);
                }
            }
            else
            {
                var module = modules.AnalyzeModule(new QuietCompilerSink(), textBuffer.GetFileName(), textBuffer.CurrentSnapshot.GetText());

                attributes = module.GetAttributesAt(line + 1, column);
            }

            completionSets.Add(GetCompletions((List <Declaration>)attributes, session));
        }
        void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
        {
            int position = session.GetTriggerPoint(session.TextView.TextBuffer).GetPosition(textBuffer.CurrentSnapshot);
            int line = textBuffer.CurrentSnapshot.GetLineNumberFromPosition(position);
            int column = position - textBuffer.CurrentSnapshot.GetLineFromPosition(position).Start.Position;

            Microsoft.VisualStudio.IronPythonInference.Modules modules = new Microsoft.VisualStudio.IronPythonInference.Modules();

            IList<Declaration> attributes;
            if (textBuffer.GetReadOnlyExtents(new Span(0, textBuffer.CurrentSnapshot.Length)).Count > 0)
            {
                int start;
                var readWriteText = TextOfLine(textBuffer, line, column, out start, true);
                var module = modules.AnalyzeModule(new QuietCompilerSink(), textBuffer.GetFileName(), readWriteText);

                attributes = module.GetAttributesAt(1, column - 1);

                foreach (var attribute in GetEngineAttributes(readWriteText, column - start - 1))
                {
                    attributes.Add(attribute);
                }
            }
            else
            {
                var module = modules.AnalyzeModule(new QuietCompilerSink(), textBuffer.GetFileName(), textBuffer.CurrentSnapshot.GetText());

                attributes = module.GetAttributesAt(line + 1, column);
            }

            completionSets.Add(GetCompletions((List<Declaration>)attributes, session));
        }
        /// <summary>
        /// Gets the errors of the text buffer
        /// </summary>
        /// <param name="textBuffer"></param>
        /// <returns></returns>
        internal IList<ValidationError> GetErrors(ITextBuffer textBuffer)
        {
            var sink = new PyErrorListCompilerSink(textBuffer);
            var modules = new Microsoft.VisualStudio.IronPythonInference.Modules();
            modules.AnalyzeModule(sink, textBuffer.GetFileName(), textBuffer.CurrentSnapshot.GetText());

            return sink.Errors.ToList();
        }
Exemplo n.º 4
0
        public static Module Analyze(Modules modules, CompilerSink sink, string name, string text)
        {
            CompilerContext context = new CompilerContext(name, sink);
            Parser parser = Parser.FromString(state, context, text);
            Statement Statement = parser.ParseFileInput();

            Analyzer analyzer = new Analyzer();
            return analyzer.DoAnalyze(modules, name, Statement);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the errors of the text buffer
        /// </summary>
        /// <param name="textBuffer"></param>
        /// <returns></returns>
        internal IList <ValidationError> GetErrors(ITextBuffer textBuffer)
        {
            var sink    = new PyErrorListCompilerSink(textBuffer);
            var modules = new Microsoft.VisualStudio.IronPythonInference.Modules();

            modules.AnalyzeModule(sink, textBuffer.GetFileName(), textBuffer.CurrentSnapshot.GetText());

            return(sink.Errors.ToList());
        }
        /// <summary>
        /// Returns the list of brace matching spans. Each tuple defines from/to the brace matching should be applied.
        /// It's possible to highlight more than one caracter.
        /// </summary>
        /// <param name="caretLocation"></param>
        /// <returns></returns>
        internal IList<Tuple<SnapshotSpan, SnapshotSpan>> GetBraceMatchingSpans(SnapshotPoint caretLocation)
        {
            var snapshot = caretLocation.Snapshot;

            PyBraceMatchCompilerSink sink = new PyBraceMatchCompilerSink(snapshot);
            Microsoft.VisualStudio.IronPythonInference.Modules modules = new Microsoft.VisualStudio.IronPythonInference.Modules();
            modules.AnalyzeModule(sink, snapshot.TextBuffer.GetFileName(), snapshot.GetText());

            //adjust off-by-one due to conversion from old text buffer system to new system, filtering to only adjust current location
            var newMatches = sink.Matches.Select(m => new Tuple<SnapshotSpan, SnapshotSpan>(new SnapshotSpan(m.Item2.Snapshot, m.Item1.Start.Position + 1, m.Item1.Length), new SnapshotSpan(m.Item2.Snapshot, m.Item2.Start.Position + 1, m.Item2.Length)))
                .Where(t => t.Item1.Contains(caretLocation) || t.Item2.Contains(caretLocation));

            return newMatches.ToList();
        }
        /// <summary>
        /// Returns the list of brace matching spans. Each tuple defines from/to the brace matching should be applied.
        /// It's possible to highlight more than one caracter.
        /// </summary>
        /// <param name="caretLocation"></param>
        /// <returns></returns>
        internal IList <Tuple <SnapshotSpan, SnapshotSpan> > GetBraceMatchingSpans(SnapshotPoint caretLocation)
        {
            var snapshot = caretLocation.Snapshot;

            PyBraceMatchCompilerSink sink = new PyBraceMatchCompilerSink(snapshot);

            Microsoft.VisualStudio.IronPythonInference.Modules modules = new Microsoft.VisualStudio.IronPythonInference.Modules();
            modules.AnalyzeModule(sink, snapshot.TextBuffer.GetFileName(), snapshot.GetText());

            //adjust off-by-one due to conversion from old text buffer system to new system, filtering to only adjust current location
            var newMatches = sink.Matches.Select(m => new Tuple <SnapshotSpan, SnapshotSpan>(new SnapshotSpan(m.Item2.Snapshot, m.Item1.Start.Position + 1, m.Item1.Length), new SnapshotSpan(m.Item2.Snapshot, m.Item2.Start.Position + 1, m.Item2.Length)))
                             .Where(t => t.Item1.Contains(caretLocation) || t.Item2.Contains(caretLocation));

            return(newMatches.ToList());
        }
 public Module(Modules references, string name, GlobalSuite global, Dictionary<ScopeStatement, Scope> scopes)
 {
     this.references = references;
     this.name = name;
     this.scopes = scopes;
     this.global = global;
 }
Exemplo n.º 9
0
        private Module DoAnalyze(Modules modules, string name, Statement root)
        {
            GlobalSuite global = new GlobalSuite(root);
            module = new Module(modules, name, global, scopes);

            ModuleScope modsc;
            module.ModuleScope = modsc = new ModuleScope(module, null, global);

            PushScope(modsc);

            root.Walk(this);

            foreach (FieldAssignment fer in this.fields)
            {
                fer.Infer(module);
            }
            return module;
        }