-
Notifications
You must be signed in to change notification settings - Fork 78
Add support for expressions and nested strings in templates #48
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
Comments
I'm going to just assume that however we decide to handle this, it ultimately comes down to syntax-tables and other relatively low-level cruft. To my knowledge syntax-tables have no understanding of interrupting string-sections with intermediate code-blocks by a string-delimiter-escape-character, before the subsequent string-section continues until the original string-delimiter is met (and whatever evil cyclic conditions one can manufacture using this technique). We can try hack our way around this, but if this functionality is needed in
There's no need to reinvent wheels emacs-devel is making for us (if they are making it for us). Agreed? Disagreed? |
I agree. It may turn out that I'll note again that |
I've written a fairly detailed email about the issue to Feel free to chime in on the issue and thread if you feel like I missed something important. |
Any news about this ? |
Any update on this? Its been years. |
I think the only realistic way this is getting solved is if somebody is willing to do what @theothornhill did for IMO that rewrite worked out really well. So well in fact I tried to do the same for If somebody else however wants to take a stab at that, I would fully support such an initiative. 😄 |
Hi! I'm actually looking to do this, since I'm a little bothered by the indentation troubles with typescript. In particular inside jsx. I've been holding off a little because I was waiting for the native implementation by Yuan Fu to land in emacs proper. I could do the same for typescript mode if you want, but I'm a little unsure if it is best to wait for emacs proper. I saw you added me to this repo, so I can start working on a branch anyways if you'd like. I write a lot of ts these days, so my motivation is improving, hehe. I think it should be pretty fast to do - the most problematic things would probably be setting the indentation properly, but most people use prettier anyways these days don't they? Thinking about it I think most of the work should be in the indentation engine. |
@josteink how about I take over your branch and turn the pr into a working draft for now? Then we'll see how far I get :) |
Of all bad luck, I think I only had that as a local branch... On a laptop I had Ubuntu on, but literally yesterday reformatted and installed Debian on instead. Ooops 😁 |
No I found it. No problem! I've started the work. Some indentation is working already, so I think this will be quick. How about we cooperate on this? I'll push what I have and we can just use it and extend it? Right now all you need to do is to |
pushed |
I've opened this bug report but I'm fine with anybody taking it over. I've
had a slew of life changing events in my life that make it so that I'm
probably not going to return to making changes to this mode. I haven't done
substantial software work in about 2 years, and I'm now focussing on other
things, like writing, producing videos, and counseling people with life
changing diseases or LGBTQ+ issues.
I'm not saying I'll never return to programming, but the chances are slim
at this stage.
…On Wed, Apr 20, 2022 at 8:39 AM Jostein Kjønigsen ***@***.***> wrote:
Of all bad luck, I think I only had that as a local branch... On a laptop
I had Ubuntu on, but literally yesterday reformatted and installed Debian
on instead. Ooops 😁
—
Reply to this email directly, view it on GitHub
<#48 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAO7LZIGRDL74GTCPQ54VFLVF73HJANCNFSM4DXZ7TMA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Good luck on your endeavours - the code'll be here should you decide to return :) |
Sounds good @theothornhill! And best of luck to you @lddubeau ! |
It may be possible to leverage the semantic tokens feature from the language server to accomplish this as well. It seems supported by lsp-mode. |
I'd advise against that. Imo it is not wise to offload more things to json. Also only lspmode supports that and not all servers do. Lastly, one can always enable it on top of tree sitter. Just my 2 cents :) |
We do indeed indent now :) and also support the new emacs proper |
(though not finished yet) :) |
I've implemented a matcher for the (defun typescript--match-subst-in-quotes (limit)
"Match dollar substitutions inside backticks."
(catch 'done
(while (re-search-forward
;; `rx' is cool, mkay.
(rx (or line-start (not (any "\\")))
(group
"$"
(and "{" (+? nonl) "}")))
limit t)
(-when-let (string-syntax (nth 3 (syntax-ppss)))
(when (= string-syntax 96)
(throw 'done (point))))))) somewhere in the keywords add (typescript--match-subst-in-quotes
(1 'default t)) I will add tests and make a PR these days but I'm traveling ATM. Feel free to try this out though :) |
This issue is old and has seen no activity in a year+. Closing this issue. Typescript support is now included in Emacs core, so if you still have problems, open a new issue on the GNU Emacs bug-tracker 😄 |
This is resolved by using |
[Opening an issue for a problem discovered while discussing #20 .]
Template strings allow expressions in string and strings to nest. For instance:
equals
"a3b"
. And since expressions can be strings, then this is valid:and equals
"abc"
Problematic areas:
The highlighter fails to handle anything in
${}
as an expression. (Trying the same in plain JS code:js-mode
is just as broken astypescript-mode
.js2-mode
, however, handles it fine.)typescript--re-search-backward-inner
completely ignores expressions in strings or the fact that strings can nest. Same fortypescript--re-search-forward-inner
. These are used for movement across syntactic features and for indentation.syntax-ppss
, which is also used for movement across syntactic features and for indentation, ignores string nesting.js2-mode
appears to have solved the issue though because I get meaningful results from checking the values ofsyntax-ppss
in nested strings in a JS file withjs2-mode
.There may be yet other problematic areas I've not identified.
The text was updated successfully, but these errors were encountered: