Minor refactoring
This commit is contained in:
parent
72393480e3
commit
f6c40813d2
|
@ -7,6 +7,7 @@
|
|||
"Nathan McCarty <thatonelutenist@stranger.systems>"
|
||||
],
|
||||
"provides": {
|
||||
"IUtils": "lib/IUtils.rakumod",
|
||||
"IUtils::IDEMode": "lib/IUtils/IDEMode.rakumod"
|
||||
},
|
||||
"bin": {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#!/usr/bin/env raku
|
||||
use v6.d;
|
||||
use IUtils::IDEMode;
|
||||
use IUtils;
|
||||
|
||||
my $ide = IUtils::IDEMode::IDEMode.new();
|
||||
my $ide = IUtils::IDEMode.new();
|
||||
# my @res = $ide.browse-namespace: 'Data.List';
|
||||
# say @res;
|
||||
|
||||
|
@ -14,7 +14,6 @@ say @res.raku;
|
|||
|
||||
@res = $ide.interpret: ':exec works >>= print';
|
||||
say @res.raku;
|
||||
say $ide.read-sexp();
|
||||
|
||||
@res = $ide.interpret: ':exec fails';
|
||||
say @res.raku;
|
||||
|
|
3
lib/IUtils.rakumod
Normal file
3
lib/IUtils.rakumod
Normal file
|
@ -0,0 +1,3 @@
|
|||
unit module IUtils;
|
||||
|
||||
need IUtils::IDEMode;
|
|
@ -1,4 +1,9 @@
|
|||
unit module IUtils::IDEMode;
|
||||
unit class IUtils::IDEMode;
|
||||
|
||||
has $!process;
|
||||
has $!port;
|
||||
has $!socket;
|
||||
has $!request-id = 0;
|
||||
|
||||
grammar SExp {
|
||||
rule TOP { <sexp> }
|
||||
|
@ -35,13 +40,7 @@ class SExp::Actions {
|
|||
}
|
||||
}
|
||||
|
||||
class IDEMode {
|
||||
has $!process;
|
||||
has $!port;
|
||||
has $!socket;
|
||||
has $!request-id = 0;
|
||||
|
||||
submethod TWEAK {
|
||||
submethod TWEAK {
|
||||
# Start idris2 in IDE mode
|
||||
my $ret = Promise.new;
|
||||
$!process = Proc::Async.new('idris2', '--ide-mode-socket');
|
||||
|
@ -69,24 +68,24 @@ class IDEMode {
|
|||
say "Idris 2 Version: ", @version[0], ".", @version[1], ".", @version[2],
|
||||
" (", $commit, ")";
|
||||
say "IDE Protocol Version: $major.$minor";
|
||||
}
|
||||
}
|
||||
|
||||
method process-protocol-version() {
|
||||
method process-protocol-version() {
|
||||
my @resp = self.read-sexp();
|
||||
if @resp[0] eq ':protocol-version' {
|
||||
return (@resp[1], @resp[2]);
|
||||
}
|
||||
die "Expected protocol version, got: ", @resp;
|
||||
}
|
||||
}
|
||||
|
||||
method read-sexp() {
|
||||
method read-sexp() {
|
||||
my $len = $!socket.read(6).decode('utf8');
|
||||
my $msg = $!socket.read(:bin, $len.parse-base(16)).decode('utf8');
|
||||
# say "Got: ", $len, $msg;
|
||||
SExp.parse($msg, actions => SExp::Actions).made
|
||||
}
|
||||
}
|
||||
|
||||
method send-command(*@cmd) {
|
||||
method send-command(*@cmd) {
|
||||
my $id = ++$!request-id;
|
||||
my $cmd-str;
|
||||
if @cmd.elems > 1 {
|
||||
|
@ -107,40 +106,38 @@ class IDEMode {
|
|||
return @responses;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
method load-file($filename, $line-number?){
|
||||
method load-file($filename, $line-number?){
|
||||
if $line-number {
|
||||
self.send-command('load-file', "\"$filename\"", $line-number.Str)
|
||||
} else {
|
||||
self.send-command('load-file', "\"$filename\"")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
method cd($filepath) {
|
||||
method cd($filepath) {
|
||||
self.send-command('cd', "\"$filepath\"")
|
||||
}
|
||||
}
|
||||
|
||||
method interpret($cmd) {
|
||||
method interpret($cmd) {
|
||||
self.send-command('interpret', "\"$cmd\"")
|
||||
}
|
||||
}
|
||||
|
||||
method type-of($item) {
|
||||
method type-of($item) {
|
||||
self.send-command('type-of', "\"$item\"")
|
||||
}
|
||||
}
|
||||
|
||||
method docs-for($item) {
|
||||
method docs-for($item) {
|
||||
self.send-command('docs-for', "\"$item\"")
|
||||
}
|
||||
}
|
||||
|
||||
method browse-namespace($namespace) {
|
||||
method browse-namespace($namespace) {
|
||||
# Import the namespace first to make sure this works properly
|
||||
self.interpret: ":import $namespace";
|
||||
self.send-command('browse-namespace', "\"$namespace\"")
|
||||
}
|
||||
|
||||
method version() {
|
||||
self.send-command('version')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
method version() {
|
||||
self.send-command('version')
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue