114
114
:group 'psc-ide
115
115
:type 'boolean )
116
116
117
+ (defcustom psc-ide-add-qualification-on-completion " t"
118
+ " Whether to automatically prepend the qualifier for completions
119
+ that are imported qualified in the current module"
120
+ :group 'psc-ide
121
+ :type 'boolean )
122
+
117
123
(defcustom psc-ide-rebuild-on-save nil
118
124
" Whether to rebuild files on save and display errors/warnings
119
125
in a buffer"
@@ -196,7 +202,7 @@ in a buffer"
196
202
; ; Don't add an import when the option to do so is disabled
197
203
(not psc-ide-add-import-on-completion)
198
204
; ; or when a qualified identifier was completed
199
- (s-contains-p " ." (company-grab-symbol)))
205
+ (or ( get-text-property 0 :qualifier arg) ( s-contains-p " ." (company-grab-symbol) )))
200
206
(psc-ide-add-import-impl arg (vector
201
207
(psc-ide-filter-modules
202
208
(list (get-text-property 0 :module arg))))))))))
@@ -222,7 +228,8 @@ in a buffer"
222
228
(defun psc-ide-load-all ()
223
229
" Loads all the modules in the current project"
224
230
(interactive )
225
- (psc-ide-send psc-ide-command-load-all 'psc-ide-unwrap-result ))
231
+ (psc-ide-send psc-ide-command-load-all
232
+ (-compose 'message 'psc-ide-unwrap-result )))
226
233
227
234
(defun psc-ide-show-type (expand )
228
235
" Show type of the symbol under cursor."
@@ -349,7 +356,7 @@ use when the search used was with `string-match'."
349
356
(idx 3 )
350
357
result)
351
358
(push `(module . ,(match-string-no-properties 1 string)) result)
352
- (push `(alias . ,(match-string-no-properties 3 string)) result)
359
+ (push `(qualifier . ,(match-string-no-properties 3 string)) result)
353
360
result))
354
361
355
362
(defun psc-ide-parse-imports-in-buffer (&optional buffer )
@@ -481,10 +488,10 @@ The cases we have to cover:
481
488
3. fil| <- filter by prefix and imported modules"
482
489
(let* ((components (s-split " \\ ." search))
483
490
(prefix (car (last components)))
484
- (alias (s-join " ." (butlast components))))
485
- (if (not (s-blank? alias ))
491
+ (qualifier (s-join " ." (butlast components))))
492
+ (if (not (s-blank? qualifier ))
486
493
; ; 1. List.fil <- filter by prefix and List module
487
- (psc-ide-qualified-completion-command prefix alias )
494
+ (psc-ide-qualified-completion-command prefix qualifier )
488
495
(if manual
489
496
; ; 2. fil| + manual <- don't filter at all
490
497
(psc-ide-command-complete
@@ -498,9 +505,9 @@ The cases we have to cover:
498
505
nil
499
506
(psc-ide-get-module-name))))))
500
507
501
- (defun psc-ide-qualified-completion-command (prefix alias )
502
- " Builds a completion command for a PREFIX with ALIAS "
503
- (let ((modules (psc-ide-modules-for-alias alias )))
508
+ (defun psc-ide-qualified-completion-command (prefix qualifier )
509
+ " Builds a completion command for a PREFIX with QUALIFIERF "
510
+ (let ((modules (psc-ide-modules-for-qualifier qualifier )))
504
511
(psc-ide-command-complete
505
512
(vector (psc-ide-filter-prefix prefix)
506
513
(psc-ide-filter-modules (vconcat modules)))
@@ -512,34 +519,50 @@ The cases we have to cover:
512
519
(-map (lambda (import ) (cdr (assoc 'module import)))
513
520
(psc-ide-parse-imports-in-buffer)))
514
521
515
- (defun psc-ide-modules-for-alias ( alias )
522
+ (defun psc-ide-modules-for-qualifier ( qualifier )
516
523
" Searches the current module's imports for modules that are
517
- qualified as ALIAS "
524
+ qualified as QUALIFIER "
518
525
(let ((imports (psc-ide-parse-imports-in-buffer)))
519
526
(-keep (lambda (import )
520
- (when (equal alias (cdr (assoc 'alias import)))
527
+ (when (equal qualifier (cdr (assoc 'qualifier import)))
521
528
(cdr (assoc 'module import)))) imports)))
522
529
530
+ (defun psc-ide-qualifier-for-module (module &optional parsed-imports )
531
+ " Searches the current module's imports for MODULE and returns
532
+ its qualifier. Returns nil if the module is not imported qualified"
533
+ (let ((imports (or parsed-imports (psc-ide-parse-imports-in-buffer))))
534
+ (-first-item
535
+ (-keep (lambda (import )
536
+ (when (equal module (cdr (assoc 'module import)))
537
+ (cdr (assoc 'qualifier import)))) imports))))
538
+
523
539
(defun psc-ide-handle-completionresponse (callback response )
524
540
" Accepts a callback and a completion response from psc-ide,
525
541
processes the response into a format suitable for company and
526
542
passes it into the callback"
527
543
(let* ((result (psc-ide-unwrap-result response))
528
- (completions (-map 'psc-ide-annotate-completion result)))
544
+ (completions (-map (-partial 'psc-ide-annotate-completion (psc-ide-parse-imports-in-buffer)) result)))
529
545
(funcall callback completions)))
530
546
531
- (defun psc-ide-annotate-completion (completion )
547
+ (defun psc-ide-annotate-completion (parsed-imports completion )
532
548
" Turns a completion from psc-ide into a string with
533
549
text-properties, which carry additional information"
534
- (let ((identifier (cdr (assoc 'identifier completion)))
535
- (type (cdr (assoc 'type completion)))
536
- (module (cdr (assoc 'module completion))))
537
- ; ; :qualifier qualifier <- TODO: Add this back in
538
- (add-text-properties 0 1 (list :type type
539
- :module module) identifier)
540
- ; ; add-text-properties is sideeffecting and doesn't return the modified
541
- ; ; string, so we need to explicitly return the identifier from here
542
- identifier))
550
+ (let-alist completion
551
+ (let* ((qualifier (psc-ide-qualifier-for-module .module parsed-imports))
552
+ (identifier (if (and psc-ide-add-qualification-on-completion
553
+ qualifier
554
+ ; ; Don't add a qualifier if we're already
555
+ ; ; completing a qualified prefix
556
+ (not (s-contains-p " ." (company-grab-symbol))))
557
+ (format " %s .%s " qualifier .identifier)
558
+ .identifier)))
559
+
560
+ (add-text-properties 0 1 (list :type .type
561
+ :module .module
562
+ :qualifier qualifier) identifier)
563
+ ; ; add-text-properties is sideeffecting and doesn't return the modified
564
+ ; ; string, so we need to explicitly return the identifier from here
565
+ identifier)))
543
566
544
567
(defun psc-ide-goto-definition-impl (search )
545
568
" Asks for the definition location of SEARCH and jumps to it."
@@ -586,18 +609,18 @@ on whether WARN is true."
586
609
" Builds a type command from SEARCH."
587
610
(let* ((components (s-split " \\ ." search))
588
611
(ident (car (last components)))
589
- (alias (s-join " ." (butlast components))))
590
- (if (not (s-blank? alias ))
591
- (psc-ide-qualified-type-command ident alias )
612
+ (qualifier (s-join " ." (butlast components))))
613
+ (if (not (s-blank? qualifier ))
614
+ (psc-ide-qualified-type-command ident qualifier )
592
615
(psc-ide-command-show-type
593
616
(vector (psc-ide-filter-modules
594
617
(psc-ide-all-imported-modules)))
595
618
ident
596
619
(psc-ide-get-module-name)))))
597
620
598
- (defun psc-ide-qualified-type-command (ident alias )
599
- " Builds a type command for an IDENT with ALIAS "
600
- (let ((modules (psc-ide-modules-for-alias alias )))
621
+ (defun psc-ide-qualified-type-command (ident qualifier )
622
+ " Builds a type command for an IDENT with QUALIFIER "
623
+ (let ((modules (psc-ide-modules-for-qualifier qualifier )))
601
624
(psc-ide-command-show-type
602
625
(vector (psc-ide-filter-modules (vconcat modules)))
603
626
ident
0 commit comments