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

lsp-mode with flycheck doesn't work. #9

Open
jcs090218 opened this issue May 19, 2020 · 8 comments · Fixed by #10 · May be fixed by #11
Open

lsp-mode with flycheck doesn't work. #9

jcs090218 opened this issue May 19, 2020 · 8 comments · Fixed by #10 · May be fixed by #11
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jcs090218
Copy link
Member

  • flycheck via lsp-mode doesn't appear to detect the changes to the closing tag, so it shows an error even when there isn't one (this is possibly a bug in flycheck or lsp-mode...)

Refer to #3 (comment)

@aaronjensen
Copy link
Contributor

Thanks, I added a repro and reported upstream: emacs-lsp/lsp-mode#1704

@aaronjensen
Copy link
Contributor

@jcs090218 looks like they closed it, see: emacs-lsp/lsp-mode#1704 (comment)

I just played around with firing what's in the after-change in a timer, which works, but it makes more sense to do it as a post-command hook, I think.

@aaronjensen
Copy link
Contributor

aaronjensen commented May 19, 2020

Here's what I got working, I had to disable the before change hook while the timer is running:

(defvar auto-rename-tag--after-change-active nil)

(defun auto-rename-tag--before-change-functions (_begin _end)
  "Do stuff before buffer is changed.
BEGIN : beginning of the changes.
END : end of the changes."
  (unless auto-rename-tag--after-change-active

    ;; Reset record.
    (setq auto-rename-tag--record-prev-word "")
    ;; Reset flag.
    (setq auto-rename-tag--pre-command-actived nil)

    (when (and (not undo-in-progress)
               (auto-rename-tag--inside-tag-p)
               (not (auto-rename-tag--self-tag-p)))
      (save-excursion
        ;; Set active flag.
        (setq auto-rename-tag--pre-command-actived t)

        (setq auto-rename-tag--record-prev-word (auto-rename-tag--get-tag-name-at-point))

        (when (string= auto-rename-tag--record-prev-word "/")
          (setq auto-rename-tag--record-prev-word ""))

        ;; Ensure `auto-rename-tag--record-prev-word' is something other than nil.
        (unless auto-rename-tag--record-prev-word
          (setq auto-rename-tag--record-prev-word ""))))))

(defun auto-rename-tag--after-change-function (_begin _end _length)
  "Do stuff after buffer is changed.
BEGIN : beginning of the changes.
END : end of the changes.
LENGTH : deletion length."
  (when auto-rename-tag--pre-command-actived
    (run-at-time 0 nil (lambda () 
                         (save-excursion
                           (let ((is-end-tag nil)
                                 (current-word "") (pair-tag-word "")
                                 (auto-rename-tag--after-change-active nil))
                             ;; Goto the first character inside the tag.
                             (auto-rename-tag--goto-the-start-of-tag-name)

                             (setq is-end-tag (auto-rename-tag--is-closing-tag-p))

                             (setq current-word (auto-rename-tag--get-tag-name-at-point))

                             (unless (string= current-word auto-rename-tag--record-prev-word)
                               ;; NOTE: Is closing tag.
                               (when is-end-tag
                                 (auto-rename-tag--resolve-nested 'backward)

                                 ;; Get the tag name and ready to be compare.
                                 (setq pair-tag-word (auto-rename-tag--get-tag-name-at-point))

                                 ;; Ensure `pair-tag-word' is something other than nil.
                                 (unless pair-tag-word (setq pair-tag-word ""))

                                 (when (string= auto-rename-tag--record-prev-word pair-tag-word)
                                   ;; Delete the pair word.
                                   (unless (string= pair-tag-word "")
                                     (auto-rename-tag--delete-tag-name))
                                   ;; Insert new word.
                                   (insert current-word)))

                               ;; NOTE: Is opening tag.
                               (unless is-end-tag
                                 (auto-rename-tag--resolve-nested 'forward)

                                 (setq is-end-tag (auto-rename-tag--is-closing-tag-p))

                                 ;; Get the tag name and ready to be compare.
                                 (setq pair-tag-word (auto-rename-tag--get-tag-name-at-point))

                                 ;; Ensure `pair-tag-word' is something other than nil.
                                 (unless pair-tag-word (setq pair-tag-word ""))

                                 (when (string= auto-rename-tag--record-prev-word pair-tag-word)
                                   ;; Delete the pair word.
                                   (unless (string= pair-tag-word "")
                                     (auto-rename-tag--delete-tag-name))
                                   ;; Insert new word.
                                   (insert current-word))))))))))

@jcs090218
Copy link
Member Author

jcs090218 commented May 20, 2020

Interesting, not sure if there is more elegant way to solve this. Would you mind to make a PR? Cuz I can't really tell what changes and what doesn't. 😕

In my understanding, we have a auto-rename-tag--after-change-active flag to check weather to active the timer you put in after hook? Would that causes any side effect? Thanks! :)

aaronjensen added a commit to aaronjensen/auto-rename-tag that referenced this issue May 20, 2020
@jcs090218
Copy link
Member Author

Refer to #10.

@jcs090218
Copy link
Member Author

Okay, so post-command-hook doesn't gives me the same result hence I have this patch here 4fd9de4. I just have function runs twice, the performance might went down but this is the best solution for now. 😕 See if this works for you! (Running twice might still cause the LSP display error)

@jcs090218 jcs090218 reopened this May 20, 2020
@aaronjensen
Copy link
Contributor

Yeah, unfortunately this has the same problem.

What was the issue you had with post-command-hook alone?

@jcs090218
Copy link
Member Author

jcs090218 commented May 20, 2020

What was the issue you had with post-command-hook alone?

I think the tag wasn't update properly. If I tried delete the whole word, then it seems to be not working. But it will work when I modified by adding/deleting the character one by one. I haven't figure out the solution yet. 😕

@jcs090218 jcs090218 added bug Something isn't working enhancement New feature or request help wanted Extra attention is needed and removed question Further information is requested bug Something isn't working labels May 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
2 participants