Skip to content

Commit

Permalink
vscode extension to show not-sourcemapped stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
TanninOne committed Mar 6, 2019
1 parent 2368c59 commit cf5c41f
Show file tree
Hide file tree
Showing 21 changed files with 2,242 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules/*
**/node_modules/*
typings
dist
dist_custom
Expand All @@ -10,6 +10,8 @@ coverage
.vscode/.BROWSE.VC.DB*
*.VC.db
app/bundledPlugins
attachments
sourcemaps

extensions/usvfs-deploy/node_modules/*

Expand Down
7 changes: 7 additions & 0 deletions tools/stackmap/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"ms-vscode.vscode-typescript-tslint-plugin"
]
}
35 changes: 35 additions & 0 deletions tools/stackmap/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: watch"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "npm: watch"
}
]
}
11 changes: 11 additions & 0 deletions tools/stackmap/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
20 changes: 20 additions & 0 deletions tools/stackmap/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
10 changes: 10 additions & 0 deletions tools/stackmap/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.vscode/**
.vscode-test/**
out/test/**
src/**
.gitignore
vsc-extension-quickstart.md
**/tsconfig.json
**/tslint.json
**/*.map
**/*.ts
9 changes: 9 additions & 0 deletions tools/stackmap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Change Log

All notable changes to the "stackmap" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]

- Initial release
13 changes: 13 additions & 0 deletions tools/stackmap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Features

## Requirements

## Extension Settings

## Known Issues

## Release Notes

### 1.0.0

Initial release
2 changes: 2 additions & 0 deletions tools/stackmap/media/paste-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions tools/stackmap/media/paste-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tools/stackmap/media/version-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tools/stackmap/media/version-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/stackmap/media/vortex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions tools/stackmap/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"name": "stackmap",
"displayName": "StackMap",
"publisher": "black-tree-gaming",
"description": "",
"license": "GPL-3.0",
"version": "0.0.1",
"engines": {
"vscode": "^1.31.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onView:stackmap",
"onCommand:stackmap.fromClipboard"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "stackmap.fromClipboard",
"title": "Update",
"icon": {
"light": "media/paste-light.svg",
"dark": "media/paste-dark.svg"
}
},
{
"command": "stackmap.selectVersion",
"title": "Version",
"icon": {
"light": "media/version-light.svg",
"dark": "media/version-dark.svg"
}
},
{
"command": "stackmap.open",
"title": "Open"
}
],
"views": {
"explorer": [
{
"id": "stackmap",
"name": "Stack Map"
}
]
},
"menus": {
"view/title": [
{
"command": "stackmap.fromClipboard",
"when": "view == stackmap",
"group": "navigation"
},
{
"command": "stackmap.selectVersion",
"when": "view == stackmap",
"group": "navigation"
}
]
}
},
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "yarn run compile && node ./node_modules/vscode/bin/test"
},
"dependencies": {
"copy-paste": "^1.3.0",
"fs-extra": "^7.0.1",
"source-map": "^0.7.3",
"stack-trace": "^0.0.10"
},
"devDependencies": {
"vscode": "^1.1.28",
"tslint": "^5.12.1",
"typescript": "^3.3.1",
"@types/copy-paste": "1.1.30",
"@types/node": "^10.12.21",
"@types/mocha": "^2.2.42",
"@types/stack-trace": "^0.0.29"
}
}
70 changes: 70 additions & 0 deletions tools/stackmap/src/SourceMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import { SourceMapConsumer, NullableMappedPosition } from 'source-map';

const sourceMappingRE = /^\/\/# sourceMappingURL=([a-zA-Z0-9._\-\/\\]+)$/;

class SourceMap {
private mConsumers: { [fileName: string]: Promise<SourceMapConsumer | null>} = {};
private mSourcePath: string;
private mVersion: string;

constructor(sourcePath: string, version: string) {
this.mSourcePath = sourcePath;
this.mVersion = version;
if ((process.platform === 'win32') && (sourcePath.startsWith('/'))) {
this.mSourcePath = sourcePath.slice(1);
}
}

public lookup(position: NullableMappedPosition): Promise<NullableMappedPosition> {
return this.getConsumer(position.source)
.then(consumer => (consumer === null)
? Promise.resolve(position)
: consumer.originalPositionFor({ line: position.line || 0, column: position.column || 0 }));
}

private findSourceMapPath(sourceData: string): string {
// search for the sourceMappingURL from back to front
const sourceMappingLine = sourceData
.split('\n')
.reverse()
.find(line => line.match(sourceMappingRE) !== null);
const match = (sourceMappingLine !== undefined)
? sourceMappingLine.match(sourceMappingRE)
: null;
return (match !== null)
? match[1]
: '';
}

private getConsumer(filePath: string | null): Promise<SourceMapConsumer | null> {
if (filePath === null) {
return Promise.resolve(null);
}

if (this.mConsumers[filePath] === undefined) {
const correctedPath = path.join(this.mSourcePath, filePath);
this.mConsumers[filePath] = fs.readFile(correctedPath, { encoding: 'utf8' })
.then(data => {
const sourceMapPath = this.findSourceMapPath(data);
if (sourceMapPath === undefined) {
return Promise.reject(null);
}
const fullPath: string = (sourceMapPath.startsWith('/'))
? this.mSourcePath + sourceMapPath
: path.resolve(this.mSourcePath, 'sourcemaps', this.mVersion, sourceMapPath);
console.log('res', sourceMapPath, this.mSourcePath, fullPath);
return fs.readFile(fullPath, { encoding: 'utf8' });
})
.then(data => new SourceMapConsumer(JSON.parse(data)))
.catch(err => {
console.error('failed to read sourcemap', err);
return null;
});
}
return this.mConsumers[filePath];
}
}

export default SourceMap;
Loading

0 comments on commit cf5c41f

Please sign in to comment.