Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions lspce-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ be set to `lspce-move-to-lsp-abiding-column', and

(cl-defstruct lspce-documentChange
(kind) ;; change, documentChange, create, rename or delete
(change) ;;
)
(change)) ;;


(cl-defstruct lspce-completionCache
(prefix-start)
Expand Down Expand Up @@ -190,6 +190,7 @@ be set to `lspce-move-to-lsp-abiding-column', and
:synchronization (list
:dynamicRegistration :json-false
:willSave t
:willSaveWaitUntil t
:didSave t)
:completion (list
:dynamicRegistration :json-false
Expand All @@ -205,8 +206,7 @@ be set to `lspce-move-to-lsp-abiding-column', and
:tagSupport (list :valueSet [1])
:preselectSupoort :json-false
:insertReplaceSupport :json-false
:resolveSupport (list :properties (vector "documentation" "details" "additionalTextEdits"))
)
:resolveSupport (list :properties (vector "documentation" "details" "additionalTextEdits")))
:contextSupport t)
:hover (list
:dynamicRegistration :json-false
Expand Down Expand Up @@ -274,8 +274,8 @@ be set to `lspce-move-to-lsp-abiding-column', and
:tagSupport (list :valueSet [1 2]))
:callHierarchy (list
:dynamicRegistration :json-false))
:experimental lspce--{})
)
:experimental lspce--{}))


(defun lspce--initializeParams (rootUri &optional initializationOptions trace workspaceFolders)
"初始化参数"
Expand Down Expand Up @@ -701,13 +701,22 @@ Return value of `body', or nil if interrupted."
(lspce--notify
"textDocument/didClose" (lspce--make-didCloseTextDocumentParams))))

(defun lspce--make-willSaveTextDocumentParams ()
(list :textDocument (lspce--textDocumentIdenfitier (lspce--uri))
:reason 1))

(defun lspce--notify-textDocument/willSave ()
"Send textDocument/willSave to server."
(when (lspce--server-capable-chain "textDocumentSync" "willSave")
(lspce--notify
"textDocument/willSave"
(list :textDocument
(lspce--textDocumentIdenfitier (lspce--uri)) :reason 1))))
(lspce--make-willSaveTextDocumentParams))))

(defun lspce--request-textDocument/willSaveWaitUntil ()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, we can make two improvements here. 1. Adding a customizable variable to control whether sending this request or not. 2. Is it better to make this 1 customizable too?
WDYT?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll add a customizable variable

"Request textDocument/willSaveWaitUntil."
(when (lspce--server-capable-chain "textDocumentSync" "willSaveWaitUntil")
(let ((response (lspce--request "textDocument/willSaveWaitUntil" (lspce--make-willSaveTextDocumentParams) 1)))
(when response (lspce--apply-text-edits response)))))

(defun lspce--notify-textDocument/didSave ()
"Send textDocument/willSave to server."
Expand Down Expand Up @@ -892,8 +901,8 @@ Return value of `body', or nil if interrupted."
(lspce--info "Server message: %s" message))
((eq message-type 4)
(lspce--debug "Server message: %s" message))))
(t
)))))))
(t)))))))



(provide 'lspce-core)
2 changes: 2 additions & 0 deletions lspce.el
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,7 @@ Records BEG, END and PRE-CHANGE-LENGTH locally."
(add-hook 'pre-command-hook 'lspce--pre-command-hook nil t)
(add-hook 'post-self-insert-hook 'lspce--post-self-insert-hook nil t)
(add-hook 'before-save-hook 'lspce--notify-textDocument/willSave nil t)
(add-hook 'before-save-hook 'lspce--request-textDocument/willSaveWaitUntil nil t)
(add-hook 'after-save-hook 'lspce--notify-textDocument/didSave nil t)
(when lspce-enable-eldoc
(when eldoc-mode
Expand Down Expand Up @@ -1794,6 +1795,7 @@ Records BEG, END and PRE-CHANGE-LENGTH locally."
(remove-hook 'pre-command-hook 'lspce--pre-command-hook t)
(remove-hook 'post-self-insert-hook 'lspce--post-self-insert-hook t)
(remove-hook 'before-save-hook 'lspce--notify-textDocument/willSave t)
(remove-hook 'before-save-hook 'lspce--request-textDocument/willSaveWaitUntil t)
(remove-hook 'after-save-hook 'lspce--notify-textDocument/didSave t)
(remove-hook 'flymake-diagnostic-functions 'lspce-flymake-backend t)
(remove-hook 'eldoc-documentation-functions #'lspce-eldoc-function t)
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl LspServer {
Logger::info(&format!("emacs_envs: {}", &emacs_envs));

let mut child;
let root_dir = root_uri.strip_prefix("file://").unwrap_or(&root_uri);
if !emacs_envs.is_empty() {
let envs = serde_json::from_str::<HashMap<String, String>>(&emacs_envs);
match envs {
Expand All @@ -160,21 +161,23 @@ impl LspServer {
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.envs(envs)
.spawn();
.current_dir(root_dir)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is setting current dir necessary? If not set, will anything not work properly? or is it just a good coding practice?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this is an unrelated change I added to my fork, I did this so that rust-analyzer would pick up overrides correctly (i.e. using nightly rust in projects where I did rustup override set nightly)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this change and put it in a separate PR if you want

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this change and put it in a separate PR if you want

Sure, please, thanks.

.spawn();
}
Err(e) => {
Logger::error(&format!(
"deserializing emacs_envs failed with error {:?}", e
));
return None;
}
}
}
} else {
child = Command::new(cmd)
.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.current_dir(root_dir)
.spawn();
}

Expand Down