Skip to content

Commit

Permalink
Merge pull request #1766 from voodoos/502+PWO
Browse files Browse the repository at this point in the history
Add support for project-wide occurrences
  • Loading branch information
voodoos authored Jun 4, 2024
2 parents a7e8e6e + 2dfa1fc commit bd900fd
Show file tree
Hide file tree
Showing 32 changed files with 568 additions and 156 deletions.
14 changes: 14 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
UNRELEASED
==========

+ merlin binary
- Support project-wide occurrences queries using index files (#1766)
- The file format is described in library `Merlin_lib.index_format`
- Two new configuration directives are introduced:
- `SOURCE_ROOT` that is used to resolve relative paths found in the
indexes.
- `INDEX` that is used to declare the list of index files Merlin should
use when looking for occurrences.
+ editor modes
- emacs: add basic support for project-wide occurrences (#1766)

merlin 5.0
==========
Fri May 17 19:59:42 CET 2024
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(lang dune 2.9)
(lang dune 3.0)
(name merlin)
(using menhir 2.0)

Expand Down
56 changes: 39 additions & 17 deletions emacs/merlin.el
Original file line number Diff line number Diff line change
Expand Up @@ -1784,37 +1784,33 @@ Empty string defaults to jumping to all these."
(let ((inhibit-read-only t)
(buffer-undo-list t)
(pending-line)
(pending-lines-text))
(pending-lines-text)
(previous-buf))
(erase-buffer)
(occur-mode)
(insert (propertize (format "%d occurrences in buffer: %s"
(length lst)
src-buff)
'font-lock-face list-matching-lines-buffer-name-face
'read-only t
'occur-title (get-buffer src-buff)))
(insert "\n")
(dolist (pos positions)
(let* ((marker (cdr (assoc 'marker pos)))
(start (assoc 'start pos))
(let* ((start (assoc 'start pos))
(end (assoc 'end pos))
(file (cdr (assoc 'file pos)))
(occ-buff (if file (find-file-noselect file) src-buff))
(marker (with-current-buffer occ-buff
(copy-marker (merlin--point-of-pos start))))
(line (cdr (assoc 'line start)))
(start-buf-pos (with-current-buffer src-buff
(start-buf-pos (with-current-buffer occ-buff
(merlin--point-of-pos start)))
(end-buf-pos (with-current-buffer src-buff
(end-buf-pos (with-current-buffer occ-buff
(merlin--point-of-pos end)))
(prefix-length 8)
(start-offset (+ prefix-length
(cdr (assoc 'col start))))
(lines-text
(if (equal line pending-line)
pending-lines-text
(if (and (equal line pending-line) occ-buff)
pending-lines-text
(merlin--occurrence-text line
marker
start-buf-pos
end-buf-pos
src-buff))))

occ-buff))))
;; Insert the critical text properties that occur-mode
;; makes use of
(add-text-properties start-offset
Expand All @@ -1828,9 +1824,22 @@ Empty string defaults to jumping to all these."
;; found in order to accumulate multiple matches within
;; one line.
(when (and pending-lines-text
(not (equal line pending-line)))
(or (not (equal line pending-line))
(not (equal previous-buf occ-buff))))
(insert pending-lines-text))

(when (not (equal previous-buf occ-buff))
(insert (propertize (format "Occurrences in buffer %s:"
;(length lst)
occ-buff)
'font-lock-face
list-matching-lines-buffer-name-face
'read-only t
'occur-title occ-buff))
(insert "\n"))

(setq pending-line line)
(setq previous-buf occ-buff)
(setq pending-lines-text lines-text)))

;; Catch final pending text
Expand Down Expand Up @@ -1860,6 +1869,19 @@ Empty string defaults to jumping to all these."
(merlin-occurrences-list r)
(error "%s" r)))))

(defun merlin--project-occurrences ()
(merlin-call "occurrences" "-scope" "project" "-identifier-at"
(merlin-unmake-point (point))))

(defun merlin-project-occurrences ()
"List all occurrences of identifier under cursor in buffer."
(interactive)
(let ((r (merlin--project-occurrences)))
(when r
(if (listp r)
(merlin-occurrences-list r)
(error "%s" r)))))

;;;;;;;;;;;;;;;;;;;
;; OPEN REFACTOR ;;
;;;;;;;;;;;;;;;;;;;
Expand Down
2 changes: 1 addition & 1 deletion merlin.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build: [
]
depends: [
"ocaml" {>= "5.2" & < "5.3"}
"dune" {>= "2.9.0"}
"dune" {>= "3.0.0"}
"merlin-lib" {= version}
"dot-merlin-reader" {>= "5.0"}
"yojson" {>= "2.0.0"}
Expand Down
7 changes: 5 additions & 2 deletions src/analysis/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@
-open Merlin_utils
-open Merlin_specific
-open Merlin_extend
-open Merlin_kernel)
-open Merlin_kernel
-open Merlin_index_format)
(libraries
merlin_config
merlin_specific
merlin_extend
merlin_kernel
merlin_utils
merlin_index_format
ocaml_parsing
ocaml_preprocess
query_protocol
ocaml_typing
ocaml_utils
str))
str
unix))
23 changes: 0 additions & 23 deletions src/analysis/index_format.ml

This file was deleted.

Loading

0 comments on commit bd900fd

Please sign in to comment.