From 4b98ebe844630cc4293662839f0215257ba5cb58 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Fri, 16 Dec 2022 00:22:33 +0800 Subject: [PATCH 01/11] fix: Replace github-tags with ghub --- lsp-ltex.el | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/lsp-ltex.el b/lsp-ltex.el index 15d1a5f..217c7e9 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. @@ -255,14 +255,6 @@ The editor need to send a completion request.") (const "verbose")) :group 'lsp-ltex) -;; -;; (@* "Externals" ) -;; - -(defvar github-tags-names) - -(declare-function github-tags "ext:github-tags.el") - ;; ;; (@* "Util" ) ;; @@ -384,17 +376,28 @@ 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." + (let ((response (ghub-request "GET" (concat "/repos/" lsp-ltex-repo-path "/tags") + nil + :forge 'github + :host "api.github.com" + :auth 'basic)) + 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 (and (featurep 'github-tags) (ignore-errors (github-tags lsp-ltex-repo-path))) - (let ((index 0) version ver) - ;; Loop through tag name and fine the stable version - (while (and (not version) (< index (length github-tags-names))) - (setq ver (nth index github-tags-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." From 6ffe1fb41c0d8c428610ce432f8e30331bdffa6f Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Fri, 16 Dec 2022 00:24:21 +0800 Subject: [PATCH 02/11] fix compile warning --- lsp-ltex.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lsp-ltex.el b/lsp-ltex.el index 217c7e9..0d5168f 100644 --- a/lsp-ltex.el +++ b/lsp-ltex.el @@ -219,9 +219,11 @@ 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.") +The editor need to send a completion request." + :type 'boolean + :group 'lsp-ltex) (defcustom lsp-ltex-diagnostic-severity "information" "Severity of the diagnostics corresponding to the grammar and spelling errors." From eedcd547100def5e658955d8297352db7083dbe2 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Fri, 16 Dec 2022 00:28:07 +0800 Subject: [PATCH 03/11] Add ghub as dep --- Eask | 1 + 1 file changed, 1 insertion(+) 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")) From 94cf91c58defa20f8165afc98c04af1aa1a7e296 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Fri, 16 Dec 2022 00:36:35 +0800 Subject: [PATCH 04/11] allow error --- lsp-ltex.el | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lsp-ltex.el b/lsp-ltex.el index 0d5168f..a4a953e 100644 --- a/lsp-ltex.el +++ b/lsp-ltex.el @@ -380,15 +380,16 @@ This is use to active language server and check if language server's existence." (defun lsp-ltex--get-tags () "Return a list of tags." - (let ((response (ghub-request "GET" (concat "/repos/" lsp-ltex-repo-path "/tags") - nil - :forge 'github - :host "api.github.com" - :auth 'basic)) - names) - (dolist (data response) - (push (cdr (assoc 'name data)) names)) - (reverse names))) + (when-let ((response (ignore-errors + (ghub-request "GET" (concat "/repos/" lsp-ltex-repo-path "/tags") + nil + :forge 'github + :host "api.github.com" + :auth 'basic)))) + (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." From 17aa1283173ee878d208c1e6bc498b2d7ccb5ff0 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Fri, 16 Dec 2022 00:39:18 +0800 Subject: [PATCH 05/11] debug msg --- test/activate.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/activate.el b/test/activate.el index a7f5fd3..47ea818 100644 --- a/test/activate.el +++ b/test/activate.el @@ -29,8 +29,12 @@ (require 'lsp-mode) +(message "1:") + (lsp-install-server t 'ltex-ls) ; Start installation +(message "2:") + (defconst timeout 180 "Timeout in seconds.") From 6caf5c907812b27192f5ebf03bda6a8030a161ef Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Fri, 16 Dec 2022 00:43:33 +0800 Subject: [PATCH 06/11] Try remove latest version --- lsp-ltex.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lsp-ltex.el b/lsp-ltex.el index a4a953e..04fa5b7 100644 --- a/lsp-ltex.el +++ b/lsp-ltex.el @@ -411,7 +411,7 @@ This is use to active language server and check if language server's existence." :store-path ,(lsp-ltex--downloaded-extension-path)))) (defcustom lsp-ltex-version (or (lsp-ltex--current-version) - (lsp-ltex--latest-version) + ;;(lsp-ltex--latest-version) "14.0.0") ; fall back to preset version "Version of LTEX language server." :type 'string From b9e5b7e2e19dcbf96b83a64eef7de6a41cf4f623 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Fri, 16 Dec 2022 00:45:31 +0800 Subject: [PATCH 07/11] Add debug message --- lsp-ltex.el | 4 +++- test/activate.el | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lsp-ltex.el b/lsp-ltex.el index 04fa5b7..4559c4b 100644 --- a/lsp-ltex.el +++ b/lsp-ltex.el @@ -393,8 +393,10 @@ This is use to active language server and check if language server's existence." (defun lsp-ltex--latest-version () "Return the latest version from remote repository." + (message "1") (let ((tags (lsp-ltex--get-tags)) (index 0) version ver) ;; Loop through tag name and fine the stable version + (message "2") (while (and (not version) (< index (length tags))) (setq ver (nth index tags) index (1+ index)) @@ -411,7 +413,7 @@ This is use to active language server and check if language server's existence." :store-path ,(lsp-ltex--downloaded-extension-path)))) (defcustom lsp-ltex-version (or (lsp-ltex--current-version) - ;;(lsp-ltex--latest-version) + (lsp-ltex--latest-version) "14.0.0") ; fall back to preset version "Version of LTEX language server." :type 'string diff --git a/test/activate.el b/test/activate.el index 47ea818..a7f5fd3 100644 --- a/test/activate.el +++ b/test/activate.el @@ -29,12 +29,8 @@ (require 'lsp-mode) -(message "1:") - (lsp-install-server t 'ltex-ls) ; Start installation -(message "2:") - (defconst timeout 180 "Timeout in seconds.") From e78002d686db2741db49c49e67d34e54ba0e7ada Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Fri, 16 Dec 2022 00:48:04 +0800 Subject: [PATCH 08/11] wrap error log --- lsp-ltex.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lsp-ltex.el b/lsp-ltex.el index 4559c4b..e297644 100644 --- a/lsp-ltex.el +++ b/lsp-ltex.el @@ -394,9 +394,9 @@ This is use to active language server and check if language server's existence." (defun lsp-ltex--latest-version () "Return the latest version from remote repository." (message "1") - (let ((tags (lsp-ltex--get-tags)) (index 0) version ver) - ;; Loop through tag name and fine the stable version + (let ((tags (ignore-errors (lsp-ltex--get-tags))) (index 0) version ver) (message "2") + ;; Loop through tag name and fine the stable version (while (and (not version) (< index (length tags))) (setq ver (nth index tags) index (1+ index)) From 1ca392cd7b0dac0354eba6de24eb4472824c3a30 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Fri, 16 Dec 2022 00:51:53 +0800 Subject: [PATCH 09/11] test --- lsp-ltex.el | 4 +--- test/activate.el | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lsp-ltex.el b/lsp-ltex.el index e297644..a4a953e 100644 --- a/lsp-ltex.el +++ b/lsp-ltex.el @@ -393,9 +393,7 @@ This is use to active language server and check if language server's existence." (defun lsp-ltex--latest-version () "Return the latest version from remote repository." - (message "1") - (let ((tags (ignore-errors (lsp-ltex--get-tags))) (index 0) version ver) - (message "2") + (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) 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 From 47bd4331dc1a3d95323a0033fd555bab3d8d55a0 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Fri, 16 Dec 2022 00:56:02 +0800 Subject: [PATCH 10/11] Try using no error --- lsp-ltex.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lsp-ltex.el b/lsp-ltex.el index a4a953e..66c0111 100644 --- a/lsp-ltex.el +++ b/lsp-ltex.el @@ -380,12 +380,14 @@ This is use to active language server and check if language server's existence." (defun lsp-ltex--get-tags () "Return a list of tags." - (when-let ((response (ignore-errors - (ghub-request "GET" (concat "/repos/" lsp-ltex-repo-path "/tags") - nil - :forge 'github - :host "api.github.com" - :auth 'basic)))) + (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)) From 240d961862724abba784d6c2bfe6cf904f948a79 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Fri, 16 Dec 2022 00:58:48 +0800 Subject: [PATCH 11/11] Allow error for test --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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