Skip to content

Commit

Permalink
Merge commit 'miaubiz/hyperlink-detector' into miaubiz-int
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentpetit committed Feb 28, 2010
2 parents db50061 + e16e980 commit 6e544e8
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ccw.core/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ ClojureSelectEnclosing_label=Enclosing Element
GoTo_label=Go to
GoTo_matchingBracket_label=Matching Bracket
GoTo_previousTopLevelSexpr_label=Previous Top Level S-Expression
GoTo_nextTopLevelSexpr_label=Next Top Level S-Expression
GoTo_nextTopLevelSexpr_label=Next Top Level S-Expression

clojureHyperlinkDetector=Clojure hyperlink detector
16 changes: 16 additions & 0 deletions ccw.core/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>

<extension point="org.eclipse.ui.console.consolePatternMatchListeners">
<consolePatternMatchListener
id="ccw.editors.antlrbased.StacktraceHyperlink"
regex="at .*[\w]+\.clj:[0-9]+"
class="ccw.editors.antlrbased.StacktraceHyperlink">
<enablement>
<or>
<test property="org.eclipse.ui.console.consoleTypeTest" value="javaStackTraceConsole"/>
<test property="org.eclipse.debug.ui.processTypeTest" value="java"/>
</or>
</enablement>
</consolePatternMatchListener>
</extension>


<extension
point="org.eclipse.ui.newWizards">
<category
Expand Down
67 changes: 67 additions & 0 deletions ccw.core/src/ccw/editors/antlrbased/StacktraceHyperlink.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
; *******************************************************************************
; * Copyright (c) 2010 Tuomas KARKKAINEN.
; * All rights reserved. This program and the accompanying materials
; * are made available under the terms of the Eclipse Public License v1.0
; * which accompanies this distribution, and is available at
; * http://www.eclipse.org/legal/epl-v10.html
; *
; * Contributors:
; * Tuomas KARKKAINEN - initial API and implementation
; *******************************************************************************/

(ns ccw.editors.antlrbased.StacktraceHyperlink
(:require [clojure.contrib.str-utils2 :as s])
(:use [clojure.test])
(:gen-class
:init init
:state state
:implements [org.eclipse.ui.console.IPatternMatchListenerDelegate]))

(defn -init []
[[] (ref nil)])

(defn -connect [this console]
(dosync (ref-set (.state this) console)))

(defn -disconnect [this])

(defn- find-datas [s]
{:line (Integer/valueOf (second (re-find #":([0-9]+)" s)))
:file (str (s/replace (second (re-find #"at ([\w\.]+)\$" s)) "." "/") ".clj")
:ns (s/replace (second (re-find #"at ([\w\.]+)\$" s)) "_" "-")})

(defn- open-file [s]
(let [x (find-datas s)]
(ccw.ClojureCore/openInEditor (:ns x) (:file x) (:line x))))

(defn- offset-and-length [s]
(map + [1 0] (map count (s/split s #"\("))))

(defn -matchFound [this event]
(let [console @(.state this)
offset (.getOffset event)
s (.get (.getDocument console) offset (.getLength event))
[o l] (offset-and-length s)
hyperlink (proxy [org.eclipse.ui.console.IHyperlink] []
(linkActivated [] (open-file s))
(linkExited [])
(linkEntered []))]
(.addHyperlink console hyperlink (+ offset o) l)))

(def sample-string "at clojure.contrib.repl_ln$_main__7172.doInvoke(repl_ln.clj:140")

(deftest offset-and-length-are-determined
(is (= [48 15] (offset-and-length sample-string)))
(is (= "repl_ln.clj:140" (s/take (s/drop sample-string 48) 15)))
(is (= "repl_ln.clj:14" (s/take (s/drop sample-string 48) 14))))

(def test-data (find-datas sample-string))

(deftest string-is-parsed
(is (= "clojure.contrib.repl-ln" (:ns test-data)))
(is (= "clojure/contrib/repl_ln.clj" (:file test-data)))
(is (= 140 (:line test-data))))

; (println "actual:" test-data)
; (run-tests)

0 comments on commit 6e544e8

Please sign in to comment.