<commit_before>import("helpers");
import("jsutils.keys");
import("utils.*");

import("pad.model");

import("editor.workspace");

jimport("collabode.Workspace");
jimport("collabode.testing.ProjectTestsOwner");

jimport("java.lang.System");

function render_coverage(projectname, unused, testclassname, testmethodname) {
  var project = Workspace.accessProject(projectname);
  var userId = getSession().userId;
  
  var files = {};
  var calls = [];
  
  function _methodRange(padId, method) {
    var collab = workspace.documentFor(userId, padId).collab;
    var range = method.getSourceRange();
    return {
      from: collab.union.getLineOfOffset(collab.diskToUnionOffset(range.getOffset())),
      to: collab.union.getLineOfOffset(collab.diskToUnionOffset(range.getOffset() + range.getLength()))
    };
  }
  
  function _addMethod(method) {
    var filename = method.getResource().getProjectRelativePath().toString();
    var padId = workspace.accessDocumentPad(userId, method.getResource());
    var unfold = _methodRange(padId, method);
    if (files[filename]) {
      files[filename].unfolded.push(unfold);
    } else {
      model.accessPadGlobal(padId, function(pad) {
        files[filename] = {
          atext: pad.atext(),
          apool: pad.pool().toJsonable(),
          unfolded: [ unfold ]
        };
      });
    }
    return filename;
  }
  
  var test = ProjectTestsOwner.of(project).getMethod(testclassname, testmethodname);
  var testfilename = _addMethod(test);
  
  var coverage = ProjectTestsOwner.of(project).getCoverage(testclassname, testmethodname);
  for (var it = coverage.descendingIterator(); it.hasNext(); ) {
    var mr = it.next();
    if (keys(files).length > 10) {
      calls.push("and " + (coverage.size() - calls.length) + " more");
      break;
    }
    calls.push(mr.method.getDeclaringType().getElementName()<commit_msg>Fix error when coverage is unavailable<commit_after>import("helpers");
import("jsutils.keys");
import("utils.*");

import("pad.model");

import("editor.workspace");

jimport("collabode.Workspace");
jimport("collabode.testing.ProjectTestsOwner");

jimport("java.lang.System");

function render_coverage(projectname, unused, testclassname, testmethodname) {
  var project = Workspace.accessProject(projectname);
  var userId = getSession().userId;
  
  var files = {};
  var calls = [];
  
  function _methodRange(padId, method) {
    var collab = workspace.documentFor(userId, padId).collab;
    var range = method.getSourceRange();
    return {
      from: collab.union.getLineOfOffset(collab.diskToUnionOffset(range.getOffset())),
      to: collab.union.getLineOfOffset(collab.diskToUnionOffset(range.getOffset() + range.getLength()))
    };
  }
  
  function _addMethod(method) {
    var filename = method.getResource().getProjectRelativePath().toString();
    var padId = workspace.accessDocumentPad(userId, method.getResource());
    var unfold = _methodRange(padId, method);
    if (files[filename]) {
      files[filename].unfolded.push(unfold);
    } else {
      model.accessPadGlobal(padId, function(pad) {
        files[filename] = {
          atext: pad.atext(),
          apool: pad.pool().toJsonable(),
          unfolded: [ unfold ]
        };
      });
    }
    return filename;
  }
  
  var test = ProjectTestsOwner.of(project).getMethod(testclassname, testmethodname);
  var testfilename = _addMethod(test);
  
  var coverage = ProjectTestsOwner.of(project).getCoverage(testclassname, testmethodname);
  for (var it = coverage && coverage.descendingIterator(); it && it.hasNext(); ) {
    var mr = it.next();
    if (keys(files).length > 10) {
      calls.push("and " + (coverage.size() - calls.length) + " more");
      break;
    }
    calls.push(mr.method.getDeclaringType().getElementName()
{'fraction_non_alphanumeric': 0.14599312351229835, 'fraction_numerical': 0.0010579211848717272, 'mean_word_length': 3.8989637305699483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '896321', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1177, 'n_words': 196}