Skip to content

Instantly share code, notes, and snippets.

@voltrevo
Created April 9, 2017 06:57
Show Gist options
  • Save voltrevo/ed95b42596c28fe4627dc3f76c1abf14 to your computer and use it in GitHub Desktop.
Save voltrevo/ed95b42596c28fe4627dc3f76c1abf14 to your computer and use it in GitHub Desktop.
'use strict';
const loadSrcLocation = (locationStr, contextRadius = 5) => {
const parts = locationStr.split(':');
const col = Number(parts[parts.length - 1]);
const lineNo = Number(parts[parts.length - 2]);
const url = parts.slice(0, parts.length - 2).join(':');
return fetch(url)
.then(res => res.text())
.then(text => {
const lines = text.split('\n');
const contextLines = lines
.slice(lineNo - contextRadius, lineNo + contextRadius + 1)
.map((line, i) => `${lineNo - contextRadius + i}: ${line}`)
;
contextLines.splice(contextRadius, 0, '~'.repeat(`${lineNo}: `.length + col - 1) + '^');
return contextLines.join('\n');
})
;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment