示例#1
0
        async Task InitializeAsync(ITextBuffer buffer, ISynchronousTagger <IClassificationTag> tagger, IRoslynDocumentationProviderFactory docFactory)
        {
            ProfileOptimizationHelper.StartProfile("startup-roslyn");
            var refs = new MetadataReference[] {
                CreateMetadataReference(typeof(int).Assembly, docFactory),
            };

            await InitializeAsync(buffer, csharpCode, refs, LanguageNames.CSharp, tagger, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe : true), new CSharpParseOptions());
            await InitializeAsync(buffer, visualBasicCode, refs, LanguageNames.VisualBasic, tagger, new VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary), new VisualBasicParseOptions());

            (tagger as IDisposable)?.Dispose();
        }
示例#2
0
        public void CompileCode()
        {
            if (!CanCompile)
            {
                return;
            }
            CanCompile = false;

            ProfileOptimizationHelper.StartProfile("compile-" + decompiler.UniqueGuid.ToString());
            StartCompileAsync().ContinueWith(t => {
                var ex = t.Exception;
                Debug.Assert(ex == null);
            }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }
示例#3
0
        async Task StartAsync(SignatureHelpInfo info, SnapshotPoint triggerPosition, SignatureHelpTriggerInfo triggerInfo, CancellationToken cancellationToken)
        {
            // This helps a little to speed up the code
            ProfileOptimizationHelper.StartProfile("roslyn-sighelp-" + info.SignatureHelpService.Language);

            var result = await info.SignatureHelpService.GetItemsAsync(info.Document, triggerPosition.Position, triggerInfo, cancellationToken);

            if (result == null)
            {
                Dispose();
                return;
            }
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }
            StartSession(triggerPosition, result);
        }
示例#4
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            var snapshot     = session.TextView.TextSnapshot;
            var triggerPoint = session.GetTriggerPoint(snapshot);

            if (triggerPoint == null)
            {
                return;
            }
            var info = CompletionInfo.Create(snapshot);

            if (info == null)
            {
                return;
            }

            // This helps a little to speed up the code
            ProfileOptimizationHelper.StartProfile("roslyn-completion-" + info.Value.CompletionService.Language);

            CompletionTrigger completionTrigger;

            session.Properties.TryGetProperty(typeof(CompletionTrigger), out completionTrigger);

            var completionList = info.Value.CompletionService.GetCompletionsAsync(info.Value.Document, triggerPoint.Value.Position, completionTrigger).GetAwaiter().GetResult();

            if (completionList == null)
            {
                return;
            }
            Debug.Assert(completionList.DefaultSpan.End <= snapshot.Length);
            if (completionList.DefaultSpan.End > snapshot.Length)
            {
                return;
            }
            var trackingSpan  = snapshot.CreateTrackingSpan(completionList.DefaultSpan.Start, completionList.DefaultSpan.Length, SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward);
            var completionSet = RoslynCompletionSet.Create(imageMonikerService, mruCompletionService, completionList, info.Value.CompletionService, session.TextView, DefaultCompletionSetMoniker, dnSpy_Roslyn_Shared_Resources.CompletionSet_All, trackingSpan);

            completionSets.Add(completionSet);
        }
