Closed llemaitre19 closed 7 months ago
Thank you for your work on jtsx and for looking into my fork! I'm currently working on folding and backward/forward list functions behaviour, and I plan to do further manual testing and debugging on a few private TypeScript/JavaScript/React projects.
The aim is to create a PR for this within the next few days, although this timeline might extend if I encounter some more issues.
Sounds great ! Thank you for contributing to this package.
I used jtsx
modes last week to replace web-mode
, typescript-mode
, and js2-mode
on a fairly large code base. Thank you for putting it all together – especially the test suite – that was quite a large job!
I haven’t tried it yet with mmm-mode
on gql
and css-in-js
strings. Everything else seems usable. Here’s my current configuration:
https://github.com/ramblehead/.emacs.d/blob/f5dd30483d62bb1e83dbe481732d85fa748f9d9a/init.el#L2198
I use code folding extensively in my workflow, therefore, I had to look into Subj. issue.
I had to perform a few smerge calls to rebase my changes onto your latest master branch. I’m not 100% sure if the merges didn’t introduce any issues. I also haven’t found a good way to execute run-tests.bash
on my system yet, as I don’t use Nix (in transition from Ubuntu to Guix 😅). It seems that your GitHub workflows test.yml
is also disabled, so I’m a bit hesitant to create a PR.
Could I ask you to clone it from my branch and run the tests on your side? https://github.com/ramblehead/jtsx/tree/code-folding
Issues and concerns with this code-folding revision:
hide-show
code is a blend of treesit and regexp approaches. It’s uncertain if this is the best practice. It might need to be refactored to rely solely on treesit queries.hide-show
does not fold js/ts code inside {}
fragments in jsx blocks – it only folds the entire {}
fragment.jtsx-hs-forward-sexp
does not fully support forward-sexp
arguments - it always jumps one sexp forward for a positive argument and one sexp backward for a negative argument.jtsx-hs-forward-sexp
does not handle js/ts blocks inside jsx blocks.jtsx-backward-up-list
does not support backward-up-list
arguments - it always jumps up one level.Many thanks for your work @ramblehead !
I haven’t tried it yet with mmm-mode on gql and css-in-js strings.
I rarely use graphql and css in js strings, but it would be great to be able to support it in some way.
For css in js, I did a PR in tree-sitter-css-in-js few weeks ago to try to make it usable with jtsx
but I am still waiting for a feedback of the maintainer.
I didn't know about the existence of mmm-mode
(or forget it !), a quick look at it let me know it is well maintained and should be compatible with tree-sitter based modes. I am going to try it , thank you for having pointed it.
I also haven’t found a good way to execute run-tests.bash on my system yet
I need to work on making the test suite easier to use for contributors... I just have completed the integration of Eask for that purpose, but it is not yet on the master
branch.
To run run-tests.bash
, you need to install the nix package manager (https://nixos.org/download/#nix-install-linux) and enable Nix nix-command
and flakes
experimental features (https://nixos.org/manual/nix/stable/command-ref/conf-file#conf-experimental-features).
It seems that your GitHub workflows test.yml is also disabled
As far I know it is working in this repo (https://github.com/llemaitre19/jtsx/actions). But on your fork I see no workflow has run, I cannot remember if there is something to do to enable workflows on a forked repository.
Anyway, I have run the tests on my local machine, all tests have passed on 29.1
and 29.2
. But on the snapshot version I get 1 unexpected test failure:
F jtsx-test-hs-forward-sexp-parenthesis
(ert-test-failed
((should (equal (hs-forward-sexp-into-buffer content move-point #'jtsx-jsx-mode) result)) :form
(equal 11 10) :value nil :explanation (different-atoms (11 "#xb" "?\13") (10 "#xa" "?\n"))))
This small change makes the test succeed:
diff --git a/jtsx.el b/jtsx.el
index 04b855d..c8c612d 100644
--- a/jtsx.el
+++ b/jtsx.el
@@ -885,7 +885,7 @@ INTERACTIVE and argument."
;; some issues. Bug report:
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66988 Use the
;; default one instead.
- (> 30 emacs-major-version)
+ (>= 30 emacs-major-version)
;; Prevent recursive call
(eq forward-sexp-function #'jtsx-hs-forward-sexp))
It confirms that the bug #66988
is still present in Emacs master branch...
The PR has your suggested fix with Emacs version ">=30" and I re-based it to your current master branch.
The Pull Request includes your suggested fix for Emacs version “>=30”, and I have rebased it onto your current master branch. When I have some time, I’ll experiment with the Nix package manager in Guix. They seem to be compatible:
https://guix.gnu.org/manual/en/html_node/Miscellaneous-Services.html#Nix-service https://search.nixos.org/options?query=services.guix
Thank you for the comments and the thorough PR review! I am currently in a transition between jobs and away from any reasonable internet 😅
I will try to respond to your review next weekend.
For now I can say that the funny looking regexp is due to valid JS blocks inside JSX prop values that allow "//" and "/**/" comments inside opening tag. Also, JSX props can be commented with "//". Therefore regexp that just excludes "/" symbol could not be used here. There are some other edge cases, such as XML in string or comments inside JS inside JSX. This is the reason of my concern with "blend of treesit and regexp approaches".
I have merged your PR. You can see my comments inside it.
Additional comments or minor changes could be done later. It let the code folding works again from now on (in master branch). I close this issue.
Thank you again for giving some of your time to contribute to this package @ramblehead .
- hide-show does not fold js/ts code inside {} fragments in jsx blocks – it only folds the entire {} fragment.
- The function jtsx-hs-forward-sexp does not fully support forward-sexp arguments - it always jumps one sexp forward for a positive argument and one sexp backward for a negative argument.
- The function jtsx-hs-forward-sexp does not handle js/ts blocks inside jsx blocks.
The commit 2b50a2e should address these 3 points.
After some debugging, it appears that code folding does not work anymore for 2 reasons:
jtsx-hs-find-block-beginning
should return the new position instead ofnil
(bug probably introduced by commit 6a717e2).hs-looking-at-block-start-p
does not work anymore out of the box for JSX blocks, it needs to be customized.@ramblehead , your fork seems to exactly address these issues. If you are planning to send a PR soon, please let me know. Thanks !