Created
April 9, 2017 06:57
-
-
Save voltrevo/ed95b42596c28fe4627dc3f76c1abf14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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