Esempio n. 1
0
        /// <summary>
        /// Changes the analysis entry to <paramref name="entry"/> if the current
        /// entry matches <paramref name="ifCurrent"/>. Returns the current analysis
        /// entry, regardless of whether it changed or not.
        /// </summary>
        public AnalysisEntry TrySetAnalysisEntry(AnalysisEntry entry, AnalysisEntry ifCurrent)
        {
            var previous = Interlocked.CompareExchange(ref _analysisEntry, entry, ifCurrent);

            if (previous != ifCurrent)
            {
                return(previous);
            }

            if (previous != null)
            {
                previous.AnalysisComplete -= AnalysisEntry_AnalysisComplete;
                previous.ParseComplete    -= AnalysisEntry_ParseComplete;
                previous.Analyzer.BufferDetached(previous, Buffer);
            }
            if (entry != null)
            {
                entry.AnalysisComplete += AnalysisEntry_AnalysisComplete;
                entry.ParseComplete    += AnalysisEntry_ParseComplete;
            }

            OnNewAnalysisEntry(entry);

            return(entry);
        }
Esempio n. 2
0
        internal async Task RefreshNavigationsFromAnalysisEntry(AnalysisEntry analysisEntry)
        {
            var dropDownBar = _dropDownBar;

            if (dropDownBar == null)
            {
                return;
            }

            var navigations = await _uiThread.InvokeTask(() => analysisEntry.Analyzer.GetNavigationsAsync(_textView));

            lock (_navigationsLock) {
                _navigations = navigations;
                for (int i = 0; i < _curSelection.Length; i++)
                {
                    _curSelection[i] = -1;
                }
            }

            Action callback = () => CaretPositionChanged(
                this,
                new CaretPositionChangedEventArgs(
                    _textView,
                    _textView.Caret.Position,
                    _textView.Caret.Position
                    )
                );

            try {
                await _dispatcher.BeginInvoke(callback, DispatcherPriority.Background);
            } catch (TaskCanceledException) {
            }
        }
Esempio n. 3
0
 public ExtractedMethodCreator(VsProjectAnalyzer analyzer, AnalysisEntry file, ITextView view, AP.ExtractMethodResponse initialExtraction)
 {
     _analyzer      = analyzer;
     _analysisEntry = file;
     _view          = view;
     LastExtraction = initialExtraction;
 }
Esempio n. 4
0
        /// <summary>
        /// Wired to parser event for when the parser has completed parsing a new tree and we need
        /// to update the navigation bar with the new data.
        /// </summary>
        private async void ParserOnNewParseTree(AnalysisEntry entry)
        {
            var dropDownBar = _dropDownBar;

            if (dropDownBar != null)
            {
                var navigations = await _analysisEntry.Analyzer.GetNavigationsAsync(_textView);

                lock (_navigationsLock) {
                    _navigations = navigations;
                    for (int i = 0; i < _curSelection.Length; i++)
                    {
                        _curSelection[i] = -1;
                    }
                }

                Action callback = () => CaretPositionChanged(
                    this,
                    new CaretPositionChangedEventArgs(
                        _textView,
                        _textView.Caret.Position,
                        _textView.Caret.Position
                        )
                    );

                try {
                    await _dispatcher.BeginInvoke(callback, DispatcherPriority.Background);
                } catch (TaskCanceledException) {
                }
            }
        }
Esempio n. 5
0
 public NPLSyntaxErrorTagger(NPLSyntaxErrorTaggerProvider provider, ITextBuffer buffer)
 {
     _buffer                      = buffer;
     _syntaxErrorTags             = new List <ITagSpan <ErrorTag> >();
     _analysisEntry               = AnalysisEntryInitializer.Initialize(provider.ServiceProvider, buffer);
     _analysisEntry.NewParseTree += OnNewParseTree;
 }
Esempio n. 6
0
        public void Analyze(object param)
        {
            var asmDef = (param as AssemblyDefinition);

            foreach (var tDef in asmDef.MainModule.GetAllTypes())
            {
                foreach (var mDef in tDef.Methods.Where(x => x.HasBody))
                {
                    foreach (var instr in mDef.Body.Instructions)
                    {
                        if (instr.OpCode.OperandType == Mono.Cecil.Cil.OperandType.InlineMethod)
                        {
                            if (instr.Operand.ToString().Contains("System.Reflection"))
                            {
                                LocalValues.Add(true);
                                break;
                            }
                        }
                    }
                }
            }

            if (LocalValues.Count == 0)
            {
                LocalValues.Add(false);
            }

            Entry = new AnalysisEntry(LocalValues[0]);
        }