示例#5
0
        async Task StartDecompileAsync(MethodDef method, MethodSourceStatement?methodSourceStatement)
        {
            bool   canCompile = false, canceled = false;
            var    assemblyReferences = Array.Empty <CompilerMetadataReference>();
            string mainCode, hiddenCode;
            var    refSpan = new Span(0, 0);

            try {
                assemblyReferences = await DecompileAndGetRefsAsync(method, methodSourceStatement);

                mainCode   = decompileCodeState.MainOutput.ToString();
                hiddenCode = decompileCodeState.HiddenOutput.ToString();
                canCompile = true;
                var span = decompileCodeState.MainOutput.Span;
                if (span != null)
                {
                    refSpan = span.Value;
                }
            }
            catch (OperationCanceledException) {
                canceled   = true;
                mainCode   = string.Empty;
                hiddenCode = string.Empty;
            }
            catch (Exception ex) {
                mainCode   = ex.ToString();
                hiddenCode = string.Empty;
            }

            const string MAIN_CODE_NAME = "main";
            var          codeDocs       = Array.Empty <ICodeDocument>();

            if (!canceled)
            {
                // This helps a little to speed up the code
                ProfileOptimizationHelper.StartProfile("add-decompiled-code-" + decompiler.UniqueGuid.ToString());
                var docs = new List <IDecompiledDocument>();
                docs.Add(new DecompiledDocument(mainCode, MAIN_CODE_NAME));
                if (hiddenCode != string.Empty)
                {
                    docs.Add(new DecompiledDocument(hiddenCode, MAIN_CODE_NAME + ".g"));
                }
                codeDocs = languageCompiler.AddDecompiledCode(new DecompiledCodeResult(docs.ToArray(), assemblyReferences, assemblyReferenceResolver, PlatformHelper.GetPlatform(method.Module)));
            }

            decompileCodeState?.Dispose();
            decompileCodeState = null;

            foreach (var doc in codeDocs)
            {
                doc.TextView.Properties.AddProperty(editCodeTextViewKey, this);
            }
            Documents.AddRange(codeDocs.Select(a => new CodeDocument(a)));
            SelectedDocument = Documents.FirstOrDefault(a => a.NameNoExtension == MAIN_CODE_NAME) ?? Documents.FirstOrDefault();
            foreach (var doc in Documents)
            {
                if (doc.NameNoExtension == MAIN_CODE_NAME && refSpan.End <= doc.TextView.TextSnapshot.Length)
                {
                    doc.Initialize(new SnapshotPoint(doc.TextView.TextSnapshot, refSpan.Start));
                }
                else
                {
                    doc.Initialize(new SnapshotPoint(doc.TextView.TextSnapshot, 0));
                }
            }

            CanCompile    = canCompile;
            HasDecompiled = true;
            OnPropertyChanged(nameof(HasDecompiled));
        }
示例#6
0
        async Task StartDecompileAsync()
        {
            bool canCompile = false, canceled = false;
            var  assemblyReferences = Array.Empty <CompilerMetadataReference>();

            SimpleDocument[] simpleDocuments = Array.Empty <SimpleDocument>();
            try {
                var result = await DecompileAndGetRefsAsync();

                assemblyReferences = result.Value;
                simpleDocuments    = result.Key.Documents.ToArray();
                canCompile         = true;
            }
            catch (OperationCanceledException) {
                canceled = true;
            }
            catch (Exception ex) {
                simpleDocuments = new SimpleDocument[] {
                    new SimpleDocument(MAIN_CODE_NAME, ex.ToString(), null)
                };
            }

            var codeDocs = Array.Empty <ICodeDocument>();

            if (!canceled)
            {
                // This helps a little to speed up the code
                ProfileOptimizationHelper.StartProfile("add-decompiled-code-" + decompiler.UniqueGuid.ToString());
                var docs = new List <IDecompiledDocument>();
                foreach (var simpleDoc in simpleDocuments)
                {
                    docs.Add(new DecompiledDocument(simpleDoc.Text, simpleDoc.NameNoExtension));
                }
                codeDocs = languageCompiler.AddDecompiledCode(new DecompiledCodeResult(docs.ToArray(), assemblyReferences, assemblyReferenceResolver, PlatformHelper.GetPlatform(sourceModule)));
            }

            decompileCodeState?.Dispose();
            decompileCodeState = null;

            foreach (var doc in codeDocs)
            {
                doc.TextView.Properties.AddProperty(editCodeTextViewKey, this);
            }
            Documents.AddRange(codeDocs.Select(a => new CodeDocument(a)));
            SelectedDocument = Documents.FirstOrDefault(a => a.NameNoExtension == MAIN_CODE_NAME) ?? Documents.FirstOrDefault();
            Debug.Assert(Documents.Count == simpleDocuments.Length);
            for (int i = 0; i < Documents.Count; i++)
            {
                var doc       = Documents[i];
                var caretSpan = simpleDocuments[i].CaretSpan;
                if (caretSpan != null && caretSpan.Value.End <= doc.TextView.TextSnapshot.Length)
                {
                    doc.Initialize(new SnapshotPoint(doc.TextView.TextSnapshot, caretSpan.Value.Start));
                }
                else
                {
                    doc.Initialize(new SnapshotPoint(doc.TextView.TextSnapshot, 0));
                }
            }

            CanCompile    = canCompile;
            HasDecompiled = true;
            OnPropertyChanged(nameof(HasDecompiled));
        }
示例#7
0
 public App()
 {
     ProfileOptimizationHelper.CreateProfile();
 }