og: Preliminary nREPL support, auto ml file on save (#274)

This commit is contained in:
Tyler Wilding 2023-06-08 22:42:19 -05:00 committed by GitHub
parent 09efd159fa
commit 73d7d111ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 3290 additions and 1861 deletions

View file

@ -25,7 +25,9 @@ jobs:
cache: yarn
- name: Install Dependencies
run: yarn install --frozen-lockfile
run: |
yarn set version stable
yarn install --immutable
- name: Build Extension
run: yarn compile

View file

@ -23,7 +23,9 @@ jobs:
cache: yarn
- name: Install Dependencies
run: yarn install --frozen-lockfile
run: |
yarn set version stable
yarn install --immutable
- name: Check Linting
run: yarn lint
@ -42,7 +44,9 @@ jobs:
cache: yarn
- name: Install Dependencies
run: yarn install --frozen-lockfile
run: |
yarn set version stable
yarn install --immutable
- name: Check Linting
run: yarn format:check

View file

@ -28,7 +28,9 @@ jobs:
cache: yarn
- name: Install Dependencies
run: yarn install --frozen-lockfile
run: |
yarn set version stable
yarn install --immutable
- name: Bump Version
env:

3
.gitignore vendored
View file

@ -6,3 +6,6 @@ out/
*.bin
lsp-metadata.json
*-types.json
.yarn/*
!.yarn/patches
.pnp.*

View file

@ -5,3 +5,4 @@ out/
*.exe
*.bin
lib/
.pnp*

View file

@ -1,7 +1,7 @@
diff --git a/node_modules/vscode-jsonrpc/lib/common/messageReader.js b/node_modules/vscode-jsonrpc/lib/common/messageReader.js
index 99e3dea..c8fc01c 100644
--- a/node_modules/vscode-jsonrpc/lib/common/messageReader.js
+++ b/node_modules/vscode-jsonrpc/lib/common/messageReader.js
diff --git a/lib/common/messageReader.js b/lib/common/messageReader.js
index 99e3dea72d23baacef1a4ced34feedcc6b0cc9f2..c8fc01ca1cfe40f5af0a94eb649ee888bc10bee6 100644
--- a/lib/common/messageReader.js
+++ b/lib/common/messageReader.js
@@ -136,6 +136,9 @@ class ReadableStreamMessageReader extends AbstractMessageReader {
}
const contentLength = headers.get('content-length');

View file

@ -23,8 +23,7 @@
"lint": "eslint . --ext .ts,.tsx",
"watch": "tsc -watch -p ./",
"format": "npx prettier --write .",
"format:check": "npx prettier --check .",
"postinstall": "patch-package"
"format:check": "npx prettier --check ."
},
"devDependencies": {
"@types/follow-redirects": "^1.14.1",
@ -33,16 +32,16 @@
"@types/vscode": "^1.78.0",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.8",
"@vscode/vsce": "^2.15.0",
"eslint": "^8.41.0",
"patch-package": "^7.0.0",
"typescript": "^5.0.4",
"vsce": "^2.15.0"
"typescript": "^5.0.4"
},
"dependencies": {
"comment-json": "^4.2.3",
"follow-redirects": "^1.15.2",
"glob": "^10.0.0",
"parinfer": "^3.13.1",
"promise-socket": "^7.0.0",
"vscode-languageclient": "^8.1.0"
},
"activationEvents": [],
@ -143,6 +142,14 @@
{
"command": "opengoal.lsp.restart",
"title": "OpenGOAL - LSP - Restart"
},
{
"command": "opengoal.nrepl.jackin",
"title": "OpenGOAL - nREPL - Jack-In"
},
{
"command": "opengoal.nrepl.unjack",
"title": "OpenGOAL - nREPL - Un-jack"
}
],
"configuration": [
@ -168,6 +175,22 @@
}
}
},
{
"id": "opengoal-repl",
"title": "REPL",
"properties": {
"opengoal.replAutoJackIn": {
"type": "boolean",
"default": false,
"description": "Whether to automatically attempt to jack into a REPL when performing an action that requires it"
},
"opengoal.reloadFileOnSave": {
"type": "boolean",
"default": false,
"description": "Whether to automatically (ml \"file-name\") when saving a `.gc` file"
}
}
},
{
"id": "opengoal-decomp",
"title": "Decompilation",
@ -456,5 +479,8 @@
"path": "./snippets/opengoal.json"
}
]
},
"resolutions": {
"vscode-jsonrpc@8.1.0": "patch:vscode-jsonrpc@npm%3A8.1.0#./.yarn/patches/vscode-jsonrpc-npm-8.1.0-557f20ee72.patch"
}
}

View file

@ -5,6 +5,8 @@ export function getConfig() {
return {
opengoalParinferMode: configOptions.get<string>("parinferMode"),
autoReplJackIn: configOptions.get<boolean>("replAutoJackIn"),
reloadFileOnSave: configOptions.get<boolean>("reloadFileOnSave"),
launchLspOnStartup: configOptions.get<boolean>("launchLspOnStartup"),
opengoalLspVersion: configOptions.get<string>("opengoalLspVersion"),
opengoalLspPath: configOptions.get<string>("opengoalLspPath"),

View file

@ -20,6 +20,10 @@ import {
registerParinferCommands,
} from "./goal/parinfer/parinfer";
import { IRCompletionItemProvider } from "./languages/ir2/ir2-completions";
import {
nreplOnFileSaveHandler,
registerNReplCommands,
} from "./tools/opengoal/nrepl/opengoal-nrepl";
export async function activate(context: vscode.ExtensionContext) {
try {
@ -91,6 +95,10 @@ export async function activate(context: vscode.ExtensionContext) {
registerParinferCommands(context);
vscode.workspace.onDidChangeTextDocument(onChangeTextDocument);
vscode.window.onDidChangeTextEditorSelection(onChangeSelection);
// nREPL
registerNReplCommands(context);
vscode.workspace.onDidSaveTextDocument(nreplOnFileSaveHandler);
} catch (err) {
vscode.window.showErrorMessage(
"Failed to activate OpenGOAL extension, see logs for details"

View file

@ -344,7 +344,7 @@ export function registerParinferCommands(
(getConfig().opengoalParinferMode as ParinferMode) ?? ParinferMode.DISABLED
);
updateStatus();
parinferStatusItem.show();
parinferStatusItem.hide(); // TODO - consolidate menu https://github.com/rust-lang/rust-analyzer/blob/9c03aa1ac2e67051db83a85baf3cfee902e4dd84/editors/code/src/ctx.ts#L406
context.subscriptions.push(
vscode.commands.registerCommand(
"opengoal.parinfer.changeMode",

View file

@ -0,0 +1,112 @@
import { Socket } from "net";
import * as path from "path";
import PromiseSocket from "promise-socket";
import * as vscode from "vscode";
import { getConfig } from "../../../config/config";
let jackedIn = false;
let socket: PromiseSocket<Socket> | undefined = undefined;
const nreplStatusItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Left,
0
);
function updateStatus() {
// TODO - show errors
if (!jackedIn) {
nreplStatusItem.text = "$(call-outgoing) nREPL";
nreplStatusItem.tooltip =
"Jack-in to a running OpenGOAL nREPL on port 8181";
nreplStatusItem.command = "opengoal.nrepl.jackin";
} else {
nreplStatusItem.text = "$(debug-disconnect) nREPL";
nreplStatusItem.tooltip =
"Un-jack from a running OpenGOAL nREPL on port 8181";
nreplStatusItem.command = "opengoal.nrepl.unjack";
}
}
export async function jackIn() {
if (socket !== undefined) {
jackedIn = true;
updateStatus();
return;
}
try {
socket = new PromiseSocket();
socket.setEncoding("utf8");
socket.socket.setTimeout(100);
await socket.connect(8181, "127.0.0.1");
jackedIn = true;
} catch (e) {
console.error(e);
socket = undefined;
}
updateStatus();
}
export async function unJack() {
if (socket === undefined) {
jackedIn = false;
updateStatus();
return;
}
try {
socket.destroy();
} catch (e) {
console.error(e);
}
socket = undefined;
jackedIn = false;
updateStatus();
}
export async function reloadFile(fileName: string) {
if (!getConfig().reloadFileOnSave) {
return;
}
if (getConfig().autoReplJackIn && socket === undefined) {
await jackIn();
}
if (!jackedIn || socket === undefined) {
return;
}
try {
// Define your data
const mlForm = `(ml "${fileName}")`;
const headerLength = 8;
// Create a buffer
const headerBuffer = Buffer.alloc(headerLength);
// Pack the data into the buffer
headerBuffer.writeUInt32LE(Buffer.byteLength(mlForm), 0);
headerBuffer.writeUInt32LE(10, 4);
const formBuffer = Buffer.from(mlForm, "utf8");
await socket.writeAll(Buffer.concat([headerBuffer, formBuffer]));
} catch (e) {
console.error(e);
}
}
export function registerNReplCommands(context: vscode.ExtensionContext): void {
context.subscriptions.push(
vscode.commands.registerCommand("opengoal.nrepl.jackin", jackIn),
vscode.commands.registerCommand("opengoal.nrepl.unjack", unJack)
);
updateStatus();
nreplStatusItem.show();
}
export function nreplOnFileSaveHandler(e: vscode.TextDocument) {
if (e.languageId !== "opengoal") {
return;
}
// Get the name
const fileName = path.basename(e.fileName).replace(".gc", "");
console.log(fileName);
reloadFile(fileName);
}

4963
yarn.lock

File diff suppressed because it is too large Load diff