|
28 | 28 | [clooj.search]
|
29 | 29 | [clooj.help :only (arglist-from-caret-pos show-tab-help setup-tab-help
|
30 | 30 | setup-completion-list help-handle-caret-move
|
31 |
| - find-focused-text-pane)] |
| 31 | + find-focused-text-pane safe-resolve |
| 32 | + token-from-caret-pos)] |
32 | 33 | [clooj.project :only (add-project load-tree-selection
|
33 | 34 | load-expanded-paths load-project-set
|
34 | 35 | save-expanded-paths
|
|
53 | 54 | scroll-to-caret when-lets
|
54 | 55 | constrain-to-parent make-split-pane
|
55 | 56 | gen-map on-click
|
56 |
| - remove-text-change-listeners get-text-str)] |
| 57 | + remove-text-change-listeners get-text-str |
| 58 | + scroll-to-line get-directories)] |
57 | 59 | [clooj.indent :only (setup-autoindent fix-indent-selected-lines)]
|
58 | 60 | [clooj.style :only (get-monospaced-fonts show-font-window)])
|
59 | 61 | (:require [clojure.main :only (repl repl-prompt)]
|
|
650 | 652 | (update-project-tree (:docs-tree app))
|
651 | 653 | (restart-doc app f))))))
|
652 | 654 |
|
653 |
| - |
| 655 | +(defn- dir-rank [dir] |
| 656 | + (get {"src" 0 "test" 1 "lib" 2} (.getName dir) 100)) |
| 657 | + |
| 658 | +(defn- find-file [project-path relative-file-path] |
| 659 | + (let [classpath-dirs (sort-by dir-rank < (get-directories (File. project-path))) |
| 660 | + file-candidates (map |
| 661 | + #(File. (str (.getAbsolutePath %) File/separatorChar relative-file-path)) |
| 662 | + classpath-dirs)] |
| 663 | + (first (filter #(and (.exists %) (.isFile %)) file-candidates)))) |
| 664 | + |
| 665 | +(defn goto-definition [ns app] |
| 666 | + (let [text-comp (:doc-text-area app) |
| 667 | + pos (.getCaretPosition text-comp) |
| 668 | + text (.getText text-comp) |
| 669 | + src-file (:file (meta (safe-resolve (find-ns (symbol ns)) (token-from-caret-pos ns text pos)))) |
| 670 | + line (:line (meta (safe-resolve (find-ns (symbol ns)) (token-from-caret-pos ns text pos)))) |
| 671 | + project-path (first (get-selected-projects app)) |
| 672 | + file (find-file project-path src-file)] |
| 673 | + (when (and file line) |
| 674 | + (when (not= file @(:file app)) |
| 675 | + (restart-doc app file) |
| 676 | + (set-tree-selection (:docs-tree app) (.getAbsolutePath file))) |
| 677 | + (scroll-to-line text-comp line)))) |
654 | 678 |
|
655 | 679 | (defn make-menus [app]
|
656 | 680 | (when (is-mac)
|
|
677 | 701 | ["Fix indentation" "F" "cmd1 BACK_SLASH" #(fix-indent-selected-lines (:doc-text-area app))]
|
678 | 702 | ["Indent lines" "I" "cmd1 CLOSE_BRACKET" #(indent (:doc-text-area app))]
|
679 | 703 | ["Unindent lines" "D" "cmd1 OPEN_BRACKET" #(indent (:doc-text-area app))]
|
680 |
| - ["Name search/docs" "S" "TAB" #(show-tab-help app (find-focused-text-pane app) inc)]) |
| 704 | + ["Name search/docs" "S" "TAB" #(show-tab-help app (find-focused-text-pane app) inc)] |
| 705 | + ["Goto definition" "G" "F3" #(goto-definition (get-file-ns app) app)]) |
681 | 706 | (add-menu menu-bar "REPL" "R"
|
682 | 707 | ["Evaluate here" "E" "cmd1 ENTER" #(send-selected-to-repl app)]
|
683 | 708 | ["Evaluate entire file" "F" "cmd1 E" #(send-doc-to-repl app)]
|
|
772 | 797 | ; []
|
773 | 798 | ; (.setVisible (@current-app :frame) false)
|
774 | 799 | ; (startup))
|
| 800 | + |
0 commit comments