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

Update semantic highlighting code in line with the update IDE protocol #547

Merged
merged 4 commits into from
Jan 5, 2022
Merged
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
20 changes: 16 additions & 4 deletions idris-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,27 @@ A prefix argument forces loading but only up to the current line."
for h in hs
do (pcase h
(`(((:filename ,fn)
(:start ,start-line ,start-col)
(:end ,end-line ,end-col))
(:start ,start-line-raw ,start-col-raw)
(:end ,end-line-raw ,end-col-raw))
,props)
(when (string= (file-name-nondirectory fn)
(file-name-nondirectory (buffer-file-name)))
(idris-highlight-input-region (current-buffer)
(let ((start-line (if (>=-protocol-version 2 1)
(+ 1 start-line-raw)
start-line-raw))
(start-col (if (>=-protocol-version 2 1)
(+ 1 start-col-raw)
start-col-raw))
(end-line (if (>=-protocol-version 2 1)
(+ 1 end-line-raw)
end-line-raw ))
(end-col (if (>= idris-protocol-version 2 1)
(+ 1 end-col-raw)
end-col-raw )))
(idris-highlight-input-region (current-buffer)
start-line start-col
end-line end-col
props))))))
props)))))))
(_ (idris-make-clean)
(idris-update-options-cache)

Expand Down
8 changes: 8 additions & 0 deletions idris-common-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,12 @@ relative to SRC-DIR"
(when (file-exists-p lidr)
(make-link lidr))))))

(defvar idris-protocol-version 0 "The protocol version")
(defvar idris-protocol-version-minor 0 "The protocol minor version")

(defun >=-protocol-version (major minor)
(or (> idris-protocol-version major)
(and (>= idris-protocol-version major)
(>= idris-protocol-version-minor minor))))

(provide 'idris-common-utils)
4 changes: 2 additions & 2 deletions idris-highlight-input.el
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ See Info node `(elisp)Overlay Properties' to understand how ARGS are used."
(widen)
(if (or (> end-line start-line)
(and (= end-line start-line)
(>= end-col start-col)))
(> end-col start-col)))
(with-current-buffer buffer
(save-excursion
(goto-char (point-min))
(let* ((start-pos (+ (line-beginning-position start-line)
(idris-highlight-column start-col)))
(end-pos (+ (line-beginning-position end-line)
(idris-highlight-column (+ 1 end-col))))
(idris-highlight-column end-col)))
(highlight-overlay (make-overlay start-pos end-pos
(get-buffer buffer))))
(overlay-put highlight-overlay 'idris-source-highlight t)
Expand Down
16 changes: 12 additions & 4 deletions idris-warnings.el
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,18 @@ WARNING is of form (filename (startline startcolumn) (endline endcolumn) message
As of 20140807 (Idris 0.9.14.1-git:abee538) (endline endcolumn) is mostly the same as (startline startcolumn)
"
(cl-destructuring-bind (filename sl1 sl2 message spans) warning
(let ((startline (nth 0 sl1))
(startcol (1- (nth 1 sl1)))
(endline (nth 0 sl2))
(endcol (1- (nth 1 sl2))))
(let ((startline (if (>=-protocol-version 2 1)
(1+ (nth 0 sl1))
(nth 0 sl1)))
(startcol (if (>=-protocol-version 2 1)
(nth 1 sl1)
(1- (nth 1 sl1))))
(endline (if (>=-protocol-version 2 1)
(1+ (nth 0 sl2))
(nth 0 sl2)))
(endcol (if (>=-protocol-version 2 1)
(nth 1 sl2)
(1- (nth 1 sl2)))))
(push (list filename startline startcol message spans) idris-raw-warnings)
(let* ((fullpath (concat (file-name-as-directory idris-process-current-working-directory)
filename))
Expand Down
5 changes: 2 additions & 3 deletions inferior-idris.el
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@
(defvar idris-connection nil
"The Idris connection.")

(defvar idris-protocol-version 0 "The protocol version")

(defun idris-version-hook-function (event)
(pcase event
(`(:protocol-version ,version ,_target)
(`(:protocol-version ,version ,minor)
(setf idris-protocol-version version)
(setf idris-protocol-version-minor minor)
(remove-hook 'idris-event-hooks 'idris-version-hook-function)
t)))

Expand Down