Skip to content

Commit

Permalink
lsp-pwsh: support code formatting (#1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiennq authored and yyoncho committed Dec 4, 2019
1 parent b121626 commit fc8c860
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -3136,6 +3136,8 @@ The method uses `replace-buffer-contents'."
beg (+ beg (length newText))
length)))))))))

(defvar-local lsp--filter-cr? t)

(defun lsp--apply-text-edits (edits)
"Apply the edits described in the TextEdit[] object."
(unless (seq-empty-p edits)
Expand All @@ -3153,6 +3155,11 @@ The method uses `replace-buffer-contents'."
'lsp--apply-text-edit)))
(unwind-protect
(->> edits
(mapc (lambda (edit)
(when lsp--filter-cr?
;; filter \r out of text since it's mostly useless
(ht-set edit "newText"
(s-replace "\r" "" (ht-get edit "newText" ""))))))
(nreverse)
(seq-sort #'lsp--text-edit-sort-predicate)
(mapc (lambda (edit)
Expand Down
5 changes: 4 additions & 1 deletion lsp-pwsh.el
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ Must not nil.")
:initialized-fn (lambda (w)
(with-lsp-workspace w
(lsp--set-configuration
(lsp-configuration-section "powershell"))))
(lsp-configuration-section "powershell")))
(let ((caps (lsp--workspace-server-capabilities w)))
(ht-set caps "documentRangeFormattingProvider" t)
(ht-set caps "documentFormattingProvider" t)))
))

;; Compatibility
Expand Down

0 comments on commit fc8c860

Please sign in to comment.