Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 79b5cf2

Browse files
committed
Initial commit
0 parents  commit 79b5cf2

13 files changed

+657
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
*.vsix
3+
out

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Run Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"args": [
13+
"--extensionDevelopmentPath=${workspaceFolder}"
14+
],
15+
"outFiles": [
16+
"${workspaceFolder}/out/**/*.js"
17+
],
18+
"preLaunchTask": "${defaultBuildTask}"
19+
},
20+
]
21+
}

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.exclude": {
4+
"out": false // set this to true to hide the "out" folder with the compiled JS files
5+
},
6+
"search.exclude": {
7+
"out": true // set this to false to include "out" folder in search results
8+
},
9+
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10+
"typescript.tsc.autoDetect": "off"
11+
}

.vscode/tasks.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// See https://go.microsoft.com/fwlink/?LinkId=733558
2+
// for the documentation about the tasks.json format
3+
{
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "npm",
8+
"script": "watch",
9+
"problemMatcher": "$tsc-watch",
10+
"isBackground": true,
11+
"presentation": {
12+
"reveal": "never"
13+
},
14+
"group": {
15+
"kind": "build",
16+
"isDefault": true
17+
}
18+
}
19+
]
20+
}

.vscodeignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.vscode/**
2+
.vscode-test/**
3+
out/test/**
4+
src/**
5+
.gitignore
6+
.yarnrc
7+
vsc-extension-quickstart.md
8+
**/tsconfig.json
9+
**/.eslintrc.json
10+
**/*.map
11+
**/*.ts

package.json

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"name": "syntax_tree",
3+
"displayName": "Syntax Tree",
4+
"description": "VSCode integration for syntax tree",
5+
"version": "0.1.0",
6+
"publisher": "kddnewton",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/kddnewton/syntax_tree.git"
10+
},
11+
"license": "MIT",
12+
"bugs": {
13+
"url": "https://github.com/kddnewton/syntax_tree/issues"
14+
},
15+
"engines": {
16+
"vscode": "^1.46.0"
17+
},
18+
"activationEvents": [
19+
"onLanguage:ruby",
20+
"workspaceContains:Gemfile.lock",
21+
"onCommand:syntaxTree.start",
22+
"onCommand:syntaxTree.stop",
23+
"onCommand:syntaxTree.restart",
24+
"onCommand:syntaxTree.showOutputChannel",
25+
"onCommand:syntaxTree.visualize",
26+
"onCommand:syntaxTree.disasm"
27+
],
28+
"main": "./out/extension",
29+
"contributes": {
30+
"commands": [
31+
{
32+
"command": "syntaxTree.start",
33+
"title": "Syntax Tree: Start"
34+
},
35+
{
36+
"command": "syntaxTree.stop",
37+
"title": "Syntax Tree: Stop"
38+
},
39+
{
40+
"command": "syntaxTree.restart",
41+
"title": "Syntax Tree: Restart"
42+
},
43+
{
44+
"command": "syntaxTree.showOutputChannel",
45+
"title": "Syntax Tree: Show Output Channel"
46+
},
47+
{
48+
"command": "syntaxTree.visualize",
49+
"title": "Syntax Tree: Visualize"
50+
},
51+
{
52+
"command": "syntaxTree.disasm",
53+
"title": "Syntax Tree: Disassemble"
54+
}
55+
],
56+
"colors": [
57+
{
58+
"id": "syntaxTree.implicits",
59+
"description": "Text color for the inserted implicits",
60+
"defaults": {
61+
"dark": "#707070",
62+
"light": "#999999",
63+
"highContrast": "foreground"
64+
}
65+
}
66+
]
67+
},
68+
"scripts": {
69+
"compile": "tsc -p ./",
70+
"package": "vsce package --yarn --githubBranch main",
71+
"publish": "vsce publish --yarn --githubBranch main",
72+
"vscode:prepublish": "yarn compile",
73+
"watch": "tsc --watch -p ./"
74+
},
75+
"dependencies": {
76+
"vscode-languageclient": "^7.0.0"
77+
},
78+
"devDependencies": {
79+
"@types/node": "^17.0.8",
80+
"@types/vscode": "^1.46.0",
81+
"typescript": "^4.2.2"
82+
}
83+
}

src/Disasm.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { commands, Disposable, languages, OutputChannel, ProviderResult, TextDocumentContentProvider, Uri, ViewColumn, window, workspace } from "vscode";
2+
import { LanguageClient } from "vscode-languageclient/node";
3+
4+
class Disasm implements Disposable, TextDocumentContentProvider {
5+
// The client used to communicate with the language server.
6+
private readonly languageClient: LanguageClient;
7+
8+
// The output channel used for logging for this class. It's given from the
9+
// main file so that it uses the same as the rest of the extension.
10+
private readonly outputChannel: OutputChannel;
11+
12+
// The list of callbacks and objects that should be disposed when an instance
13+
// of Visualize is being disposed.
14+
private readonly disposables: Disposable[];
15+
16+
constructor(languageClient: LanguageClient, outputChannel: OutputChannel) {
17+
this.languageClient = languageClient;
18+
this.outputChannel = outputChannel;
19+
this.disposables = [
20+
commands.registerCommand("syntaxTree.disasm", this.disasm),
21+
workspace.registerTextDocumentContentProvider("syntaxTree.disasm", this)
22+
];
23+
}
24+
25+
dispose() {
26+
this.disposables.forEach((disposable) => disposable.dispose());
27+
}
28+
29+
provideTextDocumentContent(uri: Uri): ProviderResult<string> {
30+
this.outputChannel.appendLine("Requesting disassembly");
31+
32+
const query: Record<string, string> = {};
33+
uri.query.split("&").forEach((pair) => {
34+
const [key, value] = pair.split("=");
35+
query[key] = value;
36+
});
37+
38+
return this.languageClient.sendRequest("syntaxTree/disasm", { textDocument: { uri: uri.path, query } });
39+
}
40+
41+
async disasm(line: number, name: string) {
42+
const document = window.activeTextEditor?.document;
43+
44+
if (document && document.languageId === "ruby" && document.uri.scheme === "file") {
45+
const uri = Uri.parse(`syntaxTree.disasm:${document.uri.toString()}?line=${line}&name=${name}`);
46+
47+
const doc = await workspace.openTextDocument(uri);
48+
languages.setTextDocumentLanguage(doc, "plaintext");
49+
50+
await window.showTextDocument(doc, ViewColumn.Beside, true);
51+
}
52+
}
53+
}
54+
55+
export default Disasm;

0 commit comments

Comments
 (0)