Skip to content

Commit 3bec2be

Browse files
committed
req -> lsp_ext
1 parent bec3bf7 commit 3bec2be

File tree

7 files changed

+58
-53
lines changed

7 files changed

+58
-53
lines changed

crates/rust-analyzer/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ mod to_proto;
2424
mod from_proto;
2525
mod main_loop;
2626
mod markdown;
27-
// TODO: rename to lsp_ext
28-
pub mod req;
27+
pub mod lsp_ext;
2928
pub mod config;
3029
mod world;
3130
mod diagnostics;

crates/rust-analyzer/src/req.rs renamed to crates/rust-analyzer/src/lsp_ext.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//! Defines `rust-analyzer` specific custom messages.
1+
//! rust-analyzer extensions to the LSP.
2+
3+
use std::path::PathBuf;
24

35
use lsp_types::request::Request;
46
use lsp_types::{Location, Position, Range, TextDocumentIdentifier};
57
use rustc_hash::FxHashMap;
68
use serde::{Deserialize, Serialize};
79

8-
use std::path::PathBuf;
9-
1010
pub enum AnalyzerStatus {}
1111

1212
impl Request for AnalyzerStatus {

crates/rust-analyzer/src/main_loop.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ use threadpool::ThreadPool;
3838
use crate::{
3939
config::{Config, FilesWatcher},
4040
diagnostics::DiagnosticTask,
41-
from_proto,
41+
from_proto, lsp_ext,
4242
main_loop::{
4343
pending_requests::{PendingRequest, PendingRequests},
4444
subscriptions::Subscriptions,
4545
},
46-
req,
4746
world::{WorldSnapshot, WorldState},
4847
Result,
4948
};
@@ -502,26 +501,27 @@ fn on_request(
502501
request_received,
503502
};
504503
pool_dispatcher
505-
.on_sync::<req::CollectGarbage>(|s, ()| Ok(s.collect_garbage()))?
506-
.on_sync::<req::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
507-
.on_sync::<req::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
504+
.on_sync::<lsp_ext::CollectGarbage>(|s, ()| Ok(s.collect_garbage()))?
505+
.on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
506+
.on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
508507
.on_sync::<lsp_types::request::SelectionRangeRequest>(|s, p| {
509508
handlers::handle_selection_range(s.snapshot(), p)
510509
})?
511-
.on_sync::<req::FindMatchingBrace>(|s, p| {
510+
.on_sync::<lsp_ext::FindMatchingBrace>(|s, p| {
512511
handlers::handle_find_matching_brace(s.snapshot(), p)
513512
})?
514-
.on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)?
515-
.on::<req::SyntaxTree>(handlers::handle_syntax_tree)?
516-
.on::<req::ExpandMacro>(handlers::handle_expand_macro)?
513+
.on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)?
514+
.on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)?
515+
.on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro)?
516+
.on::<lsp_ext::ParentModule>(handlers::handle_parent_module)?
517+
.on::<lsp_ext::Runnables>(handlers::handle_runnables)?
518+
.on::<lsp_ext::InlayHints>(handlers::handle_inlay_hints)?
517519
.on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)?
518520
.on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)?
519521
.on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)?
520522
.on::<lsp_types::request::GotoDefinition>(handlers::handle_goto_definition)?
521523
.on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation)?
522524
.on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition)?
523-
.on::<req::ParentModule>(handlers::handle_parent_module)?
524-
.on::<req::Runnables>(handlers::handle_runnables)?
525525
.on::<lsp_types::request::Completion>(handlers::handle_completion)?
526526
.on::<lsp_types::request::CodeActionRequest>(handlers::handle_code_action)?
527527
.on::<lsp_types::request::CodeLensRequest>(handlers::handle_code_lens)?
@@ -534,7 +534,6 @@ fn on_request(
534534
.on::<lsp_types::request::References>(handlers::handle_references)?
535535
.on::<lsp_types::request::Formatting>(handlers::handle_formatting)?
536536
.on::<lsp_types::request::DocumentHighlightRequest>(handlers::handle_document_highlight)?
537-
.on::<req::InlayHints>(handlers::handle_inlay_hints)?
538537
.on::<lsp_types::request::CallHierarchyPrepare>(handlers::handle_call_hierarchy_prepare)?
539538
.on::<lsp_types::request::CallHierarchyIncomingCalls>(
540539
handlers::handle_call_hierarchy_incoming,
@@ -546,7 +545,7 @@ fn on_request(
546545
.on::<lsp_types::request::SemanticTokensRangeRequest>(
547546
handlers::handle_semantic_tokens_range,
548547
)?
549-
.on::<req::Ssr>(handlers::handle_ssr)?
548+
.on::<lsp_ext::Ssr>(handlers::handle_ssr)?
550549
.finish();
551550
Ok(())
552551
}

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::{
3434
config::RustfmtConfig,
3535
diagnostics::DiagnosticTask,
3636
from_json, from_proto,
37-
req::{self, InlayHint, InlayHintsParams},
37+
lsp_ext::{self, InlayHint, InlayHintsParams},
3838
to_proto,
3939
world::WorldSnapshot,
4040
LspError, Result,
@@ -52,7 +52,10 @@ pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> {
5252
Ok(buf)
5353
}
5454

55-
pub fn handle_syntax_tree(world: WorldSnapshot, params: req::SyntaxTreeParams) -> Result<String> {
55+
pub fn handle_syntax_tree(
56+
world: WorldSnapshot,
57+
params: lsp_ext::SyntaxTreeParams,
58+
) -> Result<String> {
5659
let _p = profile("handle_syntax_tree");
5760
let id = from_proto::file_id(&world, &params.text_document.uri)?;
5861
let line_index = world.analysis().file_line_index(id)?;
@@ -63,8 +66,8 @@ pub fn handle_syntax_tree(world: WorldSnapshot, params: req::SyntaxTreeParams) -
6366

6467
pub fn handle_expand_macro(
6568
world: WorldSnapshot,
66-
params: req::ExpandMacroParams,
67-
) -> Result<Option<req::ExpandedMacro>> {
69+
params: lsp_ext::ExpandMacroParams,
70+
) -> Result<Option<lsp_ext::ExpandedMacro>> {
6871
let _p = profile("handle_expand_macro");
6972
let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
7073
let line_index = world.analysis().file_line_index(file_id)?;
@@ -74,7 +77,7 @@ pub fn handle_expand_macro(
7477
None => Ok(None),
7578
Some(offset) => {
7679
let res = world.analysis().expand_macro(FilePosition { file_id, offset })?;
77-
Ok(res.map(|it| req::ExpandedMacro { name: it.name, expansion: it.expansion }))
80+
Ok(res.map(|it| lsp_ext::ExpandedMacro { name: it.name, expansion: it.expansion }))
7881
}
7982
}
8083
}
@@ -124,7 +127,7 @@ pub fn handle_selection_range(
124127

125128
pub fn handle_find_matching_brace(
126129
world: WorldSnapshot,
127-
params: req::FindMatchingBraceParams,
130+
params: lsp_ext::FindMatchingBraceParams,
128131
) -> Result<Vec<Position>> {
129132
let _p = profile("handle_find_matching_brace");
130133
let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
@@ -146,8 +149,8 @@ pub fn handle_find_matching_brace(
146149

147150
pub fn handle_join_lines(
148151
world: WorldSnapshot,
149-
params: req::JoinLinesParams,
150-
) -> Result<req::SourceChange> {
152+
params: lsp_ext::JoinLinesParams,
153+
) -> Result<lsp_ext::SourceChange> {
151154
let _p = profile("handle_join_lines");
152155
let frange = from_proto::file_range(&world, params.text_document, params.range)?;
153156
let source_change = world.analysis().join_lines(frange)?;
@@ -157,7 +160,7 @@ pub fn handle_join_lines(
157160
pub fn handle_on_enter(
158161
world: WorldSnapshot,
159162
params: lsp_types::TextDocumentPositionParams,
160-
) -> Result<Option<req::SourceChange>> {
163+
) -> Result<Option<lsp_ext::SourceChange>> {
161164
let _p = profile("handle_on_enter");
162165
let position = from_proto::file_position(&world, params)?;
163166
match world.analysis().on_enter(position)? {
@@ -388,8 +391,8 @@ pub fn handle_parent_module(
388391

389392
pub fn handle_runnables(
390393
world: WorldSnapshot,
391-
params: req::RunnablesParams,
392-
) -> Result<Vec<req::Runnable>> {
394+
params: lsp_ext::RunnablesParams,
395+
) -> Result<Vec<lsp_ext::Runnable>> {
393396
let _p = profile("handle_runnables");
394397
let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
395398
let line_index = world.analysis().file_line_index(file_id)?;
@@ -419,7 +422,7 @@ pub fn handle_runnables(
419422
match cargo_spec {
420423
Some(spec) => {
421424
for &cmd in ["check", "test"].iter() {
422-
res.push(req::Runnable {
425+
res.push(lsp_ext::Runnable {
423426
range: Default::default(),
424427
label: format!("cargo {} -p {}", cmd, spec.package),
425428
bin: "cargo".to_string(),
@@ -431,7 +434,7 @@ pub fn handle_runnables(
431434
}
432435
}
433436
None => {
434-
res.push(req::Runnable {
437+
res.push(lsp_ext::Runnable {
435438
range: Default::default(),
436439
label: "cargo check --workspace".to_string(),
437440
bin: "cargo".to_string(),
@@ -972,7 +975,10 @@ pub fn handle_document_highlight(
972975
Ok(Some(res))
973976
}
974977

975-
pub fn handle_ssr(world: WorldSnapshot, params: req::SsrParams) -> Result<req::SourceChange> {
978+
pub fn handle_ssr(
979+
world: WorldSnapshot,
980+
params: lsp_ext::SsrParams,
981+
) -> Result<lsp_ext::SourceChange> {
976982
let _p = profile("handle_ssr");
977983
let source_change =
978984
world.analysis().structural_search_replace(&params.query, params.parse_only)??;
@@ -1003,7 +1009,7 @@ fn to_lsp_runnable(
10031009
world: &WorldSnapshot,
10041010
file_id: FileId,
10051011
runnable: Runnable,
1006-
) -> Result<req::Runnable> {
1012+
) -> Result<lsp_ext::Runnable> {
10071013
let spec = CargoTargetSpec::for_file(world, file_id)?;
10081014
let (args, extra_args) = CargoTargetSpec::runnable_args(spec, &runnable.kind)?;
10091015
let line_index = world.analysis().file_line_index(file_id)?;
@@ -1014,7 +1020,7 @@ fn to_lsp_runnable(
10141020
RunnableKind::DocTest { test_id, .. } => format!("doctest {}", test_id),
10151021
RunnableKind::Bin => "run binary".to_string(),
10161022
};
1017-
Ok(req::Runnable {
1023+
Ok(lsp_ext::Runnable {
10181024
range: to_proto::range(&line_index, runnable.range),
10191025
label,
10201026
bin: "cargo".to_string(),

crates/rust-analyzer/src/to_proto.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use ra_syntax::{SyntaxKind, TextRange, TextSize};
1010
use ra_text_edit::{Indel, TextEdit};
1111
use ra_vfs::LineEndings;
1212

13-
use crate::{req, semantic_tokens, world::WorldSnapshot, Result};
13+
use crate::{lsp_ext, semantic_tokens, world::WorldSnapshot, Result};
1414

1515
pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> lsp_types::Position {
1616
let line_col = line_index.line_col(offset);
@@ -215,14 +215,14 @@ pub(crate) fn signature_information(
215215
lsp_types::SignatureInformation { label, documentation, parameters: Some(parameters) }
216216
}
217217

218-
pub(crate) fn inlay_int(line_index: &LineIndex, inlay_hint: InlayHint) -> req::InlayHint {
219-
req::InlayHint {
218+
pub(crate) fn inlay_int(line_index: &LineIndex, inlay_hint: InlayHint) -> lsp_ext::InlayHint {
219+
lsp_ext::InlayHint {
220220
label: inlay_hint.label.to_string(),
221221
range: range(line_index, inlay_hint.range),
222222
kind: match inlay_hint.kind {
223-
InlayKind::ParameterHint => req::InlayKind::ParameterHint,
224-
InlayKind::TypeHint => req::InlayKind::TypeHint,
225-
InlayKind::ChainingHint => req::InlayKind::ChainingHint,
223+
InlayKind::ParameterHint => lsp_ext::InlayKind::ParameterHint,
224+
InlayKind::TypeHint => lsp_ext::InlayKind::TypeHint,
225+
InlayKind::ChainingHint => lsp_ext::InlayKind::ChainingHint,
226226
},
227227
}
228228
}
@@ -478,7 +478,7 @@ pub(crate) fn resource_op(
478478
pub(crate) fn source_change(
479479
world: &WorldSnapshot,
480480
source_change: SourceChange,
481-
) -> Result<req::SourceChange> {
481+
) -> Result<lsp_ext::SourceChange> {
482482
let cursor_position = match source_change.cursor_position {
483483
None => None,
484484
Some(pos) => {
@@ -513,7 +513,7 @@ pub(crate) fn source_change(
513513
changes: None,
514514
document_changes: Some(lsp_types::DocumentChanges::Operations(document_changes)),
515515
};
516-
Ok(req::SourceChange { label: source_change.label, workspace_edit, cursor_position })
516+
Ok(lsp_ext::SourceChange { label: source_change.label, workspace_edit, cursor_position })
517517
}
518518

519519
pub fn call_hierarchy_item(

crates/rust-analyzer/tests/heavy_tests/main.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ mod support;
33
use std::{collections::HashMap, path::PathBuf, time::Instant};
44

55
use lsp_types::{
6-
CodeActionContext, DidOpenTextDocumentParams, DocumentFormattingParams, FormattingOptions,
7-
GotoDefinitionParams, HoverParams, PartialResultParams, Position, Range, TextDocumentItem,
8-
TextDocumentPositionParams, WorkDoneProgressParams,
9-
};
10-
use rust_analyzer::req::{
11-
CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument,
12-
Formatting, GotoDefinition, GotoTypeDefinition, HoverRequest, OnEnter, Runnables,
13-
RunnablesParams,
6+
notification::DidOpenTextDocument,
7+
request::{
8+
CodeActionRequest, Completion, Formatting, GotoDefinition, GotoTypeDefinition, HoverRequest,
9+
},
10+
CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
11+
DocumentFormattingParams, FormattingOptions, GotoDefinitionParams, HoverParams,
12+
PartialResultParams, Position, Range, TextDocumentItem, TextDocumentPositionParams,
13+
WorkDoneProgressParams,
1414
};
15+
use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams};
1516
use serde_json::json;
1617
use tempfile::TempDir;
1718
use test_utils::skip_slow_tests;

crates/rust-analyzer/tests/heavy_tests/support.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ use lsp_types::{
1313
request::Shutdown,
1414
DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url, WorkDoneProgress,
1515
};
16+
use lsp_types::{ProgressParams, ProgressParamsValue};
1617
use serde::Serialize;
1718
use serde_json::{to_string_pretty, Value};
1819
use tempfile::TempDir;
1920
use test_utils::{find_mismatch, parse_fixture};
2021

21-
use req::{ProgressParams, ProgressParamsValue};
2222
use rust_analyzer::{
2323
config::{ClientCapsConfig, Config},
24-
main_loop, req,
24+
main_loop,
2525
};
2626

2727
pub struct Project<'a> {
@@ -206,7 +206,7 @@ impl Server {
206206
Message::Notification(n) if n.method == "$/progress" => {
207207
match n.clone().extract::<ProgressParams>("$/progress").unwrap() {
208208
ProgressParams {
209-
token: req::ProgressToken::String(ref token),
209+
token: lsp_types::ProgressToken::String(ref token),
210210
value: ProgressParamsValue::WorkDone(WorkDoneProgress::End(_)),
211211
} if token == "rustAnalyzer/startup" => true,
212212
_ => false,

0 commit comments

Comments
 (0)