public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback) { if (relationshipName != PredefinedPeekRelationships.Definitions.Name) { return; } string file = FindRuleSetInFile(new[] { ".less", ".scss", ".css" }, peekableItem._id, out RuleSet rule); if (rule == null) { callback.ReportProgress(1); return; } using (var displayInfo = new PeekResultDisplayInfo(label: peekableItem._id, labelTooltip: file, title: Path.GetFileName(file), titleTooltip: file)) { IDocumentPeekResult result = peekableItem._peekResultFactory.Create ( displayInfo, file, new Span(rule.Start, rule.Length), rule.Start, false ); resultCollection.Add(result); callback.ReportProgress(1); } }
private async Task<IDocumentPeekResult> FindFunctionAsync(string sourceFileName, Span sourceSpan, string functionName) { try { string code = await GetFunctionCode(functionName); if (!string.IsNullOrEmpty(code)) { string tempFile = Path.ChangeExtension(Path.GetTempFileName(), ".r"); using (var sw = new StreamWriter(tempFile)) { sw.Write(code); } using (var displayInfo = new PeekResultDisplayInfo( label: functionName, labelTooltip: functionName, title: functionName, titleTooltip: functionName)) { _result = _peekItem.PeekResultFactory.Create(displayInfo, tempFile, new Span(0, 0), 0, isReadOnly: true); // Editor opens external items as plain text. When file opens, change content type to R. IdleTimeAction.Create(() => { if (_result.Span.IsDocumentOpen) { var rs = _shell.ExportProvider.GetExportedValue<IContentTypeRegistryService>(); var ct = rs.GetContentType(RContentTypeDefinition.ContentType); _result.Span.Document.TextBuffer.ChangeContentType(ct, this.GetType()); try { File.Delete(tempFile); } catch (IOException) { } catch (UnauthorizedAccessException) { } } }, 50, GetType(), _shell); return _result; } } } catch (Exception ex) { _exception = ex; } return null; }
private async Task <IDocumentPeekResult> FindFunctionAsync(string sourceFileName, Span sourceSpan, string functionName) { try { string code = await GetFunctionCode(functionName); if (!string.IsNullOrEmpty(code)) { string tempFile = Path.ChangeExtension(Path.GetTempFileName(), ".r"); using (var sw = new StreamWriter(tempFile)) { sw.Write(code); } using (var displayInfo = new PeekResultDisplayInfo( label: functionName, labelTooltip: functionName, title: functionName, titleTooltip: functionName)) { _result = _peekItem.PeekResultFactory.Create(displayInfo, tempFile, new Span(0, 0), 0, isReadOnly: true); // Editor opens external items as plain text. When file opens, change content type to R. IdleTimeAction.Create(() => { if (_result.Span.IsDocumentOpen) { var rs = _services.GetService <IContentTypeRegistryService>(); var ct = rs.GetContentType(RContentTypeDefinition.ContentType); _result.Span.Document.TextBuffer.ChangeContentType(ct, this.GetType()); try { File.Delete(tempFile); } catch (IOException) { } catch (UnauthorizedAccessException) { } } }, 50, GetType(), _services.GetService <IIdleTimeService>()); return(_result); } } } catch (Exception ex) { _exception = ex; } return(null); }