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