Esempio n. 7
0
        internal static AnalysisEntry GetAnalysisAtCaretSingletonMode(this ITextBuffer textBuffer)
        {
            AnalysisEntry entry = null;

            textBuffer.Properties.TryGetProperty(typeof(AnalysisEntry), out entry);
            return(entry);
        }
Esempio n. 8
0
        /// <summary>
        /// Changes the analysis entry to <paramref name="entry"/> if the current
        /// entry matches <paramref name="ifCurrent"/>. Returns the current analysis
        /// entry, regardless of whether it changed or not.
        /// </summary>
        public AnalysisEntry TrySetAnalysisEntry(AnalysisEntry entry, AnalysisEntry ifCurrent)
        {
            var previous = Interlocked.CompareExchange(ref _analysisEntry, entry, ifCurrent);

            if (previous != ifCurrent)
            {
                TraceWithStack("FailedToSetAnalysisEntry", previous?.Analyzer, entry?.Analyzer, ifCurrent?.Analyzer);
                return(previous);
            }

            if (previous != null)
            {
                previous.AnalysisComplete -= AnalysisEntry_AnalysisComplete;
                previous.ParseComplete    -= AnalysisEntry_ParseComplete;
                previous.Analyzer.BufferDetached(previous, Buffer);
            }
            if (entry != null)
            {
                entry.AnalysisComplete += AnalysisEntry_AnalysisComplete;
                entry.ParseComplete    += AnalysisEntry_ParseComplete;

                Interlocked.Exchange(ref _waitingForEntry, null)?.TrySetResult(entry);
            }

            TraceWithStack("TrySetAnalysisEntry", entry?.Analyzer, ifCurrent?.Analyzer);
            OnNewAnalysisEntry(entry);

            return(entry);
        }
Esempio n. 9
0
        public void Analyze(object param)
        {
            int size;
            var ico = NativeHelper.ExtractIcon(param as string, out size);

            LocalValues.Add(Tuple.Create(ico, size));
            Entry = new AnalysisEntry(LocalValues[0]);
        }
Esempio n. 10
0
        internal static AnalysisEntry GetAnalysisAtCaretProjectMode(this ITextBuffer textBuffer, IServiceProvider serviceProvider)
        {
            var           service = serviceProvider.GetEntryService();
            AnalysisEntry entry   = null;

            service?.TryGetAnalysisEntry(textBuffer, out entry);
            return(entry);
        }
Esempio n. 11
0
        public void Analyze(object param)
        {
            var asmDef        = (param as AssemblyDefinition);
            var targetRuntime = asmDef.MainModule.Runtime;

            LocalValues.Add(targetRuntime);

            Entry = new AnalysisEntry(LocalValues[0]);
        }
Esempio n. 12
0
        public void Analyze(object param)
        {
            var asmDef = (param as AssemblyDefinition);
            var ep     = asmDef.EntryPoint;

            var @params = ep.Parameters;

            LocalValues.Add(@params);
            Entry = new AnalysisEntry(LocalValues[0]);
        }
Esempio n. 13
0
        internal static bool TryGetPythonProjectEntry(this ITextBuffer buffer, out AnalysisEntry entry)
        {
            AnalysisEntry e;

            if (buffer.TryGetAnalysisEntry(out e) && (entry = e as AnalysisEntry) != null)
            {
                return(true);
            }
            entry = null;
            return(false);
        }
        public void Analyze(object param)
        {
            _asmDef = (param as AssemblyDefinition);

            foreach (var @ref in RecursiveReferenceIdentifier())
            {
                LocalValues.Add(@ref);
            }

            Entry = new AnalysisEntry(LocalValues.ToArray());
        }
Esempio n. 15
0
 public SimpleLocationInfo(VsProjectAnalyzer analyzer, IServiceProvider serviceProvider, string searchText, AnalysisLocation locInfo, StandardGlyphGroup glyphType) {
     _serviceProvider = serviceProvider;
     _locationInfo = locInfo;
     _glyphType = glyphType;
     _pathText = GetSearchDisplayText();
     AnalysisEntry entry = analyzer.GetAnalysisEntryFromPath(_locationInfo.FilePath);
     if (entry != null) {
         _lineText = entry.GetLine(_locationInfo.Line);
     } else {
         _lineText = "";
     }
 }
Esempio n. 16
0
        /// <summary>
        /// Construct the classifier and define search tokens
        /// </summary>
        internal NPLClassifier(ITextBuffer textBuffer,
                               IClassificationTypeRegistryService typeService, NPLClassifierProvider provider)
        {
            _textBuffer = textBuffer;
            _tokens     = new TokenList();

            IServiceProvider serviceProvider = provider.ServiceProvider as IServiceProvider;

            _analysisEntry = AnalysisEntryInitializer.Initialize(serviceProvider, textBuffer);
            _analysisEntry.NewParseTree += OnNewParseTree;
            InitializeTypeMapping(typeService);
        }
Esempio n. 17
0
        public void Analyze(object param)
        {
            var asmDef = (param as AssemblyDefinition);
            var subSystem = asmDef.MainModule.Kind;

            if (subSystem == ModuleKind.Dll)
                throw new BadImageFormatException("Dll not supported");

            LocalValues.Add(subSystem);

            Entry = new AnalysisEntry(LocalValues[0]);
        }
Esempio n. 18
0
        public NPLOutliningTagger(NPLOutliningTaggerProvider provider, ITextBuffer textBuffer)
        {
            _textBuffer = textBuffer;
            _provider   = provider;
            _regions    = new List <ITrackingSpan>();
            IServiceProvider serviceProvider = _provider.ServiceProvider as IServiceProvider;

            _analysisEntry = AnalysisEntryInitializer.Initialize(serviceProvider, textBuffer);
            _analysisEntry.NewParseTree += OnNewParseTree;
            // should init model to let outlining work when opening file
            // TODO: move to a more proper place
            _analysisEntry.InitModel();
        }
Esempio n. 19
0
        private async void OnNewAnalysis(AnalysisEntry entry)
        {
            var pyService = _provider._serviceProvider.GetPythonToolsService();
            var options   = pyService != null ? pyService.AdvancedOptions : null;

            if (options == null || options.ColorNames == false)
            {
                bool raise = false;
                lock (_spanCacheLock) {
                    if (_spanCache != null)
                    {
                        _spanCache = null;
                        raise      = true;
                    }
                }

                if (raise)
                {
                    OnNewClassifications(_buffer.CurrentSnapshot);
                }
                return;
            }

            var classifications = await entry.Analyzer.GetAnalysisClassificationsAsync(
                entry,
                _buffer,
                options.ColorNamesWithAnalysis
                );

            if (classifications != null)
            {
                Debug.WriteLine("Received {0} classifications", classifications.Data.classifications.Length);
                // sort the spans by starting position so we can use binary search when handing them out
                Array.Sort(
                    classifications.Data.classifications,
                    (x, y) => x.start - y.start
                    );

                lock (_spanCacheLock) {
                    _spanCache      = classifications.Data.classifications;
                    _spanTranslator = classifications.GetTracker(classifications.Data.version);
                }

                if (_spanTranslator != null)
                {
                    OnNewClassifications(_buffer.CurrentSnapshot);
                }
            }
        }
Esempio n. 20
0
        internal static async Task <AnalysisLocation> GetDefinitionLocationAsync(AnalysisEntry entry, ITextView textView, SnapshotSpan span)
        {
            var result = await entry.Analyzer.AnalyzeExpressionAsync(entry, textView, span.Start).ConfigureAwait(false);

            foreach (var variable in result?.Variables.MaybeEnumerate())
            {
                if (variable.Type == Analysis.VariableType.Definition &&
                    !string.IsNullOrEmpty(variable.Location?.FilePath))
                {
                    return(variable.Location);
                }
            }

            return(null);
        }
Esempio n. 21
0
        /// <summary>
        /// Returns the AnalysisEntry being used for where the caret is currently located in this view.
        ///
        /// Returns null if the caret isn't in Python code or an analysis doesn't exist for some reason.
        /// </summary>
        internal static AnalysisEntry GetAnalysisAtCaret(this ITextView textView, IServiceProvider serviceProvider)
        {
            var buffer = textView.GetPythonBufferAtCaret();

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

            var           service = serviceProvider.GetEntryService();
            AnalysisEntry entry   = null;

            service?.TryGetAnalysisEntry(textView, buffer, out entry);
            return(entry);
        }
Esempio n. 22
0
            private async void OnNewParseTree(AnalysisEntry entry)
            {
                var snapshot = _buffer.CurrentSnapshot;

                var tags = await entry.Analyzer.GetOutliningTagsAsync(snapshot);

                if (tags != null)
                {
                    _tags = tags.Concat(ProcessRegionTags(snapshot)).ToArray();

                    TagsChanged?.Invoke(
                        this,
                        new SnapshotSpanEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length))
                        );
                }
            }
