Comments (7)
Thanks for the bug report. Double-width characters are known to cause problems in naive code...
I'll see if I can't investigate this later on.
from typescript.el.
I've tested with the following simple code:
class Testy {
test() {
let x = "大塚 愛";
}
}
Upon pressing ;
at the end there, I do get weird behaviour.
For a scenario similar to yours I get more behaviour like this:
class Testy {
test() {
test("大塚 愛", function()
}
}
Upon typing the opening paren in function()
, the cursor gets moved thee characters ahead of where it should be.
Basically: After three wide characters the cursor is now three points ahead of where it should actually be! I refuse to believe that is a coincidence.
What seems to trigger is this section here: https://github.com/ananthakumaran/typescript.el/blob/master/typescript-mode.el#L484-L485
(and (not (nth 8 syntax))
typescript-auto-indent-flag)
I'll be honest and say I have no idea what that's supposed to mean, but when this code reports t
back, what gets run is indent-according-to-mode
, and that's what's triggering this behaviour. Could this be an error in indent.el
?
Running indent-according-to-mode
manually on any portion of the code with these wide characters does seem to lead to weird things, with the cursor-position often being calculated incorrectly.
For a quick workaround, I suggest you just set the typescript-auto-indent-flag
defcustom to nil
. This will suppresses this behaviour (and conceals the bug).
In the meantime, I'm not sure if this is a bug in our mode or if there are unicode errors in core Emacs functions. I'll try to get some help in these matters.
from typescript.el.
I've found the culprit. It's our code.
(defun typescript-indent-line ()
"Indent the current line as typescript."
(interactive)
(save-restriction
(widen)
(let* ((parse-status
(save-excursion (syntax-ppss (point-at-bol))))
(offset (- (current-column) (current-indentation))))
(indent-line-to (typescript--proper-indentation parse-status))
(when (> offset 0) (forward-char offset)))))
We're doing some weird calculations here, inside typescript--proper-indentation
, and that results in a "offset" between the original and the indented version, and a attempt to fix this mismatch.
Clearly we're calculating some things incorrectly here, and that's causing issues further up the stack.
Edit: This analysis is wrong. See comments further down.
from typescript.el.
I just started running into this when I switched to using fira code with the symbols font for pseudo ligatures. Any idea if this will get fixed?
from typescript.el.
Update: I hate to leave code to rot, so I decided to a minimal effort debugging.
I used the following test-buffer:
export class Moo {
let x = "abc";
let y = "大塚愛";
}
Pressing ;
after the line with "abc"
resulted in typescript--proper-indentation
returning 4
(which is correct).
Pressing ;
after the line with "大塚愛"
also resulted in typescript--proper-indentation
returning 4
(which again is the correct value).
So clearly the error is in the offset-calculation in typescript-indent-line
where we try to regain our original position after re-indenting the line. That should be much more manageable to analyse and debug, even for non-Elisp experts.
from typescript.el.
Nailed it: The problem is current-column
counts wide-chars as several characters, causing a API-wise impedance-mismatch with forward-char
(which counts all chars as 1 char).
This is easy to demonstrate. Take the following line in any mode:
abcd大塚愛
Put the cursor after the d
, and eval (current-column)
. It should print 4
.
Now put the cursor after the 大
, and eval (current-column)
. Our algorithm expects it to return 5
, but it returns 6
.
Are there any options to current-column
which correctly accounts for wide characters?
from typescript.el.
I've added a new function typescript--current-column
which is unicode-aware and employed that instead in typescript-indent-line
.
As far as I can see, this fixes this issue.
I also observe that we use current-column
lots of other places in our code, but until someone can demonstrate that this is causing issues elsewhere, in the name of cautiousness I've left those as is.
If we have issues they should then be trivial to migrate to typescript--current-column
.
from typescript.el.
Related Issues (20)
- can't seem to indent props in JSX expression HOT 1
- Consider migrating CI to something not Travis HOT 5
- Symbol’s value as variable is void: compilation-error-regexp-alist-alist HOT 4
- Indentation hangs in `typescript--backward-to-parameter-list` when previous function has unbalanced parens
- typescript-mode hangs if I enter a newline after a dot character.
- File mode specification error: (void-function -compose) HOT 3
- typescript new keyword 'override' highlight HOT 2
- M-j in /** foo */ comment blocks is broken. Reasonbly easy to fix HOT 3
- Bump Version Tag HOT 8
- const, let formatting with multiple lines HOT 1
- Missing debugger keyword HOT 1
- Freeze on indenting dot after comma HOT 1
- `typescript-mode` is failing to download HOT 4
- Incorrect highlighting of keywords on latest commit HOT 5
- Adding mechanisms in place not to collide with in-tree typescript-mode HOT 7
- typescript 4.9 - satisfies operator HOT 1
- No option to achieve desired formatting HOT 1
- typescript--backward-to-parameter-list can cause multi-second delays in large files HOT 4
- Diagnostics don't show until file is changed HOT 1
- Thanks HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.el.