private async Task <ConversionResult> ConvertDocumentUnhandledAsync <TLanguageConversion>(string documentPath, Span selected, CancellationToken cancellationToken) where TLanguageConversion : ILanguageConversion, new() { await _outputWindow.WriteToOutputWindowAsync($"Converting {documentPath}...", true, true); //TODO Figure out when there are multiple document ids for a single file path var documentId = _visualStudioWorkspace.CurrentSolution.GetDocumentIdsWithFilePath(documentPath).SingleOrDefault(); if (documentId == null) { //If document doesn't belong to any project return(await ConvertTextOnlyAsync <TLanguageConversion>(documentPath, selected, cancellationToken)); } var document = _visualStudioWorkspace.CurrentSolution.GetDocument(documentId); var selectedTextSpan = new TextSpan(selected.Start, selected.Length); return(await ProjectConversion.ConvertSingleAsync <TLanguageConversion>(document, new SingleConversionOptions { SelectedTextSpan = selectedTextSpan }, CreateOutputWindowProgress(), cancellationToken)); }
private async Task <ConversionResult> ConvertDocumentUnhandledAsync <TLanguageConversion>(string documentPath, Span selected, CancellationToken cancellationToken) where TLanguageConversion : ILanguageConversion, new() { await _outputWindow.WriteToOutputWindowAsync($"Converting {documentPath}...", true, true); // If multiple projects contain this file path, there may be multiple ids, but in that the wrong project may have been built too... var documentId = _visualStudioWorkspace.CurrentSolution.GetDocumentIdsWithFilePath(documentPath).FirstOrDefault(); if (documentId == null) { //If document doesn't belong to any project await _outputWindow.WriteToOutputWindowAsync("File is not part of a compiling project, using best effort text conversion (less accurate)."); return(await ConvertFileTextAsync <TLanguageConversion>(documentPath, selected, cancellationToken)); } var document = _visualStudioWorkspace.CurrentSolution.GetDocument(documentId); var selectedTextSpan = new TextSpan(selected.Start, selected.Length); return(await ProjectConversion.ConvertSingleAsync <TLanguageConversion>(document, new SingleConversionOptions { SelectedTextSpan = selectedTextSpan, AbandonOptionalTasksAfter = await GetAbandonOptionalTasksAfterAsync() }, CreateOutputWindowProgress(), cancellationToken)); }