Esempio n. 23
0
        private async Task OnNewAnalysisAsync(PythonTextBufferInfo sender, AnalysisEntry entry)
        {
            if (!_provider._colorNames || entry == null)
            {
                bool raise = false;
                lock (_spanCacheLock) {
                    if (_spanCache != null)
                    {
                        _spanCache = null;
                        raise      = true;
                    }
                }

                if (raise)
                {
                    OnNewClassifications(sender.CurrentSnapshot);
                }
                return;
            }


            var classifications = await entry.Analyzer.GetAnalysisClassificationsAsync(
                entry,
                sender.Buffer,
                _provider._colorNamesWithAnalysis
                );

            if (classifications != null)
            {
                Debug.WriteLine("Received {0} classifications", classifications.Data.classifications?.Length ?? 0);

                lock (_spanCacheLock) {
                    // sort the spans by starting position so we can use binary search when handing them out
                    _spanCache = classifications.Data.classifications
                                 .MaybeEnumerate()
                                 .OrderBy(c => c.start)
                                 .Distinct(ClassificationComparer.Instance)
                                 .ToArray();
                    _spanTranslator = classifications.GetTracker(classifications.Data.version);
                }

                if (_spanTranslator != null)
                {
                    OnNewClassifications(sender.CurrentSnapshot);
                }
            }
        }
Esempio n. 24
0
        internal static async Task <IAnalysisVariable[]> GetDefinitionLocationsAsync(AnalysisEntry entry, SnapshotPoint pt)
        {
            var list = new List <IAnalysisVariable>();

            var result = await entry.Analyzer.AnalyzeExpressionAsync(entry, pt, ExpressionAtPointPurpose.FindDefinition).ConfigureAwait(false);

            foreach (var variable in (result?.Variables).MaybeEnumerate())
            {
                if (variable.Type == VariableType.Definition &&
                    !string.IsNullOrEmpty(variable.DefinitionLocation?.FilePath))
                {
                    list.Add(variable);
                }
            }

            return(list.ToArray());
        }
Esempio n. 25
0
        public DropDownBarClient(IServiceProvider serviceProvider, IWpfTextView textView, AnalysisEntry analysisEntry)
        {
            Utilities.ArgumentNotNull(nameof(serviceProvider), serviceProvider);
            Utilities.ArgumentNotNull(nameof(textView), textView);
            Utilities.ArgumentNotNull(nameof(analysisEntry), analysisEntry);

            _serviceProvider = serviceProvider;
            _analysisEntry   = analysisEntry;
            textView.TextBuffer.RegisterForParseTree(ParserOnNewParseTree);
            _textView   = textView;
            _dispatcher = Dispatcher.CurrentDispatcher;
            _textView.Caret.PositionChanged += CaretPositionChanged;
            for (int i = 0; i < NavigationLevels; i++)
            {
                _curSelection[i] = -1;
            }
        }
Esempio n. 26
0
        private async Task <IPeekableItem> GetPeekableItemAsync(IPeekResultFactory peekResultFactory, ITextBuffer buffer, SnapshotPoint pt)
        {
            AnalysisEntry entry = null;

            _editorServices.AnalysisEntryService?.TryGetAnalysisEntry(buffer, out entry);
            if (entry == null)
            {
                return(null);
            }

            var result = await NavigableSymbolSource.GetDefinitionLocationsAsync(entry, pt).ConfigureAwait(false);

            if (result.Length > 0)
            {
                return(new PythonPeekableItem(peekResultFactory, result));
            }

            return(null);
        }
Esempio n. 27
0
        public DropDownBarClient(IServiceProvider serviceProvider, IWpfTextView textView, AnalysisEntry analysisEntry)
        {
            Utilities.ArgumentNotNull(nameof(serviceProvider), serviceProvider);
            Utilities.ArgumentNotNull(nameof(textView), textView);
            Utilities.ArgumentNotNull(nameof(analysisEntry), analysisEntry);

            _serviceProvider = serviceProvider;
            _uiThread        = _serviceProvider.GetUIThread();
            _services        = _serviceProvider.GetComponentModel().GetService <PythonEditorServices>();
            _analysisEntry   = analysisEntry;
            _textView        = textView;
            _services.GetBufferInfo(_textView.TextBuffer).OnNewParseTree += ParserOnNewParseTree;
            _dispatcher = Dispatcher.CurrentDispatcher;
            _textView.Caret.PositionChanged += CaretPositionChanged;
            for (int i = 0; i < NavigationLevels; i++)
            {
                _curSelection[i] = -1;
            }
        }
Esempio n. 28
0
        private Task OnNewAnalysisEntryAsync(PythonTextBufferInfo sender, AnalysisEntry entry)
        {
            var analyzer = entry?.Analyzer;

            if (analyzer == null)
            {
                Debug.Assert(entry == null, "Should not have new analysis entry without an analyzer");
                return(Task.CompletedTask);
            }

            var snapshot = sender.CurrentSnapshot;

            ClassificationChanged?.Invoke(
                this,
                new ClassificationChangedEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length))
                );

            return(Task.CompletedTask);
        }