lsp-bridge -- 速度最快的语法补全插件

那能增加 orderless 的 completion-styles么,orderless 支持regexp,literal,initialism,prefixes,flex 五种匹配方法,看acm代码只实现了 literal

比如 ad1d 能匹配到 AdaptiveAvgPool1d

你能看懂日文? 群里真是卧虎藏龙啊。

平时会用到韩文, :grinning_face_with_smiling_eyes:所以比较喜欢用 emacs + 补全功能,来提高输入的准确率。而且很多词时间久了不用会忘记,就自己制作了中韩、韩中补全backend,现在结合 acm 框架,使用体验更好啦! :blush:

丢人了,我瞟了一眼,以为是日文呢 :joy:

3 个赞

哈哈, :handshake:我对法文、德文傻傻分不清!

有能力就发补丁吧,现在的功能我已经很满足了。

可以糊着先用。 比如下面这个就支持了 flex 匹配方式。上面的 ad1d 应该没问题了。 顺便说, acm 现在实现的应该是 regexp 方式。

(defun acm-match-orderless-flex (keyword candidate)
  (string-match-p (orderless-flex (downcase keyword)) (downcase candidate)))
 
(advice-add #'acm-candidate-fuzzy-search :override #'acm-match-orderless-flex)

里面 orderless-flex 这个随便换,比如 orderless-initialism 等。 不过我看了, elisp 里面是没有这个 fuzzy-search 的,所以这个 advice 对 elisp 无用。

1 个赞

nice 确实可以用,暂时 lsp 就够啦

又研究了下,发现可以通过 orderless-matching-styles 指定多种匹配方式,orderless-pattern-compiler 生成正则

  (setq orderless-matching-styles '(orderless-flex))

  (defun acm-match-orderless (keyword candidate)
    (string-match-p (car (orderless-pattern-compiler (downcase keyword) orderless-matching-styles)) (downcase candidate)))

  (advice-add #'acm-candidate-fuzzy-search :override #'acm-match-orderless)

这个弹窗怎么修改样式呢? 边框有点粗,里面的符号怎么是也是黑色。

报任何bug之前先 emacs -Q 排除一下自己的配置问题。

这个补丁修复了。

如果关键字是 ‘’ 空字符串,而恰巧遇到 typescript 这时候返回3000个候选词,对这些候选词做正则搜索和排序都会产生大量的 heap 数据,太多以后就会触发 Emacs 做GC操作, Emacs这个单线程怪物,它GC的时候就啥都干不了。

解决方案就是,当关键字是空字符串 (比如 . 后面, 或者 = 后面),只显示前100个候选词,并且停止前缀排序,这样既不会触发Emacs的GC操作,又保证进一步输入前缀后可以搜索到匹配的候选词。

1 个赞

orderless 的搜索已经实现了,感谢 @smallzhan 的补丁 add simple orderless support by smallzhan · Pull Request #195 · manateelazycat/lsp-bridge · GitHub

5 个赞

可以分享下你在windows上的使用环境/配置吗?

(when (or (eq system-type 'berkeley-unix) (eq system-type 'gnu/linux))
  (defvar lsp-bridge-path "/home/blove/myLinux/myApp/lsp-bridge")
  )
(when (eq system-type 'windows-nt)
	  (defvar lsp-bridge-path "D:/App/lsp-bridge")
  )

(when (file-exists-p lsp-bridge-path)
  ;; --- posframe
  (add-to-list 'load-path (concat user-emacs-directory "lisp/blove-extra/lsp-unites/posframe"))

  ;; --- markdown-mode
  (add-to-list 'load-path (concat user-emacs-directory "lisp/blove-extra/lsp-unites/markdown-mode"))

  ;; --- yasnippet
  (add-to-list 'load-path (concat user-emacs-directory "lisp/blove-extra/lsp-unites/yasnippet"))
  (require 'yasnippet)
  (yas-global-mode 1)
  (setq yas-snippet-dirs '("~/.emacs.d/snippets/blove-snippets" "~/.emacs.d/snippets/yas-snippets"))

  ;; --- lsp-bridge
  (add-to-list 'load-path lsp-bridge-path)
  (require 'lsp-bridge)
  (global-lsp-bridge-mode)

  ;; :: acm settings
  ;; (setq acm-enable-icon t) ;; show svg icons : default t
  (setq acm-enable-doc nil) ;; show doc helper : default t
  (defun lsp-bridge/doc-toggle ()
	(interactive)
	(if acm-enable-doc
		(setq acm-enable-doc nil)
	  (setq acm-enable-doc t)
	  )
	)
  (defun acm-remap ()
	(define-key evil-insert-state-map (kbd "TAB") nil)
	(define-key acm-mode-map (kbd "<tab>") 'acm-select-next)
	(define-key acm-mode-map (kbd "<s-tab>") 'acm-select-prev)
	(define-key acm-mode-map (kbd "<backtab>") 'acm-select-prev)
	)
  (progn
	(if (not (string-equal (buffer-name) "*BloveDashboard*"))
		(if (not (string-equal (buffer-name) "*scratch*"))
			(if (not (string-equal (file-name-extension buffer-file-name) "org"))
				(acm-remap)
			  )
		  (acm-remap)
		  )
	  (acm-remap)
	  )
	)

  ;; --- language-helper for korean-helper / us-english-helper
  (add-to-list 'load-path (concat user-emacs-directory "lisp/blove-extra/blove-lang-helper"))
  (require 'blove-lang-helper)
  )

;;; ========== at-the-bottom
(provide 'init-lsp-bridge)

1 个赞
;;; --- Encoding
;;;
(prefer-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)
(set-language-environment 'utf-8)
(set-default-coding-systems 'utf-8)
(set-buffer-file-coding-system 'utf-8)
(set-clipboard-coding-system 'utf-8)
(set-file-name-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
;;;
;;; --- Gui
;;;
;;; ~ system fonts ~
(setq-default uifont "FiraCode Nerd Font")
;;; ~ fix qindos font view for windows only ~
(when (eq system-type 'windows-nt)
  (set-next-selection-coding-system 'utf-16-le)
  (set-selection-coding-system 'utf-16-le)
  (set-clipboard-coding-system 'utf-16-le))
;;; ~ better scrolling bar action ~
(setq scroll-conservatively 101
	  scroll-step 2
	  scroll-margin 2
	  hscroll-step 2
	  hscroll-margin 2
	  scroll-up-aggressively 0.01
	  scroll-down-aggressively 0.01
	  scroll-preserve-screen-position 'always
      )
;;;

继续深入扩展~添加了 中韩、韩中、中-US_ENG、US_ENG-中 的 backend。希望达到的功能都实现了!应对中文、其它语种文字,lsp-bridge 依然速度飞快! :+1:
以下是具体配置,请大佬、大家 ~ 帮忙修正优化!

;;;
;;; blove-lang-helper.el
;;;
(defalias 'lsp-bridge-toggle-korean-helper #'acm-toggle-korean-helper)
(defalias 'lsp-bridge-toggle-us-eng-helper #'acm-toggle-us-eng-helper)

(defvar-local acm-enable-korean-helper nil)
(defvar-local acm-enable-us-eng-helper nil)

(defcustom acm-backend-korean-min-length 1
  "Minimum length of korean word."
  :type 'integer)
(defcustom acm-backend-us-eng-min-length 1
  "Minimum length of us english word."
  :type 'integer)

;; (setq acm-icon-alist (append acm-icon-alist '(("korean" "material" "korean" "#ed6856"))))
(defun acm-backend-language-candidates (min-length keyword dict)
  (let* ((candidates (list)))
    (when (>= (length keyword) min-length)
      (dolist (candidate dict)
        (when (string-prefix-p (downcase keyword) candidate)
          (add-to-list 'candidates (list :key candidate
                                         :icon "translate"
                                         :label candidate
                                         :display-label candidate
                                         :annotation (get-text-property 0 :initials candidate)
                                         :backend "blove-lang")
                       t))))

    candidates))

(defun acm-toggle-korean-helper ()
  "Toggle korean helper."
  (interactive)
  (setq-local acm-enable-us-eng-helper nil)
  (if acm-enable-korean-helper
      (message "Turn off korean helper.")
    (message "Turn on korean helper."))
  (setq-local acm-enable-korean-helper (not acm-enable-korean-helper))
  )
(defun acm-toggle-us-eng-helper ()
  "Toggle us english helper."
  (interactive)
  (setq-local acm-enable-korean-helper nil)
  (if acm-enable-us-eng-helper
      (message "Turn off us english helper.")
    (message "Turn on us english helper."))
  (setq-local acm-enable-us-eng-helper (not acm-enable-us-eng-helper))
  )

(add-to-list 'load-path (concat user-emacs-directory "lisp/blove-extra/blove-lang-helper/blove-lang-zh"))
(add-to-list 'load-path (concat user-emacs-directory "lisp/blove-extra/blove-lang-helper/blove-zh-lang"))
(defun acm-update-candidates-advice ()
  (let* ((keyword (acm-get-input-prefix))
         (char-before-keyword (save-excursion
                                (backward-char (length keyword))
                                (acm-char-before)))
         (candidates (list))
         path-candidates
         yas-candidates
         tempel-candidates
         mode-candidates)

	;; --- add language-helper for korean-helper / us-eng-helper --- begin
	(if (or acm-enable-korean-helper acm-enable-us-eng-helper)
		(progn
		  (setq-local fin-dict '())
		  (if acm-enable-korean-helper
			  (progn
				(require 'blove-backends-kor-zh-15000)
				(require 'blove-backends-zh-kor-15000)
				(setq fin-dict (append fin-dict blove-kor-zh-15000))
				(setq fin-dict (append fin-dict blove-zh-kor-15000))
				(setq candidates (acm-backend-language-candidates acm-backend-korean-min-length keyword fin-dict))
				)
			(progn
			  (if acm-enable-us-eng-helper
				  (progn
					(require 'blove-backends-us-zh-15000)
					(require 'blove-backends-zh-us-15000)
					(setq fin-dict (append fin-dict blove-us-zh-15000))
					(setq fin-dict (append fin-dict blove-zh-us-15000))
					(setq candidates (acm-backend-language-candidates acm-backend-us-eng-min-length keyword fin-dict))
					)
				)
			  )
			)
		  )
	  ;; --- add language-helper for korean-helper / us-eng-helper --- end
	  (progn
		;; from acm.el :: acm-update-candidates --- begin
		(if acm-enable-english-helper
			;; Completion english if option `acm-enable-english-helper' is enable.
			(progn
			  (require 'acm-backend-english-data)
			  (require 'acm-backend-english)

			  (setq candidates (acm-backend-english-candidates keyword)))

		  (setq path-candidates (acm-backend-path-candidates keyword))
		  (if (> (length path-candidates) 0)
			  ;; Only show path candidates if prefix is valid path.
			  (setq candidates path-candidates)

			;; Fetch syntax completion candidates.
			(setq mode-candidates (append
								   (acm-backend-elisp-candidates keyword)
								   (acm-backend-lsp-candidates keyword)))

			;; Don't search snippet if char before keyword is not in `acm-backend-lsp-completion-trigger-characters'.
			(unless (member char-before-keyword acm-backend-lsp-completion-trigger-characters)
			  (setq yas-candidates (acm-backend-yas-candidates keyword))
			  (setq tempel-candidates (acm-backend-tempel-candidates keyword)))

			;; Insert snippet candidates in first page of menu.
			(setq candidates
				  (if (> (length mode-candidates) acm-snippet-insert-index)
					  (append (cl-subseq mode-candidates 0 acm-snippet-insert-index)
							  yas-candidates
							  tempel-candidates
							  (cl-subseq mode-candidates acm-snippet-insert-index))
					(append mode-candidates yas-candidates tempel-candidates)
					))))
		;; from acm.el :: acm-update-candidates --- end
		)
	  )
    candidates))

(advice-add 'acm-update-candidates :override #'acm-update-candidates-advice)

;;; ========== at-the-bottom
(provide 'blove-lang-helper)

4 个赞

今天想尝试一下 lsp-bridge,有个比较初级的问题想请教下哈

第一个是,这个补全菜单怎么出来的呢? 我尝试了一下,在一个 java 文件里面随便输入一些变量,然后点 . 发现并没有出来补全菜单

多谢 :slight_smile:

这是我的设置

(require 'yasnippet)
(require 'lsp-bridge)
;; provide Java third-party library jump and -data directory support, optional
(require 'lsp-bridge-jdtls)

(yas-global-mode 1)
(global-lsp-bridge-mode)


搞定了,之前 jdtls 命令没有在 PATH 里面


确实速度和颜值均在线👍

编辑ts时,使用lsp-bridge-rename会出现多余的提示内容。

但是功能是正常的

修复了 Don't send textDocument/prepareRename request if LSP server haven't t… · manateelazycat/lsp-bridge@c3dea2a · GitHub

1 个赞