Skip to content

Commit cf6850a

Browse files
authored
Merge pull request #1 from 0x100101/feat-additional-lang-support
Additional Lang Support
2 parents d0331f8 + 844d6a6 commit cf6850a

21 files changed

+1376
-121
lines changed

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,35 @@
1010

1111
### Code Runner
1212
- The foundational feature for lab.nvim is a code runner with real-time, inline feedback. (Inspired by [runjs](https://runjs.app/), [quokka](https://quokkajs.com/) and others.)
13-
- The code runner currently supports javascript with additional language support planned for the very near future.
14-
- The goal of the code runner isn't to be a full-fledged debugger.
13+
- The code runner currently supports Javascript, Typescript, Python, and Lua with additional language support planned.
14+
- The goal of the code runner isn't to be a full-fledged debugger, rather it aims to provide a simple rapid feedback mechanism that can be useful while working on protoyping tasks.
1515

1616
[code-runner-demo.webm](https://user-images.githubusercontent.com/106625318/178158478-09f4fc29-7dbe-4d34-a56c-64c9f4ecae54.webm)
1717

1818
#### Commands
1919

2020
| Command | Action |
2121
:---------| :-------
22-
| `Lab code run` | Run or resume the code runner on the current buffer. |
23-
| `Lab code stop` | Stop the code runner on the current buffer. |
24-
| `Lab code panel` | Show the code runner info buffer |
22+
| `Lab code run` | Run or resume the code runner on the current file. |
23+
| `Lab code stop` | Stop the code runner on the current file. |
24+
| `Lab code panel` | Show the code runner info buffer. |
25+
| `Lab code config` | Show the code runner config for the current file. |
26+
27+
Note that the run command is also automatically invoked each time you save changes to a file that is currently active.
2528

2629
## Requirements
2730
- neovim >= 0.7.2
2831
- plenary.nvim
2932
- node >= 16.10.0
3033

34+
## Optional Requirements
35+
- Python 3 (Python code runner)
36+
- Lua 5.4 (Lua code runner)
37+
3138
## Example Setup
3239

40+
**Important:** Notice the post install hook. Lab.nvim has a few internal node dependencies that should be installed. See: [package.json](https://github.com/0x100101/lab.nvim/blob/main/js/package.json#L10)
41+
3342
```
3443
Plug 'nvim-lua/plenary.nvim'
3544
Plug '0x100101/lab.nvim', { 'do': 'cd js && npm ci' }
@@ -40,3 +49,8 @@ nnoremap <F4> :Lab code stop<CR>
4049
nnoremap <F5> :Lab code run<CR>
4150
nnoremap <F6> :Lab code panel<CR>
4251
```
52+
53+
## Road Map
54+
- Add tests.
55+
- Expose more configuration options.
56+
- Perf audit.

js/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-exact=true

js/constants.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,27 @@ export const RPC_METHOD = {
3131
RUNNER_RESUME: 'Lab.Runner.Resume',
3232
}
3333

34-
export const RUNNER_FILE_MAPPINGS = {
35-
'js': 'node',
34+
export const PROCESSORS = {
35+
ESBUILD: 'lab.esbuild'
36+
}
37+
38+
export const RUNNERS = {
39+
NODE: 'lab.node',
40+
PYTHON: 'lab.python',
41+
LUA: 'lab.lua',
42+
};
43+
44+
export const PROCESSORS_PATH = './processors/';
45+
export const RUNNERS_PATH = './runners/';
46+
47+
export const PROCESSOR_PATHS = {
48+
[PROCESSORS.ESBUILD]: PROCESSORS_PATH + 'esbuild.js',
49+
};
50+
51+
export const RUNNER_PATHS = {
52+
[RUNNERS.NODE]: RUNNERS_PATH + 'node/node.js',
53+
[RUNNERS.PYTHON]: RUNNERS_PATH + 'python/python.js',
54+
[RUNNERS.LUA]: RUNNERS_PATH + 'lua/lua.js',
3655
};
3756

38-
export const WS_REGEX = /ws:\/\/\S*/ig;
3957

js/index.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,52 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
2121
import readline from 'node:readline';
2222
import { stdin, stdout } from 'node:process';
2323
import jsonrpc from 'jsonrpc-lite';
24-
import { logger } from './logging.js';
25-
import { print } from './util.js';
26-
import { DEBUG, RPC_TYPE, RPC_METHOD, RUNNER_FILE_MAPPINGS } from './constants.js'
27-
import { Runner } from './runner.js';
24+
import { logger } from './util/logging.js';
25+
import { print } from './util/index.js';
26+
import { RPC_TYPE, RPC_METHOD } from './constants.js'
27+
import { runner } from './runner.js';
2828

2929
const log = logger();
3030
const input = readline.createInterface({ input: stdin, output: stdout });
31-
const runner = new Runner();
3231

3332
while (true) {
3433
const data = await new Promise(async (resolve) => {
3534
input.question('', (remoteInput) => resolve(remoteInput));
3635
});
3736
try {
3837
const message = jsonrpc.parse(data)
39-
if (DEBUG) log.info(message);
38+
log(message);
4039
({
4140
[RPC_TYPE.REQUEST]: {
4241
[RPC_METHOD.RUNNER_START]: async () => {
43-
const started = await runner.start(message.payload.params);
42+
const [started, startedMsg] = await runner.start(message.payload.params);
4443
if (!started) {
45-
print(jsonrpc.error(message.payload.id, new jsonrpc.JsonRpcError('runner not started', 101)));
44+
print(jsonrpc.error(message.payload.id, new jsonrpc.JsonRpcError(`Runner not started: ${startedMsg}`, 101)));
4645
return;
4746
}
4847
print(jsonrpc.success(message.payload.id, 'ok'));
4948
},
5049
[RPC_METHOD.RUNNER_STOP]: () => {
51-
const stopped = runner.stop(message.payload.params);
50+
const [stopped, stopMsg] = runner.stop(message.payload.params);
5251
if (!stopped) {
53-
print(jsonrpc.error(message.payload.id, new jsonrpc.JsonRpcError('runner not stopped', 102)));
52+
print(jsonrpc.error(message.payload.id, new jsonrpc.JsonRpcError(`Runner not stopped ${stopMsg}`, 102)));
5453
return;
5554
}
5655
print(jsonrpc.success(message.payload.id, 'ok'));
5756
},
5857
[RPC_METHOD.RUNNER_RESUME]: () => {
59-
const resumed = runner.resume(message.payload.params);
58+
const [resumed, resumeMsg] = runner.resume(message.payload.params);
6059
if (!resumed) {
61-
print(jsonrpc.error(message.payload.id, new jsonrpc.JsonRpcError('runner not resumed', 102)));
60+
print(jsonrpc.error(message.payload.id, new jsonrpc.JsonRpcError(`Runner not resumed ${resumeMsg}`, 102)));
6261
return;
6362
}
6463
print(jsonrpc.success(message.payload.id, 'ok'));
6564
},
6665
},
6766
}[message.type][message.payload.method]());
6867
} catch (err) {
69-
if (DEBUG) log.error(err);
70-
print(jsonrpc.error(message.payload.id, new jsonrpc.JsonRpcError('routing error occured', 100)));
68+
log(err);
69+
print(jsonrpc.error(0, new jsonrpc.JsonRpcError(`routing error occured ${err}`, 100)));
7170
continue;
7271
}
7372
}

0 commit comments

Comments
 (0)