diff --git a/Eask b/Eask index 71eeb2b..03e5dbe 100644 --- a/Eask +++ b/Eask @@ -16,6 +16,7 @@ (depends-on "emacs" "26.1") (depends-on "lsp-mode") (depends-on "github-tags") +(depends-on "ghub") (development (depends-on "markdown-mode")) diff --git a/Makefile b/Makefile index 46cf6ad..8eeef4c 100644 --- a/Makefile +++ b/Makefile @@ -34,4 +34,4 @@ clean: activate: $(EASK) install --dev - $(EASK) load ./test/activate.el + $(EASK) load ./test/activate.el --allow-error diff --git a/lsp-ltex.el b/lsp-ltex.el index a7864f9..66c0111 100644 --- a/lsp-ltex.el +++ b/lsp-ltex.el @@ -6,7 +6,7 @@ ;; Author: Shen, Jen-Chieh ;; URL: https://github.com/emacs-languagetool/lsp-ltex ;; Version: 0.2.1 -;; Package-Requires: ((emacs "27.1") (lsp-mode "6.1")) +;; Package-Requires: ((emacs "27.1") (lsp-mode "6.1") (ghub "2.0.0")) ;; Keywords: convenience lsp languagetool checker ;; This file is NOT part of GNU Emacs. @@ -33,9 +33,9 @@ (require 'custom) (require 'subr-x) -(require 'lsp-mode) -(require 'github-tags nil t) +(require 'lsp-mode) +(require 'ghub) (defgroup lsp-ltex nil "Settings for the LTEX Language Server. @@ -219,7 +219,7 @@ This must be a positive integer." :type 'integer :group 'lsp-ltex) -(defcustom lsp-ltex-completion-enabled nil ;; TODO: Add proper implementation +(defcustom lsp-ltex-completion-enabled nil ; TODO: Add proper implementation "If this this is enabled, auto-completion list for the current word is sent. The editor need to send a completion request." :type 'boolean @@ -257,12 +257,6 @@ The editor need to send a completion request." (const "verbose")) :group 'lsp-ltex) -;; -;; (@* "Externals" ) -;; - -(declare-function github-tags "ext:github-tags.el") - ;; ;; (@* "Util" ) ;; @@ -384,19 +378,31 @@ This is use to active language server and check if language server's existence." (lsp-ltex--s-replace "ltex-ls-" "" fn)) (ignore-errors (gethash "ltex-ls" (json-parse-string (shell-command-to-string "ltex-ls -V")))))) +(defun lsp-ltex--get-tags () + "Return a list of tags." + (when-let + ((response + (ghub-request "GET" (concat "/repos/" lsp-ltex-repo-path "/tags") + nil + :forge 'github + :host "api.github.com" + :auth 'basic + :noerror t))) + (let (names) + (dolist (data response) + (push (cdr (assoc 'name data)) names)) + (reverse names)))) + (defun lsp-ltex--latest-version () "Return the latest version from remote repository." - (when (featurep 'github-tags) - (when-let ((response (ignore-errors (github-tags lsp-ltex-repo-path)))) - (let ((names (plist-get (cdr response) :names)) - (index 0) version ver) - ;; Loop through tag name and fine the stable version - (while (and (not version) (< index (length names))) - (setq ver (nth index names) - index (1+ index)) - (when (string-match-p "^[0-9.]+$" ver) ; stable version are only with numbers and dot - (setq version ver))) - version)))) + (let ((tags (lsp-ltex--get-tags)) (index 0) version ver) + ;; Loop through tag name and fine the stable version + (while (and (not version) (< index (length tags))) + (setq ver (nth index tags) + index (1+ index)) + (when (string-match-p "^[0-9.]+$" ver) ; stable version are only with numbers and dot + (setq version ver))) + version)) (defun lsp-ltex--lsp-dependency () "Register LSP dependency once." diff --git a/test/activate.el b/test/activate.el index a7f5fd3..4354be7 100644 --- a/test/activate.el +++ b/test/activate.el @@ -29,6 +29,12 @@ (require 'lsp-mode) +(message ":1") + +(require 'lsp-ltex) + +(message ":2 %s" lsp-ltex-version) + (lsp-install-server t 'ltex-ls) ; Start installation (defconst timeout 180