[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/company 38b84b29ee 1/4: fix sorting of dabbrev-code bac
From: |
ELPA Syncer |
Subject: |
[elpa] externals/company 38b84b29ee 1/4: fix sorting of dabbrev-code backend for flex style |
Date: |
Fri, 27 Dec 2024 12:57:37 -0500 (EST) |
branch: externals/company
commit 38b84b29eeb6e5d6bc994d3d52c0c4dde2d421bd
Author: Denis Zubarev <dvzubarev@yandex.ru>
Commit: Denis Zubarev <dvzubarev@yandex.ru>
fix sorting of dabbrev-code backend for flex style
Candidates were sorted in the `company--preprocess-candidates' in
alphabetical order, because `company-dabbrev-code` always returned nil
for `sorted` command.
Now `sorted` returns t if style has sorting function.
The second problem was sorting function that is set in
`completion--flex-adjust-metadata` never were used for sorting of
candidates.
I don't know how to properly fix this, so I just added invocation of
this function after candidates filtration.
---
company-dabbrev-code.el | 10 +++++++-
test/dabbrev-code-tests.el | 63 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/company-dabbrev-code.el b/company-dabbrev-code.el
index 4da6388ef6..a7b3be6fa3 100644
--- a/company-dabbrev-code.el
+++ b/company-dabbrev-code.el
@@ -80,6 +80,7 @@ parameter and returns a list of major modes to search. See
also
:package-version '(company . "1.0.0"))
(defvar-local company-dabbrev--boundaries nil)
+(defvar-local company-dabbrev-code--sorted nil)
(defun company-dabbrev-code--make-regexp (prefix)
(let ((prefix-re
@@ -118,6 +119,7 @@ comments or strings."
company-dabbrev--boundaries)))
(expand-common (company-dabbrev-code--expand-common arg (car rest)))
(kind 'text)
+ (sorted company-dabbrev-code--sorted)
(no-cache t)
(ignore-case company-dabbrev-code-ignore-case)
(match (when company-dabbrev-code-completion-styles
@@ -161,12 +163,18 @@ comments or strings."
(completion-styles (if (listp company-dabbrev-code-completion-styles)
company-dabbrev-code-completion-styles
completion-styles))
+ (metadata (completion-metadata prefix table nil))
res)
(if (not company-dabbrev-code-completion-styles)
(all-completions prefix table)
(setq res (company--capf-completions
prefix suffix
- table))
+ table nil
+ metadata))
+ (when-let ((sort-fn (completion-metadata-get metadata
'display-sort-function)))
+ (setq company-dabbrev-code--sorted t)
+ (setf (alist-get :completions res)
+ (funcall sort-fn (alist-get :completions res))))
(setq company-dabbrev--boundaries
(company--capf-boundaries-markers
(assoc-default :boundaries res)
diff --git a/test/dabbrev-code-tests.el b/test/dabbrev-code-tests.el
new file mode 100644
index 0000000000..f64e646ba5
--- /dev/null
+++ b/test/dabbrev-code-tests.el
@@ -0,0 +1,63 @@
+;;; dabbrev-code-tests.el --- company-mode tests -*- lexical-binding: t -*-
+
+;; Copyright (C) 2024 Free Software Foundation, Inc.
+
+;; Author: Denis Zubarev
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+(require 'company-tests)
+
+(ert-deftest company-dabbrev-code-with-flex-style-test ()
+ (with-temp-buffer
+ (insert "scheduled_job
+sa_enum
+self
+
+se")
+ (company-mode)
+ (let (company-frontends
+ company-transformers
+ (company-dabbrev-code-other-buffers nil)
+ (company-dabbrev-code-modes t)
+ (company-backends '(company-dabbrev-code))
+ (company-dabbrev-code-completion-styles '(flex)))
+ (ignore company-dabbrev-code-other-buffers
+ company-dabbrev-code-modes
+ company-dabbrev-code-completion-styles)
+
+ (company-manual-begin)
+ (should (equal '("self" "sa_enum" "scheduled_job")
company-candidates)))))
+
+(ert-deftest company-dabbrev-code-with-basic-style-test ()
+ (with-temp-buffer
+ (insert "scheduled_job
+sa_enum
+self
+
+se")
+ (company-mode)
+ (let (company-frontends
+ company-transformers
+ (company-dabbrev-code-other-buffers nil)
+ (company-dabbrev-code-modes t)
+ (company-backends '(company-dabbrev-code))
+ (company-dabbrev-code-completion-styles '(basic)))
+ (ignore company-dabbrev-code-other-buffers
+ company-dabbrev-code-modes
+ company-dabbrev-code-completion-styles)
+ (company-manual-begin)
+ (should (equal '("self") company-candidates)))))