Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Replace github-tags with ghub #33

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions Eask
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ clean:

activate:
$(EASK) install --dev
$(EASK) load ./test/activate.el
$(EASK) load ./test/activate.el --allow-error
48 changes: 27 additions & 21 deletions lsp-ltex.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Author: Shen, Jen-Chieh <[email protected]>
;; 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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" )
;;
Expand Down Expand Up @@ -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."
Expand Down
6 changes: 6 additions & 0 deletions test/activate.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down