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

rjsx-electric-lt and rjsx-delete-creates-full-tag misbehaves #68

Open
shackra opened this issue Apr 18, 2018 · 21 comments
Open

rjsx-electric-lt and rjsx-delete-creates-full-tag misbehaves #68

shackra opened this issue Apr 18, 2018 · 21 comments
Labels

Comments

@shackra
Copy link

shackra commented Apr 18, 2018

Sometimes I will push the < key on my keyboard and the tag woun't auto-complete per rjsx-electric-lt behavior as I expect, instead the error missing ‘>’ after ‘/’ in self-closing tag will be registered on *Messages*.

Also, if the tag is automatically close by rjsx-electric-lt, and then I press C-d (rjsx-delete-creates-full-tag) the / gets deleted but I see no closing tags, I need to insert the / again and the delete it with C-d in order to get the function working as expected.

You can see this misbehavior from both functions in action on the following video:

https://streamable.com/6izlx

This is my full JavaScript, ReactJS and JSX configuration:

(setq-default js-indent-level 2)

(use-package ng2-mode)

;; TODO: Eliminar cuando el soporte para lsp-mode sea activado
(use-package tide
  :init
  (defun setup-tide-mode ()
    (interactive)
    (tide-setup)
    (tide-hl-identifier-mode +1))
  (setf tide-format-options
        '(:insertSpaceAfterFunctionKeywordForAnonymousFunctions t :placeOpenBraceOnNewLineForFunctions nil))
  (setf tide-tsserver-process-environment '("TSS_LOG=-level verbose -file /tmp/tss.log"))
  (add-hook 'before-save-hook 'tide-format-before-save)
  ;; Añade company-tide como fuente de auto-completado para varios modos
  ;; mayores que lidian con JavaScript/Typescript
  (dolist (hook '(js2-mode-hook
                  rjsx-mode-hook
                  inferior-js-mode-hook
                  typescript-mode-hook
                  ng2-ts-mode-hook))
    (add-hook hook #'setup-tide-mode)
    (add-hook hook (lambda ()
                     (add-to-list (make-local-variable 'company-backends)
                                  '(company-tide :with company-yasnippet)))))
  :config
  (with-eval-after-load flycheck-mode
    (flycheck-add-next-checker 'javascript-eslint 'jsx-tide 'append)))

(use-package js2-refactor
  :after (js2-mode)
  :config
  (add-hook 'js2-mode-hook #'js2-refactor-mode)
  (js2r-add-keybindings-with-prefix "C-c C-m"))

(use-package xref-js2
  :after (js2-mode)
  :init
  (add-hook 'js2-mode-hook (lambda () (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t))))

(use-package js2-mode
  :mode "\\.js\\'"
  :init
  (add-hook 'js2-mode-hook #'js2-imenu-extras-mode))

;; Indium se conecta con una pestaña del navegador web o un proceso de NodeJS
;; y provee varias características para el desarrollo en JavaScript
(use-package indium ;; https://indium.readthedocs.io/en/latest/setup.html
  :config
  (add-hook 'js-mode-hook #'indium-interaction-mode))

;; Modo mayor para trabajar con Reactive.JS
(use-package rjsx-mode
  :init
  (add-to-list 'auto-mode-alist '("components?\\/.*\\.js\\'" . rjsx-mode))
  (add-to-list 'auto-mode-alist '("containers?\\/.*\\.js\\'" . rjsx-mode))
  :config
  ;; tomado de https://emacs.stackexchange.com/a/33544/690 mejora el sangrado
  ;; de lineas
  (defadvice js-jsx-indent-line (after js-jsx-indent-line-after-hack activate)
    "Workaround sgml-mode and follow airbnb component style."
    (save-excursion
      (beginning-of-line)
      (if (looking-at-p "^ +\/?> *$")
          (delete-char sgml-basic-offset)))))

(with-eval-after-load flycheck-mode
  ;; tomado de https://jamiecollinson.com/blog/my-emacs-config/ hace que
  ;; flycheck utilice eslint instalado en el proyecto en lugar del habilitado
  ;; globalmente en el sistema
  (defun jc/use-eslint-from-node-modules ()
    "Set local eslint if available."
    (let* ((root (locate-dominating-file
                  (or (buffer-file-name) default-directory)
                  "node_modules"))
           (eslint (and root
                        (expand-file-name "node_modules/eslint/bin/eslint.js"
                                          root))))
      (when (and eslint (file-executable-p eslint))
        (setq-local flycheck-javascript-eslint-executable eslint))))

  (add-hook 'flycheck-mode-hook #'jc/use-eslint-from-node-module))
@felipeochoa
Copy link
Owner

What version of rjsx are you using? I can reproduce the first problem (working on a fix), but not the second one

felipeochoa added a commit that referenced this issue Apr 18, 2018
@shackra
Copy link
Author

shackra commented Apr 18, 2018 via email

@ar1a
Copy link

ar1a commented Apr 21, 2018

I have this problem with https://github.com/hlissner/doom-emacs too

@felipeochoa
Copy link
Owner

Is this issue still happening with the latest version of rjsx? Based on the syntax highlighting it looks like the parse is choking on your file, but when I manually write it into a test buffer it works fine. Would you mind pasting the file that is causing issues for you?

@shackra
Copy link
Author

shackra commented Apr 28, 2018

I'm not getting the close tag when deleting the / with C-d

@felipeochoa
Copy link
Owner

Can you paste the whole buffer content that causes the issue?

@shackra
Copy link
Author

shackra commented Apr 28, 2018

Sure:

import React, { Component } from 'react';
import './App.css';

class App extends Component {
  constructor() {
    super();
    this.state = { inputValue: "hola mundo" };
    this.onChange = this.onChange.bind(this);
  }
  onChange(event) {
    this.setState({ inputValue: event.target.value });
  }
  render() {
    return (
      <div>
        <input type="text" id="input1" value={this.state.inputValue} onChange={this.onChange} />
      </div>
    );
  }
}

export default App;

@felipeochoa
Copy link
Owner

Where are you trying to add the </div>?

@shackra
Copy link
Author

shackra commented Apr 28, 2018

I write < which becomes </> then I write div which leaves me with <div/> and the I press C-d which leaves me with <div> when I was expecting <div></div>. I need to write the / and then press C-d again to trigger the close tag auto-completion.

@felipeochoa
Copy link
Owner

I understand the issue, but still cannot reproduce. Where in the buffer are you writing this?

@shackra
Copy link
Author

shackra commented Apr 28, 2018

At the upper line from <input type="text" id="input1" value={this.state.inputValue} onChange={this.onChange} /> but inside the div tag.

@felipeochoa
Copy link
Owner

Sorry still nothing. Can you reproduce the issue in an emacs -Q session? Have you updated to the latest version of rjsx?

@shackra
Copy link
Author

shackra commented Apr 28, 2018

Here is a demo https://streamable.com/shkt3

Yes, I just updated all my packages 5 minutes ago

@felipeochoa
Copy link
Owner

And can you reproduce in an emacs -Q session? I understand the issue you're describing, but unless I can reproduce on my machine it's very hard to debug.

Can you do the following and let me know what you get?

  1. Type <div (so you end up with <div/>). Leave point on the /
  2. Run M-x eval-expression and then (get-char-property (point) 'rjsx-class)
  3. Run M-x eval-expression and then (js2-node-short-name (rjsx--tag-at-point))

@shackra
Copy link
Author

shackra commented Apr 28, 2018

These are the results, with emacs -Q:

self-closing-slash
"rjsx-node"

@felipeochoa
Copy link
Owner

And does it work with emacs -Q? What are the results in your normal session?

@shackra
Copy link
Author

shackra commented Apr 28, 2018

yeah, it actually works fine with emacs -Q

When running emacs normally the behavior shown on the last video is what happens

@felipeochoa
Copy link
Owner

Ok. At this point you should try bisecting your config to see what causes the issue. I personally use js2-refactor, and tide, so I it's probably not one of those. If you can narrow it down to a single package interacting badly with rjsx I can investigate from there

@shackra
Copy link
Author

shackra commented Apr 28, 2018

Done, using Bug hunter it tells me the error comes from this part of my configuration:

Initial tests done. Hunting for the cause...
"/home/jorge/.emacs.d/tmp-init.el", line 1332 pos 0:
  The assertion returned the following value here:
    t
  Caused by the following expression:
    (use-package prog-mode :ensure nil :init
      (defun shackra-prog-mode nil
        (set
         (make-local-variable 'fill-column)
         79)
        (set
         (make-local-variable 'comment-auto-fill-only-comments)
         t)
        (auto-fill-mode t)
        (highlight-numbers-mode)
        (hes-mode)
        (electric-pair-mode)
        (rainbow-turn-on)
        (when
            (or
             (executable-find "ispell")
             (executable-find "hunspell"))
          (flyspell-prog-mode))
        (prettify-symbols-mode))
      (bind-key* "C-M-," 'comment-dwim)
      (add-hook 'prog-mode-hook #'shackra-prog-mode))

But I don't know if you see anything meaningful in that snippet of code

@felipeochoa
Copy link
Owner

I think I may have found it... Can you try disabling flyspell-prog-mode and seeing if you can reproduce the issue? Can you then re-enable flyspell and after typing <div wait for ~10s and then try deleting the slash?

@shackra
Copy link
Author

shackra commented Apr 28, 2018

I was narrowing my code too and the issue is indeed flyspell-prog-mode, ha!

Disabling it functions as a workaround.

shackra added a commit to shackra/emacs that referenced this issue Apr 28, 2018
Evita desorden y la posibilidad de fallos en la configuración, aumenta el control sobre la configuración.

- dbordak/telephone-line#66
- felipeochoa/rjsx-mode#68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants