-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: lsp-restart #533
feat: lsp-restart #533
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1739,6 +1739,42 @@ mod cmd { | |
doc.reload(view.id) | ||
} | ||
|
||
fn lsp_restart( | ||
cx: &mut compositor::Context, | ||
_args: &[&str], | ||
_event: PromptEvent, | ||
) -> anyhow::Result<()> { | ||
let view = cx.editor.tree.get(cx.editor.tree.focus); | ||
let doc_id = view.doc; | ||
let doc = cx.editor.document(doc_id).unwrap(); | ||
let language_server = match doc.language_server_arc() { | ||
Some(language_server) => language_server, | ||
None => return Err(anyhow!("running lsp server not found")), | ||
}; | ||
|
||
log::debug!("got lspserver"); | ||
let fut = async move { | ||
log::debug!("trying shutdown"); | ||
let shutdown_result = language_server.shutdown_and_exit().await; | ||
if let Err(err) = shutdown_result { | ||
log::debug!("shutdown & exit request returned error: {}", err); // we're not doing anything except logging, if LSP crashes then this error is expected | ||
} | ||
let callback: job::Callback = Box::new(move |editor: &mut Editor, _compositor| { | ||
let doc = editor.document(doc_id).unwrap(); | ||
let language_config = doc.language_config_arc().unwrap(); | ||
let language_server = editor.language_servers.get(&language_config).unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're getting the failures because It's hard to get mutable access though, so I imagine we actually want to use arc-swap here to start a new server, arc-swap the new server in. It's a bit trickier than that, you also need to loop over all the documents and re-send textDocument/open events for all open files with that language server, as well as replay any changes since last file save (you can do this by taking the last saved version id, then replaying all the changes in the tree from that id to current id). |
||
log::debug!("got new language server"); | ||
let doc = editor.document_mut(doc_id).unwrap(); | ||
doc.set_language_server(Some(language_server)); | ||
log::debug!("set new language server"); | ||
}); | ||
Ok::<job::Callback, anyhow::Error>(callback) | ||
}; | ||
cx.jobs.callback(fut); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ | ||
TypableCommand { | ||
name: "quit", | ||
|
@@ -1935,6 +1971,13 @@ mod cmd { | |
doc: "Discard changes and reload from the source file.", | ||
fun: reload, | ||
completer: None, | ||
}, | ||
TypableCommand { | ||
name: "lsp-restart", | ||
alias: None, | ||
doc: "Restart current LSP connection.", | ||
fun: lsp_restart, | ||
completer: None, | ||
} | ||
]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for an arc here.