Skip to content

Commit e887c95

Browse files
feedback and fixups
1 parent e95af84 commit e887c95

11 files changed

Lines changed: 154 additions & 160 deletions

File tree

crates/rust-analyzer/src/config.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ pub struct Config {
11161116

11171117
default_config: &'static DefaultConfigData,
11181118
/// Config node that obtains its initial value during the server initialization and
1119-
/// by receiving a `lsp_types::DidChangeConfiguration`.
1119+
/// by receiving a [`lsp_types::DidChangeConfigurationNotification`].
11201120
client_config: (FullConfigInput, ConfigErrors),
11211121

11221122
/// Config node whose values apply to **every** Rust project.
@@ -2657,8 +2657,6 @@ impl Config {
26572657
}
26582658

26592659
pub fn snippet_cap(&self) -> Option<SnippetCap> {
2660-
// FIXME: Also detect the proposed lsp version at caps.workspace.workspaceEdit.snippetEditSupport
2661-
// once lsp-types has it.
26622660
SnippetCap::new(self.snippet_text_edit())
26632661
}
26642662

crates/rust-analyzer/src/handlers/dispatch.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,7 @@ impl RequestDispatcher<'_> {
282282
R::Params: DeserializeOwned + fmt::Debug,
283283
{
284284
let req = self.req.take_if(|it| it.method == R::METHOD.to_string())?;
285-
// FIXME: use `as_str()` when that is possible
286-
// https://github.com/ribru17/gen-lsp-types/issues/9
287-
let res = crate::from_json(Box::new(R::METHOD.to_string()).leak(), &req.params);
285+
let res = crate::from_json(R::METHOD.to_string(), &req.params);
288286
match res {
289287
Ok(params) => {
290288
let panic_context =

crates/rust-analyzer/src/handlers/notification.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ pub(crate) fn handle_run_flycheck(
554554

555555
pub(crate) fn handle_abort_run_test(state: &mut GlobalState, _: ()) -> anyhow::Result<()> {
556556
if state.test_run_session.take().is_some() {
557-
state.send_notification::<lsp_ext::EndRunTest>(());
557+
state.send_notification::<lsp_ext::EndRunTestNotification>(());
558558
}
559559
Ok(())
560560
}

crates/rust-analyzer/src/handlers/request.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use lsp_server::ErrorCode;
1818
use lsp_types::{
1919
CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
2020
CallHierarchyOutgoingCall, CallHierarchyOutgoingCallsParams, CallHierarchyPrepareParams,
21-
CodeLens, CompletionItem, Contents, FoldingRange, FoldingRangeParams, InlayHint,
22-
InlayHintParams, Location, LocationLink, Position, PrepareRenameResult, Range, RenameParams,
23-
ResourceOperationKind, SemanticTokens, SemanticTokensDeltaParams,
21+
CodeLens, CompletionItem, Contents, DocumentChange, FoldingRange, FoldingRangeParams,
22+
InlayHint, InlayHintParams, Location, LocationLink, Position, PrepareRenameResult, Range,
23+
RenameParams, ResourceOperationKind, SemanticTokens, SemanticTokensDeltaParams,
2424
SemanticTokensDeltaRequestResponse, SemanticTokensParams, SemanticTokensRangeParams,
2525
SymbolInformation, SymbolTag, TextDocumentIdentifier, Uri, WorkspaceEdit,
2626
};
@@ -252,7 +252,7 @@ pub(crate) fn handle_run_test(
252252
params: lsp_ext::RunTestParams,
253253
) -> anyhow::Result<()> {
254254
if let Some(_session) = state.test_run_session.take() {
255-
state.send_notification::<lsp_ext::EndRunTest>(());
255+
state.send_notification::<lsp_ext::EndRunTestNotification>(());
256256
}
257257

258258
let mut handles = vec![];
@@ -1416,7 +1416,7 @@ pub(crate) fn handle_rename(
14161416

14171417
if let Some(changes) = workspace_edit.document_changes.as_ref() {
14181418
for change in changes {
1419-
resource_ops_supported(&snap.config, resolve_resource_op(change))?;
1419+
resource_ops_supported(&snap.config, change)?;
14201420
}
14211421
}
14221422

@@ -1542,8 +1542,8 @@ pub(crate) fn handle_code_action(
15421542
let changes = code_action.edit.as_ref().and_then(|it| it.document_changes.as_ref());
15431543
if let Some(changes) = changes {
15441544
for change in changes {
1545-
if let lsp_ext::SnippetDocumentChangeOperation::Change(res_op) = change {
1546-
resource_ops_supported(&snap.config, resolve_resource_op(res_op))?
1545+
if let lsp_ext::SnippetDocumentChangeOperation::Change(change) = change {
1546+
resource_ops_supported(&snap.config, change)?
15471547
}
15481548
}
15491549
}
@@ -1645,8 +1645,8 @@ pub(crate) fn handle_code_action_resolve(
16451645
&& let Some(changes) = edit.document_changes.as_ref()
16461646
{
16471647
for change in changes {
1648-
if let lsp_ext::SnippetDocumentChangeOperation::Change(res_op) = change {
1649-
resource_ops_supported(&snap.config, resolve_resource_op(res_op))?
1648+
if let lsp_ext::SnippetDocumentChangeOperation::Change(change) = change {
1649+
resource_ops_supported(&snap.config, change)?
16501650
}
16511651
}
16521652
}
@@ -2669,14 +2669,20 @@ fn crate_path(root_file_path: &VfsPath) -> Option<VfsPath> {
26692669
None
26702670
}
26712671

2672-
fn resource_ops_supported(config: &Config, kind: ResourceOperationKind) -> anyhow::Result<()> {
2673-
if !matches!(config.workspace_edit_resource_operations(), Some(resops) if resops.contains(&kind))
2672+
fn resource_ops_supported(config: &Config, kind: &DocumentChange) -> anyhow::Result<()> {
2673+
let op = match kind {
2674+
lsp_types::DocumentChange::CreateFile(_) => ResourceOperationKind::Create,
2675+
lsp_types::DocumentChange::RenameFile(_) => ResourceOperationKind::Rename,
2676+
lsp_types::DocumentChange::DeleteFile(_) => ResourceOperationKind::Delete,
2677+
lsp_types::DocumentChange::TextDocumentEdit(_) => return Ok(()),
2678+
};
2679+
if !matches!(config.workspace_edit_resource_operations(), Some(resops) if resops.contains(&op))
26742680
{
26752681
return Err(LspError::new(
26762682
ErrorCode::RequestFailed as i32,
26772683
format!(
26782684
"Client does not support {} capability.",
2679-
match kind {
2685+
match op {
26802686
ResourceOperationKind::Create => "create",
26812687
ResourceOperationKind::Rename => "rename",
26822688
ResourceOperationKind::Delete => "delete",
@@ -2689,15 +2695,6 @@ fn resource_ops_supported(config: &Config, kind: ResourceOperationKind) -> anyho
26892695
Ok(())
26902696
}
26912697

2692-
fn resolve_resource_op(op: &lsp_types::DocumentChange) -> ResourceOperationKind {
2693-
match op {
2694-
lsp_types::DocumentChange::CreateFile(_) => ResourceOperationKind::Create,
2695-
lsp_types::DocumentChange::RenameFile(_) => ResourceOperationKind::Rename,
2696-
lsp_types::DocumentChange::DeleteFile(_) => ResourceOperationKind::Delete,
2697-
lsp_types::DocumentChange::TextDocumentEdit(_) => todo!(),
2698-
}
2699-
}
2700-
27012698
pub(crate) fn diff(left: &str, right: &str) -> TextEdit {
27022699
use dissimilar::Chunk;
27032700

crates/rust-analyzer/src/lsp/capabilities.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ impl ClientCapabilities {
470470
}
471471

472472
pub fn snippet_text_edit(&self) -> bool {
473+
// FIXME: apply https://github.com/rust-lang/rust-analyzer/pull/22088
474+
// self.0.workspace.unwrap().workspace_edit.unwrap().snippet_edit_support
473475
self.experimental_bool("snippetTextEdit")
474476
}
475477

0 commit comments

Comments
 (0)