[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/typescript-mode 2815dd1b4b 098/222: Add option to support
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/typescript-mode 2815dd1b4b 098/222: Add option to support indented case-statements. Fixes #23 (#66) |
Date: |
Sun, 6 Feb 2022 16:59:21 -0500 (EST) |
branch: elpa/typescript-mode
commit 2815dd1b4bbf902fb61e0a8f1aca6319c7b0c940
Author: jack-williams <jw@jackw.io>
Commit: Louis-Dominique Dubeau <ldd@lddubeau.com>
Add option to support indented case-statements. Fixes #23 (#66)
Add the `typescript-indent-switch-clauses` customization option. At the
default of `t`, it causes the mode to follow tsserver's indentation. When set
to `nil`, it causes the mode to follow the indentation that `typescript-mode`
was originally offering.
---
test-files/indentation-reference-document.ts | 23 ++++---------------
test-files/switch-case-indent-default.ts | 30 ++++++++++++++++++++++++
test-files/switch-case-indent-disabled.ts | 30 ++++++++++++++++++++++++
typescript-mode-tests.el | 24 +++++++++++++++++++-
typescript-mode.el | 34 ++++++++++++++++++++--------
5 files changed, 112 insertions(+), 29 deletions(-)
diff --git a/test-files/indentation-reference-document.ts
b/test-files/indentation-reference-document.ts
index 7ba8328968..fe06883a14 100644
--- a/test-files/indentation-reference-document.ts
+++ b/test-files/indentation-reference-document.ts
@@ -21,25 +21,10 @@ namespace ts.server {
// functions indent.
function getGlobalTypingsCacheLocation() {
- // We know switch/case is indented incorrectly.
- // TODO: FIX!
-
- // switch (process.platform) {
- // case "win32": {
- // const basePath = process.env.LOCALAPPDATA ||
- // process.env.APPDATA;
- // return combinePaths(normalizeSlashes(basePath),
"Microsoft/TypeScript");
- // }
- // case "darwin":
- // case "linux":
- // case "android": {
- // const cacheLocation =
getNonWindowsCacheLocation(process.platform === "darwin");
- // return combinePaths(cacheLocation, "typescript");
- // }
- // default:
- // Debug.fail(`unsupported platform '${process.platform}'`);
- // return;
- // }
+ const obj = {
+ case: 1,
+ default: 2
+ };
}
// interfaces and classes indent.
diff --git a/test-files/switch-case-indent-default.ts
b/test-files/switch-case-indent-default.ts
new file mode 100644
index 0000000000..b1af8804b5
--- /dev/null
+++ b/test-files/switch-case-indent-default.ts
@@ -0,0 +1,30 @@
+function indentTest(): any {
+ const obj = {
+ case: 1,
+ default: 2
+ };
+ switch (process.platform) {
+ case "win32": {
+ const basePath = process.env.LOCALAPPDATA ||
+ process.env.APPDATA;
+ return combinePaths(normalizeSlashes(basePath),
"Microsoft/TypeScript");
+ }
+ case "darwin":
+ const objCase = {
+ case: 1,
+ default: 2
+ };
+ case "linux":
+ case "android": {
+ const cacheLocation = getNonWindowsCacheLocation(process.platform
=== "darwin");
+ return combinePaths(cacheLocation, "typescript");
+ }
+ default:
+ const objDefault = {
+ case: 1,
+ default: 2
+ };
+ Debug.fail(`unsupported platform '${process.platform}'`);
+ return;
+ }
+}
diff --git a/test-files/switch-case-indent-disabled.ts
b/test-files/switch-case-indent-disabled.ts
new file mode 100644
index 0000000000..3b29dba743
--- /dev/null
+++ b/test-files/switch-case-indent-disabled.ts
@@ -0,0 +1,30 @@
+function getGlobalTypingsCacheLocation() {
+ const obj = {
+ case: 1,
+ default: 2
+ };
+ switch (process.platform) {
+ case "win32": {
+ const basePath = process.env.LOCALAPPDATA ||
+ process.env.APPDATA;
+ return combinePaths(normalizeSlashes(basePath),
"Microsoft/TypeScript");
+ }
+ case "darwin":
+ const objCase = {
+ case: 1,
+ default: 2
+ };
+ case "linux":
+ case "android": {
+ const cacheLocation = getNonWindowsCacheLocation(process.platform ===
"darwin");
+ return combinePaths(cacheLocation, "typescript");
+ }
+ default:
+ const objDefault = {
+ case: 1,
+ default: 2
+ };
+ Debug.fail(`unsupported platform '${process.platform}'`);
+ return;
+ }
+}
diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el
index da8f9a3aa8..487dc2fa8d 100644
--- a/typescript-mode-tests.el
+++ b/typescript-mode-tests.el
@@ -18,15 +18,37 @@
(untabify (point-min) (point-max)))
(ert-deftest indentation-reference-document-is-reflowed-correctly ()
- (let* ((buffer (find-file "test-files/indentation-reference-document.ts")))
+ (let ((buffer (find-file "test-files/indentation-reference-document.ts")))
;; double ensure mode is active
(typescript-mode)
+ (let ((test-reference (typescript-test-get-doc)))
+ (typescript-test-indent-all)
+ (should (string-equal test-reference
+ (typescript-test-get-doc)))
+ (let ((typescript-indent-switch-clauses nil))
+ (typescript-test-indent-all)
+ (should (string-equal test-reference
+ (typescript-test-get-doc)))))
+ (kill-buffer buffer)))
+
+(ert-deftest switch-case-indent-default ()
+ (let ((buffer (find-file "test-files/switch-case-indent-default.ts")))
+ (typescript-mode)
(let ((test-reference (typescript-test-get-doc)))
(typescript-test-indent-all)
(should (string-equal test-reference
(typescript-test-get-doc))))
+ (kill-buffer buffer)))
+(ert-deftest switch-case-indent-disabled ()
+ (let ((buffer (find-file "test-files/switch-case-indent-disabled.ts"))
+ (typescript-indent-switch-clauses nil))
+ (typescript-mode)
+ (let ((test-reference (typescript-test-get-doc)))
+ (typescript-test-indent-all)
+ (should (string-equal test-reference
+ (typescript-test-get-doc))))
(kill-buffer buffer)))
(defun get-all-matched-strings (to-match)
diff --git a/typescript-mode.el b/typescript-mode.el
index 16e3f1f890..bd2f332e4a 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -591,6 +591,13 @@ The value must be no less than minus
`typescript-indent-level'."
:safe 'integerp
:group 'typescript)
+(defcustom typescript-indent-switch-clauses t
+ "Enable indenting of switch case and default clauses to
+replicate tsserver behaviour. Indent level is taken to be
+`typescript-indent-level'."
+ :type 'boolean
+ :group 'typescript)
+
(defcustom typescript-auto-indent-flag t
"Whether to automatically indent when typing punctuation characters.
If non-nil, the characters {}();,: also indent the current line
@@ -2203,8 +2210,8 @@ moved on success."
((eq (char-after) ?#) 0)
((save-excursion (typescript--beginning-of-macro)) 4)
((nth 1 parse-status)
- (let ((same-indent-p (looking-at
- "[]})]\\|\\_<case\\_>\\|\\_<default\\_>"))
+ (let ((same-indent-p (looking-at "[]})]"))
+ (switch-keyword-p (looking-at
"\\_<default\\_>\\|\\_<case\\_>[^:]"))
(continued-expr-p (typescript--continued-expression-p)))
(goto-char (nth 1 parse-status))
(if (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)")
@@ -2214,13 +2221,22 @@ moved on success."
(eq (char-before) ?\)))
(backward-list))
(back-to-indentation)
- (cond (same-indent-p
- (current-column))
- (continued-expr-p
- (+ (current-column) (* 2 typescript-indent-level)
- typescript-expr-indent-offset))
- (t
- (+ (current-column) typescript-indent-level))))
+ (let* ((in-switch-p (unless same-indent-p
+ (looking-at "\\_<switch\\_>")))
+ (same-indent-p (or same-indent-p
+ (and switch-keyword-p
+ in-switch-p)))
+ (indent
+ (cond (same-indent-p
+ (current-column))
+ (continued-expr-p
+ (+ (current-column) (* 2
typescript-indent-level)
+ typescript-expr-indent-offset))
+ (t
+ (+ (current-column)
typescript-indent-level)))))
+ (if (and in-switch-p typescript-indent-switch-clauses)
+ (+ indent typescript-indent-level)
+ indent)))
(unless same-indent-p
(forward-char)
(skip-chars-forward " \t"))
- [nongnu] elpa/typescript-mode 761f3aec6e 161/222: Fix issues reported by package-lint, (continued)
- [nongnu] elpa/typescript-mode 761f3aec6e 161/222: Fix issues reported by package-lint, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode e82a4d2527 170/222: Add a new indentation test case that triggers an infinite loop., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 54f14c4827 202/222: Update README.md, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode b369d7d251 206/222: Merge pull request #147 from ltrel/typo-fixes, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode bc37bc4b15 176/222: Fix another member expression infinite loop., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 1e9fc35cb9 210/222: Make cask and emacs locations overridable., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 96800ed070 208/222: Migrate build to use proper tasks and new source for Emacs, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode e824162051 222/222: Merge pull request #159 from tancnle/fix-cl-deprecation-warnings, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 5b0487aae8 085/222: Fix the Emacs regex used for highlighting TS regexes., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 2cd997a8d5 102/222: Fix typescript--backward-to-parameter-list, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 2815dd1b4b 098/222: Add option to support indented case-statements. Fixes #23 (#66),
ELPA Syncer <=
- [nongnu] elpa/typescript-mode 861d5983b6 090/222: Make the comment-start and comment-end variables local., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 4e3850dd2a 105/222: Remove logic handling preprocessor macros, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 32f5034e9d 127/222: Extract tests as general tests, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode e15e2bfa1a 131/222: Add jsdoc tests, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode c0f11efdfd 143/222: Fixing typescript--forward-expression for multiline indented string, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode a0f2c3ebd4 164/222: Reimplement template auto conversion as a post-self-insert-hook, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode b44b75dbe1 172/222: Add test case for infinite loop, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 5bf30fe8d6 175/222: Add member expressions tests involving type parameters., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 1c27fb09ed 220/222: Fix cl deprecation warning, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode dd832751ab 217/222: Merge pull request #156 from zkry/fix-dot-after-exclamation-indentation, ELPA Syncer, 2022/02/06