コード例 #1
0
        private async Task <AddMessageResult> AddMessageCoreAsync(TargetGeneratedError error)
        {
            // We only want to pass compiler, analyzers, etc to the language
            // service, so we skip tasks that do not have a code
            if (!TryExtractErrorListDetails(error.BuildEventArgs, out ErrorListDetails details) || string.IsNullOrEmpty(details.Code))
            {
                return(AddMessageResult.NotHandled);
            }

            bool handled = await _projectContextHost.OpenContextForWriteAsync(accessor =>
            {
                var errorReporter = (IVsLanguageServiceBuildErrorReporter2)accessor.HostSpecificErrorReporter;

                try
                {
                    errorReporter.ReportError2(details.Message,
                                               details.Code,
                                               details.Priority,
                                               details.LineNumberForErrorList,
                                               details.ColumnNumberForErrorList,
                                               details.EndLineNumberForErrorList,
                                               details.EndColumnNumberForErrorList,
                                               details.GetFileFullPath(_project.FullPath));
                    return(TaskResult.True);
                }
                catch (NotImplementedException)
                {   // Language Service doesn't handle it, typically because file
                    // isn't in the project or because it doesn't have line/column
                }

                return(TaskResult.False);
            });

            return(handled ? AddMessageResult.HandledAndStopProcessing : AddMessageResult.NotHandled);
        }
コード例 #2
0
        private async Task <CodeModel?> GetCodeModelAsync(Project project)
        {
            await _threadingService.SwitchToUIThread();

            return(await _projectContextHost.OpenContextForWriteAsync(accessor =>
            {
                return Task.FromResult(_codeModelFactory.GetCodeModel(accessor.Context, project));
            }));
        }
 private static ProjectId?GetProjectId(IProjectThreadingService threadingService, IActiveWorkspaceProjectContextHost projectContextHost)
 {
     return(threadingService.ExecuteSynchronously(() =>
     {
         return projectContextHost.OpenContextForWriteAsync(accessor =>
         {
             return Task.FromResult(accessor.Context.Id);
         });
     }));
 }
コード例 #4
0
        private int Invoke(Func <IVsENCRebuildableProjectCfg2, HResult> action)
        {
            return(_threadingService.ExecuteSynchronously(async() =>
            {
                await _threadingService.SwitchToUIThread();

                return await _projectContextHost.OpenContextForWriteAsync(accessor =>
                {
                    return Task.FromResult(action((IVsENCRebuildableProjectCfg2)accessor.HostSpecificEditAndContinueService));
                });
            }));
        }
コード例 #5
0
 private string GetWorkspaceContextIdFromActiveContext()
 {
     return(_threadingService.ExecuteSynchronously(async() =>
     {
         try
         {
             // If we're never been set an active context, we just
             // pick one based on the active configuration.
             return await _activeWorkspaceProjectContextHost.OpenContextForWriteAsync(a => Task.FromResult(a.ContextId));
         }
         catch (OperationCanceledException)
         {   // Project unloading
             return null;
         }
     }));
 }
コード例 #6
0
        protected virtual async Task CompileTempPEAsync(HashSet <string> filesToCompile, string outputFileName, CancellationToken token)
        {
            bool result = await _activeWorkspaceProjectContextHost.OpenContextForWriteAsync(accessor =>
            {
                return(_compiler.CompileAsync(accessor.Context, outputFileName, filesToCompile, token));
            });

            // if the compilation failed or was cancelled we should clean up any old TempPE outputs lest a designer gets the wrong types, plus its what legacy did
            if (!result)
            {
                try
                {
                    _fileSystem.RemoveFile(outputFileName);
                }
                catch (IOException)
                { }
                catch (UnauthorizedAccessException)
                { }
            }
        }
コード例 #7
0
        private Task ProcessCompileQueueAsync(CancellationToken token)
        {
            int compileCount       = 0;
            int initialQueueLength = _queue.Count;
            var compileStopWatch   = Stopwatch.StartNew();

            return(_activeWorkspaceProjectContextHost.OpenContextForWriteAsync(async accessor =>
            {
                while (true)
                {
                    if (IsDisposing || IsDisposed)
                    {
                        return;
                    }

                    // we don't want to pop if we've been cancelled in the time it took to take the write lock, so check just in case.
                    // this may be overkill
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }

                    // Grab the next file to compile off the queue
                    QueueItem?item = _queue.Pop();
                    if (item == null)
                    {
                        break;
                    }

                    bool cancelled = false;
                    string outputFileName = GetOutputFileName(item.FileName, item.TempPEOutputPath);
                    try
                    {
                        if (await CompileDesignTimeInputAsync(accessor.Context, item.FileName, outputFileName, item.SharedInputs, item.IgnoreFileWriteTime, token))
                        {
                            compileCount++;
                        }
                    }
                    catch (OperationCanceledException)
                    {
                        cancelled = true;
                    }

                    if (cancelled || token.IsCancellationRequested)
                    {
                        // if the compilation was cancelled, we need to re-add the file so we catch it next time
                        _queue.Push(item);
                        break;
                    }
                }

                LogTelemetry(cancelled: token.IsCancellationRequested);
            }));

            void LogTelemetry(bool cancelled)
            {
                compileStopWatch !.Stop();
                _telemetryService.PostProperties(TelemetryEventName.TempPEProcessQueue, new[]
                {
                    (TelemetryPropertyName.TempPECompileCount, (object)compileCount),
                    (TelemetryPropertyName.TempPEInitialQueueLength, initialQueueLength),
                    (TelemetryPropertyName.TempPECompileWasCancelled, cancelled),
                    (TelemetryPropertyName.TempPECompileDuration, compileStopWatch.ElapsedMilliseconds)
                });