@@ -239,6 +239,15 @@ this variable to non-nil value for Javascript buffers using `setq-local' macro."
239239 :group 'tide
240240 :safe #'booleanp )
241241
242+ (defcustom tide-native-json-parsing (and (>= emacs-major-version 27 )
243+ (functionp 'json-serialize )
244+ (functionp 'json-parse-buffer )
245+ (functionp 'json-parse-string )
246+ nil )
247+ " Use native JSON parsing (only emacs >= 27)."
248+ :type 'boolean
249+ :group 'tide )
250+
242251(defconst tide--minimal-emacs
243252 " 24.4"
244253 " This is the oldest version of Emacs that tide supports." )
@@ -336,16 +345,36 @@ buffers, as they don't set `buffer-file-name' correctly."
336345
337346(defun tide-safe-json-read-file (filename )
338347 (condition-case nil
339- (let ((json-object-type 'plist ))
340- (json-read-file filename))
348+ (if tide-native-json-parsing
349+ (with-temp-buffer
350+ (insert-file-contents filename)
351+ (goto-char (point-min ))
352+ (json-parse-buffer :object-type 'plist :null-object json-null :false-object json-false))
353+ (let ((json-object-type 'plist ))
354+ (json-read-file filename)))
341355 (error '())))
342356
343357(defun tide-safe-json-read-string (string )
344358 (condition-case nil
345- (let ((json-object-type 'plist ))
346- (json-read-from-string string))
359+ (if tide-native-json-parsing
360+ (json-parse-string string :object-type 'plist :null-object json-null :false-object json-false)
361+ (let ((json-object-type 'plist ))
362+ (json-read-from-string string)))
347363 (error '())))
348364
365+ (defun tide-json-read-object ()
366+ (if tide-native-json-parsing
367+ (json-parse-buffer :object-type 'plist :null-object json-null :false-object json-false :array-type 'list )
368+ (let ((json-object-type 'plist )
369+ (json-array-type 'list ))
370+ (json-read-object ))))
371+
372+ (defun tide-json-encode (obj )
373+ " Encode OBJ into a JSON string. JSON arrays must be represented with vectors."
374+ (if tide-native-json-parsing
375+ (json-serialize obj :null-object json-null :false-object json-false)
376+ (json-encode obj)))
377+
349378(defun tide-plist-get (list &rest args )
350379 (cl-reduce
351380 (lambda (object key )
@@ -591,7 +620,7 @@ Offset is one based."
591620 (let* ((request-id (tide-next-request-id))
592621 (command `(:command , name :seq , request-id :arguments , args ))
593622 (json-encoding-pretty-print nil )
594- (encoded-command (json-encode command))
623+ (encoded-command (tide- json-encode command))
595624 (payload (concat encoded-command " \n " )))
596625 (process-send-string (tide-current-server) payload)
597626 (when callback
@@ -814,9 +843,7 @@ Currently, two kinds of cleanups are done:
814843
815844(defun tide-decode-response (process )
816845 (with-current-buffer (process-buffer process)
817- (let ((length (tide-decode-response-legth))
818- (json-object-type 'plist )
819- (json-array-type 'list ))
846+ (let ((length (tide-decode-response-legth)))
820847 (when (and length (tide-enough-response-p length ))
821848 (search-forward " {" )
822849 (backward-char 1 )
@@ -828,7 +855,7 @@ Currently, two kinds of cleanups are done:
828855 `(:success :json-false :type " response"
829856 :message , tide-max-response-length-error-message
830857 :request_seq , seq )))
831- (json-read-object ))))
858+ (tide- json-read-object))))
832859 (delete-region (point-min ) (point ))
833860 (when response
834861 (tide-dispatch response)))
@@ -1263,7 +1290,7 @@ Noise can be anything like braces, reserved keywords, etc."
12631290 `(:file ,(tide-buffer-file-name)
12641291 :startLine ,(tide-line-number-at-pos) :startOffset ,(tide-current-offset)
12651292 :endLine ,(tide-line-number-at-pos) :endOffset ,(+ 1 (tide-current-offset))
1266- :errorCodes ,(tide-get-flycheck-errors-ids-at-point))))
1293+ :errorCodes ,(vconcat ( tide-get-flycheck-errors-ids-at-point) ))))
12671294
12681295(defun tide-command:getCombinedCodeFix (fixId )
12691296 (tide-send-command-sync " getCombinedCodeFix"
@@ -1561,7 +1588,7 @@ This function is used for the basic completions sorting."
15611588 (let* ((source (plist-get (get-text-property 0 'completion name) :source ))
15621589 (entry-names (if source
15631590 `(:entryNames [(:name , name :source , source )])
1564- `(:entryNames ( , name) )))
1591+ `(:entryNames [ , name] )))
15651592 (arguments (-concat (get-text-property 0 'file-location name)
15661593 entry-names)))
15671594 (-when-let (response (tide-send-command-sync " completionEntryDetails" arguments))
@@ -2439,12 +2466,11 @@ current buffer."
24392466 t ))
24402467
24412468; ;; Identifier highlighting
2442-
24432469(defun tide-command:documentHighlights (cb )
24442470 (tide-send-command
24452471 " documentHighlights"
24462472 `(:file ,(tide-buffer-file-name) :line ,(tide-line-number-at-pos) :offset ,(tide-current-offset)
2447- :filesToSearch ( ,(tide-buffer-file-name)) )
2473+ :filesToSearch [ ,(tide-buffer-file-name)] )
24482474 cb))
24492475
24502476(defface tide-hl-identifier-face
0 commit comments