-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the main part of the xref interface #504
Open
ikirill
wants to merge
10
commits into
Sarcasm:master
Choose a base branch
from
ikirill:xref
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ac02a00
Initial implementation of xref.
ikirill e091d05
squash! Finished irony-find-references.
ikirill 1a3a7d3
Formatting.
ikirill 7c4a80d
Add functions for entering/exiting irony-xref
ikirill c360ef7
Fix recursive require
ikirill 129795d
Add short feature list
ikirill d0ae21c
Fix log message
ikirill 2585b70
remove commented out code, and fix up two comments
ikirill 84276cb
Apply clang-tidy
ikirill cd695db
clang-tidy missed one
ikirill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
;;; irony-xref.el --- Irony xref interface | ||
;; | ||
;;; Commentary: | ||
;; | ||
;; To enable, run | ||
;; | ||
;; (add-hook 'irony-mode-hook (lambda () (add-hook 'xref-backend-functions #'irony--xref-backend nil t))) | ||
;; | ||
;; Features: | ||
;; - will jump into system headers | ||
;; - with overloaded functions, will jump to the right function definition | ||
;; (it's not just string matching on the function name) | ||
;; | ||
;; Missing commands: | ||
;; - ‘xref-find-apropos’ | ||
;; | ||
;;; Code: | ||
|
||
(require 'irony) | ||
(require 'irony-completion) | ||
|
||
(require 'xref) | ||
(require 'dash) | ||
|
||
|
||
;; | ||
;; IO tasks | ||
;; | ||
|
||
(irony-iotask-define-task irony--t-xref-definitions | ||
"`xref-definitions' server command." | ||
:start (lambda (line col) | ||
(irony--server-send-command "xref-definitions" line col)) | ||
:update irony--server-query-update) | ||
|
||
(irony-iotask-define-task irony--t-xref-references | ||
"`xref-references' server command." | ||
:start (lambda (line col) | ||
(irony--server-send-command "xref-references" line col)) | ||
:update irony--server-query-update) | ||
|
||
|
||
;; | ||
;; Functions | ||
;; | ||
|
||
;;;###autoload | ||
(defun irony-find-definitions (&optional pos) | ||
(interactive) | ||
(let* ((line-column (irony--completion-line-column pos)) | ||
(line (car line-column)) | ||
(column (cdr line-column))) | ||
(irony--run-task | ||
(irony-iotask-chain | ||
(irony--parse-task) ; FIXME Is parsing even necessary here? | ||
(irony-iotask-package-task irony--t-xref-definitions line column))))) | ||
|
||
;;;###autoload | ||
(defun irony-find-references (&optional pos) | ||
(interactive) | ||
(let* ((line-column (irony--completion-line-column pos)) | ||
(result (irony--run-task | ||
(irony-iotask-chain | ||
(irony--parse-task) ; FIXME Is parsing necessary here? | ||
(irony-iotask-package-task irony--t-xref-references | ||
(car line-column) (cdr line-column)))))) | ||
(cl-loop for item in result | ||
do (message "%S" item)))) | ||
|
||
|
||
;; | ||
;; Xref backend | ||
;; | ||
|
||
;;;###autoload | ||
(defun irony--xref-backend () 'irony) | ||
|
||
(cl-defmethod xref-backend-identifier-completion-table ((_backend (eql irony))) | ||
"A dummy completion table." | ||
nil) | ||
|
||
(cl-defmethod xref-backend-identifier-at-point ((_backend (eql irony))) | ||
;; FIXME These propertized strings are not suitable for completion | ||
;; FIXME which xref asks for | ||
(let* ((bounds (irony-completion-symbol-bounds)) | ||
(start (car bounds)) | ||
(end (cdr bounds)) | ||
;; FIXME Is (buffer-file-name) the right thing here? | ||
(file (buffer-file-name)) | ||
(buffer (current-buffer)) | ||
(line-column (irony--completion-line-column start)) | ||
(thing (buffer-substring-no-properties start end))) | ||
(put-text-property 0 (length thing) 'irony-xref (list file buffer start end) thing) | ||
thing)) | ||
|
||
(cl-defmethod xref-backend-definitions ((_backend (eql irony)) identifier) | ||
(-when-let* | ||
((thing (get-text-property 0 'irony-xref identifier)) | ||
(buffer (nth 1 thing)) | ||
(line-column (irony--completion-line-column (nth 2 thing))) | ||
(result | ||
;; FIXME Must this be synchronous? | ||
(irony--run-task | ||
(irony-iotask-chain | ||
(irony--parse-task buffer) | ||
(irony-iotask-package-task irony--t-xref-definitions | ||
(car line-column) (cdr line-column)))))) | ||
(cl-loop | ||
for (kind name filename line column start end) in result | ||
collect | ||
(xref-make (concat name "(" (symbol-name kind) ")") (xref-make-file-location filename line column))))) | ||
|
||
(cl-defmethod xref-backend-references ((_backend (eql irony)) identifier) | ||
(-when-let* | ||
((thing (get-text-property 0 'irony-xref identifier)) | ||
(buffer (nth 1 thing)) | ||
(line-column (irony--completion-line-column (nth 2 thing))) | ||
(result | ||
;; FIXME Must this be synchronous? | ||
(irony--run-task | ||
(irony-iotask-chain | ||
(irony--parse-task buffer) | ||
(irony-iotask-package-task irony--t-xref-references | ||
(car line-column) (cdr line-column)))))) | ||
(cl-loop | ||
for (kind name filename line column start end) in result | ||
collect | ||
(xref-make name (xref-make-file-location filename line column))))) | ||
|
||
|
||
;; Setting up xref | ||
|
||
(defun irony-xref--enter () | ||
(add-hook 'xref-backend-functions #'irony--xref-backend nil t)) | ||
|
||
(defun irony-xref--exit () | ||
(remove-hook 'xref-backend-functions #'irony--xref-backend t)) | ||
|
||
(provide 'irony-xref) | ||
;;; irony-xref.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,8 @@ | |
|
||
(autoload 'irony-completion--enter "irony-completion") | ||
(autoload 'irony-completion--exit "irony-completion") | ||
(autoload 'irony-xref--enter "irony-xref") | ||
(autoload 'irony-xref--exit "irony-xref") | ||
|
||
(require 'cl-lib) | ||
|
||
|
@@ -426,6 +428,7 @@ If no such file exists on the filesystem the special file '-' is | |
(display-warning 'irony "Performance will be bad because a\ | ||
pipe delay is set for this platform (see variable\ | ||
`w32-pipe-read-delay').")))) | ||
(irony-xref--enter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be optional? |
||
(irony-completion--enter)) | ||
|
||
(defun irony--mode-exit () | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ include(CTest) | |
check_for_in_source_build() | ||
release_as_default_build_type() | ||
|
||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -fsanitize=address -fsanitize=undefined -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-missing-prototypes -Wno-shadow-field-in-constructor") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. debug? |
||
|
||
# Disable exception, we aren't using them and right now clang-cl needs them | ||
# disabled to parse Windows headers. | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug?