Skip to content

Commit e5a6274

Browse files
authored
Timestamp fixes (#3823)
* Prefer float-time to doing it by hand Prefer (float-time) to (time-to-seconds (current-time)), as this uses less time and memory. * New function lsp--ms-since This refactors, preparing for a bug fix. * Fix bug in time delay calculation Return number of millseconds, not number of milliseconds modulo 1000.
1 parent 25be0a5 commit e5a6274

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lsp-mode.el

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,7 +3206,7 @@ workspace->result.
32063206
If NO-WAIT is non-nil send the request as notification."
32073207
(if no-wait
32083208
(lsp-notify method params)
3209-
(let* ((send-time (time-to-seconds (current-time)))
3209+
(let* ((send-time (float-time))
32103210
;; max time by which we must get a response
32113211
(expected-time
32123212
(and
@@ -3228,7 +3228,7 @@ If NO-WAIT is non-nil send the request as notification."
32283228
(accept-process-output
32293229
nil
32303230
(if expected-time (- expected-time send-time) 1))))
3231-
(setq send-time (time-to-seconds (current-time)))
3231+
(setq send-time (float-time))
32323232
(when (and expected-time (< expected-time send-time))
32333233
(error "Timeout while waiting for response. Method: %s" method)))
32343234
(setq done? t)
@@ -3245,7 +3245,7 @@ If NO-WAIT is non-nil send the request as notification."
32453245
"Send request METHOD with PARAMS and waits until there is no input.
32463246
Return same value as `lsp--while-no-input' and respecting `non-essential'."
32473247
(if non-essential
3248-
(let* ((send-time (time-to-seconds (current-time)))
3248+
(let* ((send-time (float-time))
32493249
;; max time by which we must get a response
32503250
(expected-time
32513251
(and
@@ -3263,7 +3263,7 @@ Return same value as `lsp--while-no-input' and respecting `non-essential'."
32633263
(catch 'lsp-done
32643264
(sit-for
32653265
(if expected-time (- expected-time send-time) 1)))
3266-
(setq send-time (time-to-seconds (current-time)))
3266+
(setq send-time (float-time))
32673267
(when (and expected-time (< expected-time send-time))
32683268
(error "Timeout while waiting for response. Method: %s" method)))
32693269
(setq done? (or resp-error resp-result))
@@ -6469,6 +6469,10 @@ PARAMS are the `workspace/configuration' request params"
64696469
section))))))
64706470
(apply #'vector)))
64716471

6472+
(defun lsp--ms-since (timestamp)
6473+
"Integer number of milliseconds since TIMESTAMP. Fractions discarded."
6474+
(floor (* 1000 (float-time (time-since timestamp)))))
6475+
64726476
(defun lsp--send-request-response (workspace recv-time request response)
64736477
"Send the RESPONSE for REQUEST in WORKSPACE and log if needed."
64746478
(-let* (((&JSONResponse :params :method :id) request)
@@ -6478,7 +6482,7 @@ PARAMS are the `workspace/configuration' request params"
64786482
(lsp--make-log-entry method id params 'incoming-req)))
64796483
(resp-entry (and lsp-log-io
64806484
(lsp--make-log-entry method id response 'outgoing-resp
6481-
(/ (nth 2 (time-since recv-time)) 1000)))))
6485+
(lsp--ms-since recv-time)))))
64826486
;; Send response to the server.
64836487
(when (lsp--log-io-p method)
64846488
(lsp--log-entry-new req-entry workspace)
@@ -6657,7 +6661,7 @@ server. WORKSPACE is the active workspace."
66576661
(when (lsp--log-io-p method)
66586662
(lsp--log-entry-new
66596663
(lsp--make-log-entry method id data 'incoming-resp
6660-
(/ (nth 2 (time-since before-send)) 1000))
6664+
(lsp--ms-since before-send))
66616665
workspace))
66626666
(when callback
66636667
(remhash id (lsp--client-response-handlers client))
@@ -6668,7 +6672,7 @@ server. WORKSPACE is the active workspace."
66686672
(when (lsp--log-io-p method)
66696673
(lsp--log-entry-new
66706674
(lsp--make-log-entry method id (lsp:json-response-error-error json-data)
6671-
'incoming-resp (/ (nth 2 (time-since before-send)) 1000))
6675+
'incoming-resp (lsp--ms-since before-send))
66726676
workspace))
66736677
(when callback
66746678
(remhash id (lsp--client-response-handlers client))

0 commit comments

Comments
 (0)