Skip to content

Commit 6accd08

Browse files
committed
Got gd working for Clojure core code
1 parent e631c92 commit 6accd08

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

src/clojure.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl FromStr for Lang {
2828

2929
pub fn bootstrap() -> String {
3030
"
31-
(require #?@(:clj ['clojure.repl 'clojure.main]
31+
(require #?@(:clj ['clojure.repl 'clojure.main 'clojure.java.io 'clojure.string]
3232
:cljs ['cljs.repl]))
3333
3434
(do
@@ -38,7 +38,18 @@ pub fn bootstrap() -> String {
3838
}
3939

4040
pub fn definition(name: &str) -> String {
41-
format!("(map (meta #'{}) [:file :line :column])", name)
41+
format!(
42+
"
43+
(update
44+
(mapv (meta #'{}) [:file :line :column])
45+
0
46+
#?(:cljs identity
47+
:clj #(-> (clojure.java.io/resource %)
48+
(str)
49+
(clojure.string/replace #\"^jar:file\" \"zipfile\")
50+
(clojure.string/replace #\"\\.jar!/\" \".jar::\"))))
51+
",
52+
name)
4253
}
4354

4455
pub fn eval(code: &str, ns: &str, lang: &Lang) -> String {

src/pool.rs

+1-25
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,6 @@ enum Error {
2424
ConnectionMissing { key: String },
2525
}
2626

27-
fn parse_location(locs: &str) -> Option<(String, i64, i64)> {
28-
lazy_static! {
29-
static ref loc_re: Regex =
30-
Regex::new(r#"^\("(.*)" (\d+) (\d+)\)$"#).expect("failed to compile location regex");
31-
}
32-
33-
if let Some(cap) = loc_re.captures_iter(locs).next() {
34-
match (cap.get(1), cap.get(2), cap.get(3)) {
35-
(Some(path), Some(row), Some(col)) => Some((
36-
path.as_str().to_owned(),
37-
row.as_str().parse().unwrap_or(1),
38-
col.as_str().parse().unwrap_or(1),
39-
)),
40-
_ => {
41-
warn!("Couldn't extract capture groups: {}", locs);
42-
None
43-
}
44-
}
45-
} else {
46-
warn!("Result didn't match expression: {}", locs);
47-
None
48-
}
49-
}
50-
5127
impl Connection {
5228
pub fn connect(addr: SocketAddr, expr: Regex, lang: clojure::Lang) -> Result<Self> {
5329
Ok(Self {
@@ -100,7 +76,7 @@ impl Connection {
10076
.expect("couldn't get responses")
10177
{
10278
match response {
103-
Ok(Response::Ret(msg)) => if let Some(loc) = parse_location(&msg) {
79+
Ok(Response::Ret(msg)) => if let Some(loc) = util::parse_location(&msg) {
10480
if let Err(msg) = go_to_definition_server.go_to(loc) {
10581
go_to_definition_server
10682
.err_writeln(&format!("Error while going to definition: {}", msg))

src/util.rs

+24
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ pub fn ns(source: &str) -> Option<String> {
2727
}
2828
}
2929

30+
pub fn parse_location(locs: &str) -> Option<(String, i64, i64)> {
31+
lazy_static! {
32+
static ref loc_re: Regex =
33+
Regex::new(r#"^\["(.*)" (\d+) (\d+)\]$"#).expect("failed to compile location regex");
34+
}
35+
36+
if let Some(cap) = loc_re.captures_iter(locs).next() {
37+
match (cap.get(1), cap.get(2), cap.get(3)) {
38+
(Some(path), Some(row), Some(col)) => Some((
39+
path.as_str().to_owned(),
40+
row.as_str().parse().unwrap_or(1),
41+
col.as_str().parse().unwrap_or(1),
42+
)),
43+
_ => {
44+
warn!("Couldn't extract capture groups: {}", locs);
45+
None
46+
}
47+
}
48+
} else {
49+
warn!("Result didn't match expression: {}", locs);
50+
None
51+
}
52+
}
53+
3054
#[cfg(test)]
3155
mod tests {
3256
use super::*;

0 commit comments

Comments
 (0)