Skip to content
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

Eldoc support #166

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/local-data/
/build/
/bin/
TAGS
*~
compile_commands.json
58 changes: 58 additions & 0 deletions irony-exprtype.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
;;; irony-exprtype.el --- Type information at point. -*- lexical-binding: t -*-
;;; Commentary:
;;
;; See Irony::exprtype in Irony.cpp.
;;
;;; Code:

(require 'irony)
(require 'pcase)

(defun irony-exprtype (&optional callback)
"Return type information string at point.

If region is active, will use the region instead."
(interactive)
(if (use-region-p)
(irony-exprtype-region (region-beginning) (region-end) callback)
(irony-exprtype-region (point) (point) callback)))

(defun irony-exprtype-region (start end callback)
(irony--send-file-request
"exprtype"
;; FIXME Why "list" of a callback?
(list (apply-partially #'irony-exprtype--handler callback))
(number-to-string (1- (position-bytes start)))
(number-to-string (1- (position-bytes end)))))

(defun irony-exprtype--fix-offsets (thing)
;; Adjust all values of the form (bound byte-offset byte-offset)
;; to use char offsets instead.
(when (consp thing)
(pcase (car thing)
(`(bounds . (,start-bytes . (,end-bytes . nil)))
(let ((start (byte-to-position (1+ start-bytes)))
(end (byte-to-position (1+ end-bytes))))
(setcar thing (list 'bounds start end))))
(_ (irony-exprtype--fix-offsets (car thing))))
(irony-exprtype--fix-offsets (cdr thing))))

(defun irony-exprtype--handler (callback exprtype)
(irony-exprtype--fix-offsets exprtype)
(if callback (funcall callback exprtype) (message "%S" exprtype)))

;; ;; FIXME Remove when no longer helpful
;; (trace-function #'irony-exprtype)
;; (trace-function #'irony-exprtype-region)
;; (trace-function #'irony-exprtype--handler)
;; (trace-function #'process-send-string)
;; (trace-function #'start-process)
;; (trace-function #'irony--send-file-request)
;; (trace-function #'irony--server-process-filter)
;; (trace-function #'irony--start-server-process)

(provide 'irony-exprtype)
;; Local Variables:
;; byte-compile-warnings: (not cl-functions)
;; End:
;;; irony-exprtype.el ends here
1 change: 1 addition & 0 deletions server/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_executable(irony-server
support/NonCopyable.h
support/TemporaryFile.cpp
support/TemporaryFile.h
support/Sexp.cpp

Command.cpp
Commands.def
Expand Down
9 changes: 8 additions & 1 deletion server/src/Command.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* \file
* \author Guillaume Papin <[email protected]>
*
*
* \brief Command parser definitions.
*
* This file is distributed under the GNU General Public License. See
Expand Down Expand Up @@ -158,6 +158,13 @@ Command *CommandParser::parse(const std::vector<std::string> &argv) {
handleUnsaved = true;
break;

case Command::ExprType:
positionalArgs.push_back(StringConverter(&command_.file));
positionalArgs.push_back(UnsignedIntConverter(&command_.line));
positionalArgs.push_back(UnsignedIntConverter(&command_.column));
handleUnsaved = true;
break;

case Command::Help:
case Command::Exit:
break;
Expand Down
3 changes: 3 additions & 0 deletions server/src/Commands.def
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ X(Diagnostics, "diagnostics", "FILE - look for diagnostics in file")
X(Complete,
"complete",
"FILE LINE COL - perform code completion at a given location")
X(ExprType,
"exprtype",
"FILE START END - get type of expression between byte offsets START and END")
X(Help, "help", "show this message")
X(Exit, "exit", "exit interactive mode, print nothing")
X(SetDebug, "set-debug", "[on|off] - enable or disable verbose logging")
Expand Down
Loading