(defun dojo-js-navigation-jump-to-own-main-css () (interactive) (let* ((name-to-project (dojo-workspace-name-to-project dojo-current-workspace)) (id-to-resource (dojo-workspace-id-to-resource dojo-current-workspace)) (resource (dojo-core-util-get-current-resource)) (project-name (if resource (dojo-resource-project resource) nil)) (project (if project-name (gethash project-name name-to-project) nil)) (css-resources (if project (dojo-project-css-resources project) nil)) (main-css-resource-id (if css-resources (gethash DOJO-PROJECT-CSS-MAIN css-resources) nil)) (main-css-resource (if (not (null main-css-resource-id)) (gethash main-css-resource-id id-to-resource) nil)) (main-file-path (if main-css-resource (dojo-resource-file-path main-css-resource) nil))) (cond ((null resource) (message "Could not find current resource.")) ((null css-resources) (message "Could not find css resources in project [%s]" project-name)) ((null main-file-path) (message "Could not find file-path for resource [%s]" main-css-resource-id)) (t (find-file main-file-path))))) (defun dojo-js-navigation-jump-to-own-main-i18n () (interactive) "Jumps to the i18n file corresponding to the first i18n import pointing to the own project." (let* ((i18n-symbol (dojo-core-util-get-own-main-i18n-symbol))) (if i18n-symbol (dojo-js-navigation-jump-to-import i18n-symbol)))) (defun dojo-js-navigation-jump-to-import (import-symbol) (let* ((resource-id (dojo-symbol-get-import-resource-id import-symbol)) (id-to-resource (dojo-workspace-id-to-resource dojo-current-workspace)) (resource (if resource-id (gethash resource-id id-to-resource) nil))) (if resource (let ((file-path (dojo-resource-file-path resource))) (find-file file-path))))) (defun dojo-js-navigation-jump-to-symbol-at-point () (interactive) "Jumps to the symbol represented by the source code at point. E.g., if point is at a import, opens the corresponding file." (let* ((inspect-path (dojo-js-inspect-get-inspect-path-at-point)) (last-inspect-token (nth (1- (length inspect-path)) inspect-path)) (symbol (if last-inspect-token (dojo-inspect-token-symbol last-inspect-token) nil))) (log-inspect (format "Called dojo-js-navigation-jump-to-symbol-at-point for symbol %s" (dojo-core-util-symbol-to-short-string symbol))) (cond ((null inspect-path) (message "Could not determine the inspect path, which gives us the information what we have at point. Maybe, the currently opened class was not yet parsed.")) ((null symbol) (message "Could not resolve symbol at point.")) ((dojo-core-util-is-import-symbol symbol) (dojo-js-navigation-jump-to-import symbol)) (t (let* ((current-class (dojo-workspace-get-current-class)) (current-class-id (if current-class (dojo-class-id current-class) nil)) (class-id (dojo-symbol-class-id symbol)) (min-pos (dojo-symbol-min-pos symbol))) (log-inspect (format "... class-id is [%s], min-pos is [%s]" class-id min-pos)) (cond ((null current-class-id) (message "Could not find current class.")) ((null class-id) (message (format "Symbol %s has no class id. Cannot determine the destination." (dojo-core-util-symbol-to-short-string symbol)))) ((null min-pos) (message (format "Symbol %s has no position information. Cannot determine jump destination." (dojo-core-util-symbol-to-short-string symbol)))) ((= current-class-id class-id) (dojo-js-navigation-jump-to-position min-pos)) (t (let* ((id-to-api-class (dojo-workspace-id-to-api-class dojo-current-workspace)) (target-class (gethash class-id id-to-api-class)) (target-resource-id (if target-class (dojo-class-resource-id target-class) nil))) (if (null target-class) (message (format (concat "Could not jump to symbol %s, as its class is not loaded. " "This is strange, as this should have been done by the code determining the symbol.") (dojo-core-util-symbol-to-short-string symbol))) (dojo-core-util-jump-to-resource-file dojo-current-workspace target-resource-id) (dojo-js-navigation-jump-to-position min-pos)))))))))) (defun dojo-js-navigation-jump-to-position (pos) (back-button-push-mark-local-and-global) (goto-char pos)) (defun dojo-js-navigation-jump-to-tree-pos (tree-number) (interactive "nNumber according to *Tree* buffer: ") (cond ((eq dojo-js-tree-mode 'DOJO-TREE-MODE-CLASS) (let* ((symbol-with-resource (if dojo-js-tree-key-to-data (gethash tree-number dojo-js-tree-key-to-data) nil)) (symbol-id (if symbol-with-resource (nth 0 symbol-with-resource) nil)) (api-resource-id (if symbol-with-resource (nth 1 symbol-with-resource) nil)) (id-to-resource (dojo-workspace-id-to-resource dojo-current-workspace)) (resource (if api-resource-id (gethash api-resource-id id-to-resource) nil)) (file-path (if resource (dojo-resource-file-path resource) nil)) (api-class (if resource (dojo-js-api-get-class-by-resource-id api-resource-id) nil)) (id-to-symbol (if api-class (dojo-class-id-to-symbol api-class) nil)) (symbol (if (not (null symbol-id)) (gethash symbol-id id-to-symbol) nil)) (min-pos (if symbol (dojo-symbol-min-pos symbol) nil))) (if (and resource (not (null symbol-id))) (progn (find-file file-path) (if (not (null min-pos)) (goto-char min-pos)))))) ((eq dojo-js-tree-mode 'DOJO-TREE-MODE-CSS) (let* ((css-list (if dojo-js-tree-key-to-data (gethash tree-number dojo-js-tree-key-to-data) nil)) (resource-id (if css-list (nth 0 css-list) nil)) (id-to-resource (dojo-workspace-id-to-resource dojo-current-workspace)) (resource (if resource-id (gethash resource-id id-to-resource) nil)) (file-path (if resource (dojo-resource-file-path resource) nil))) (if (and resource file-path) (find-file file-path)))) (t (log-tree (format "Unknown mode [%s] when jumping to tree position." dojo-js-tree-mode))))) (provide 'dojo-js-navigation)