req -> lsp_ext
This commit is contained in:
parent
bec3bf701c
commit
3bec2be9de
@ -24,8 +24,7 @@ mod to_proto;
|
||||
mod from_proto;
|
||||
mod main_loop;
|
||||
mod markdown;
|
||||
// TODO: rename to lsp_ext
|
||||
pub mod req;
|
||||
pub mod lsp_ext;
|
||||
pub mod config;
|
||||
mod world;
|
||||
mod diagnostics;
|
||||
|
@ -1,12 +1,12 @@
|
||||
//! Defines `rust-analyzer` specific custom messages.
|
||||
//! rust-analyzer extensions to the LSP.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use lsp_types::request::Request;
|
||||
use lsp_types::{Location, Position, Range, TextDocumentIdentifier};
|
||||
use rustc_hash::FxHashMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub enum AnalyzerStatus {}
|
||||
|
||||
impl Request for AnalyzerStatus {
|
@ -38,12 +38,11 @@ use threadpool::ThreadPool;
|
||||
use crate::{
|
||||
config::{Config, FilesWatcher},
|
||||
diagnostics::DiagnosticTask,
|
||||
from_proto,
|
||||
from_proto, lsp_ext,
|
||||
main_loop::{
|
||||
pending_requests::{PendingRequest, PendingRequests},
|
||||
subscriptions::Subscriptions,
|
||||
},
|
||||
req,
|
||||
world::{WorldSnapshot, WorldState},
|
||||
Result,
|
||||
};
|
||||
@ -502,26 +501,27 @@ fn on_request(
|
||||
request_received,
|
||||
};
|
||||
pool_dispatcher
|
||||
.on_sync::<req::CollectGarbage>(|s, ()| Ok(s.collect_garbage()))?
|
||||
.on_sync::<req::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
|
||||
.on_sync::<req::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
|
||||
.on_sync::<lsp_ext::CollectGarbage>(|s, ()| Ok(s.collect_garbage()))?
|
||||
.on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
|
||||
.on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
|
||||
.on_sync::<lsp_types::request::SelectionRangeRequest>(|s, p| {
|
||||
handlers::handle_selection_range(s.snapshot(), p)
|
||||
})?
|
||||
.on_sync::<req::FindMatchingBrace>(|s, p| {
|
||||
.on_sync::<lsp_ext::FindMatchingBrace>(|s, p| {
|
||||
handlers::handle_find_matching_brace(s.snapshot(), p)
|
||||
})?
|
||||
.on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)?
|
||||
.on::<req::SyntaxTree>(handlers::handle_syntax_tree)?
|
||||
.on::<req::ExpandMacro>(handlers::handle_expand_macro)?
|
||||
.on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)?
|
||||
.on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)?
|
||||
.on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro)?
|
||||
.on::<lsp_ext::ParentModule>(handlers::handle_parent_module)?
|
||||
.on::<lsp_ext::Runnables>(handlers::handle_runnables)?
|
||||
.on::<lsp_ext::InlayHints>(handlers::handle_inlay_hints)?
|
||||
.on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)?
|
||||
.on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)?
|
||||
.on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)?
|
||||
.on::<lsp_types::request::GotoDefinition>(handlers::handle_goto_definition)?
|
||||
.on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation)?
|
||||
.on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition)?
|
||||
.on::<req::ParentModule>(handlers::handle_parent_module)?
|
||||
.on::<req::Runnables>(handlers::handle_runnables)?
|
||||
.on::<lsp_types::request::Completion>(handlers::handle_completion)?
|
||||
.on::<lsp_types::request::CodeActionRequest>(handlers::handle_code_action)?
|
||||
.on::<lsp_types::request::CodeLensRequest>(handlers::handle_code_lens)?
|
||||
@ -534,7 +534,6 @@ fn on_request(
|
||||
.on::<lsp_types::request::References>(handlers::handle_references)?
|
||||
.on::<lsp_types::request::Formatting>(handlers::handle_formatting)?
|
||||
.on::<lsp_types::request::DocumentHighlightRequest>(handlers::handle_document_highlight)?
|
||||
.on::<req::InlayHints>(handlers::handle_inlay_hints)?
|
||||
.on::<lsp_types::request::CallHierarchyPrepare>(handlers::handle_call_hierarchy_prepare)?
|
||||
.on::<lsp_types::request::CallHierarchyIncomingCalls>(
|
||||
handlers::handle_call_hierarchy_incoming,
|
||||
@ -546,7 +545,7 @@ fn on_request(
|
||||
.on::<lsp_types::request::SemanticTokensRangeRequest>(
|
||||
handlers::handle_semantic_tokens_range,
|
||||
)?
|
||||
.on::<req::Ssr>(handlers::handle_ssr)?
|
||||
.on::<lsp_ext::Ssr>(handlers::handle_ssr)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ use crate::{
|
||||
config::RustfmtConfig,
|
||||
diagnostics::DiagnosticTask,
|
||||
from_json, from_proto,
|
||||
req::{self, InlayHint, InlayHintsParams},
|
||||
lsp_ext::{self, InlayHint, InlayHintsParams},
|
||||
to_proto,
|
||||
world::WorldSnapshot,
|
||||
LspError, Result,
|
||||
@ -52,7 +52,10 @@ pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> {
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
pub fn handle_syntax_tree(world: WorldSnapshot, params: req::SyntaxTreeParams) -> Result<String> {
|
||||
pub fn handle_syntax_tree(
|
||||
world: WorldSnapshot,
|
||||
params: lsp_ext::SyntaxTreeParams,
|
||||
) -> Result<String> {
|
||||
let _p = profile("handle_syntax_tree");
|
||||
let id = from_proto::file_id(&world, ¶ms.text_document.uri)?;
|
||||
let line_index = world.analysis().file_line_index(id)?;
|
||||
@ -63,8 +66,8 @@ pub fn handle_syntax_tree(world: WorldSnapshot, params: req::SyntaxTreeParams) -
|
||||
|
||||
pub fn handle_expand_macro(
|
||||
world: WorldSnapshot,
|
||||
params: req::ExpandMacroParams,
|
||||
) -> Result<Option<req::ExpandedMacro>> {
|
||||
params: lsp_ext::ExpandMacroParams,
|
||||
) -> Result<Option<lsp_ext::ExpandedMacro>> {
|
||||
let _p = profile("handle_expand_macro");
|
||||
let file_id = from_proto::file_id(&world, ¶ms.text_document.uri)?;
|
||||
let line_index = world.analysis().file_line_index(file_id)?;
|
||||
@ -74,7 +77,7 @@ pub fn handle_expand_macro(
|
||||
None => Ok(None),
|
||||
Some(offset) => {
|
||||
let res = world.analysis().expand_macro(FilePosition { file_id, offset })?;
|
||||
Ok(res.map(|it| req::ExpandedMacro { name: it.name, expansion: it.expansion }))
|
||||
Ok(res.map(|it| lsp_ext::ExpandedMacro { name: it.name, expansion: it.expansion }))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,7 +127,7 @@ pub fn handle_selection_range(
|
||||
|
||||
pub fn handle_find_matching_brace(
|
||||
world: WorldSnapshot,
|
||||
params: req::FindMatchingBraceParams,
|
||||
params: lsp_ext::FindMatchingBraceParams,
|
||||
) -> Result<Vec<Position>> {
|
||||
let _p = profile("handle_find_matching_brace");
|
||||
let file_id = from_proto::file_id(&world, ¶ms.text_document.uri)?;
|
||||
@ -146,8 +149,8 @@ pub fn handle_find_matching_brace(
|
||||
|
||||
pub fn handle_join_lines(
|
||||
world: WorldSnapshot,
|
||||
params: req::JoinLinesParams,
|
||||
) -> Result<req::SourceChange> {
|
||||
params: lsp_ext::JoinLinesParams,
|
||||
) -> Result<lsp_ext::SourceChange> {
|
||||
let _p = profile("handle_join_lines");
|
||||
let frange = from_proto::file_range(&world, params.text_document, params.range)?;
|
||||
let source_change = world.analysis().join_lines(frange)?;
|
||||
@ -157,7 +160,7 @@ pub fn handle_join_lines(
|
||||
pub fn handle_on_enter(
|
||||
world: WorldSnapshot,
|
||||
params: lsp_types::TextDocumentPositionParams,
|
||||
) -> Result<Option<req::SourceChange>> {
|
||||
) -> Result<Option<lsp_ext::SourceChange>> {
|
||||
let _p = profile("handle_on_enter");
|
||||
let position = from_proto::file_position(&world, params)?;
|
||||
match world.analysis().on_enter(position)? {
|
||||
@ -388,8 +391,8 @@ pub fn handle_parent_module(
|
||||
|
||||
pub fn handle_runnables(
|
||||
world: WorldSnapshot,
|
||||
params: req::RunnablesParams,
|
||||
) -> Result<Vec<req::Runnable>> {
|
||||
params: lsp_ext::RunnablesParams,
|
||||
) -> Result<Vec<lsp_ext::Runnable>> {
|
||||
let _p = profile("handle_runnables");
|
||||
let file_id = from_proto::file_id(&world, ¶ms.text_document.uri)?;
|
||||
let line_index = world.analysis().file_line_index(file_id)?;
|
||||
@ -419,7 +422,7 @@ pub fn handle_runnables(
|
||||
match cargo_spec {
|
||||
Some(spec) => {
|
||||
for &cmd in ["check", "test"].iter() {
|
||||
res.push(req::Runnable {
|
||||
res.push(lsp_ext::Runnable {
|
||||
range: Default::default(),
|
||||
label: format!("cargo {} -p {}", cmd, spec.package),
|
||||
bin: "cargo".to_string(),
|
||||
@ -431,7 +434,7 @@ pub fn handle_runnables(
|
||||
}
|
||||
}
|
||||
None => {
|
||||
res.push(req::Runnable {
|
||||
res.push(lsp_ext::Runnable {
|
||||
range: Default::default(),
|
||||
label: "cargo check --workspace".to_string(),
|
||||
bin: "cargo".to_string(),
|
||||
@ -972,7 +975,10 @@ pub fn handle_document_highlight(
|
||||
Ok(Some(res))
|
||||
}
|
||||
|
||||
pub fn handle_ssr(world: WorldSnapshot, params: req::SsrParams) -> Result<req::SourceChange> {
|
||||
pub fn handle_ssr(
|
||||
world: WorldSnapshot,
|
||||
params: lsp_ext::SsrParams,
|
||||
) -> Result<lsp_ext::SourceChange> {
|
||||
let _p = profile("handle_ssr");
|
||||
let source_change =
|
||||
world.analysis().structural_search_replace(¶ms.query, params.parse_only)??;
|
||||
@ -1003,7 +1009,7 @@ fn to_lsp_runnable(
|
||||
world: &WorldSnapshot,
|
||||
file_id: FileId,
|
||||
runnable: Runnable,
|
||||
) -> Result<req::Runnable> {
|
||||
) -> Result<lsp_ext::Runnable> {
|
||||
let spec = CargoTargetSpec::for_file(world, file_id)?;
|
||||
let (args, extra_args) = CargoTargetSpec::runnable_args(spec, &runnable.kind)?;
|
||||
let line_index = world.analysis().file_line_index(file_id)?;
|
||||
@ -1014,7 +1020,7 @@ fn to_lsp_runnable(
|
||||
RunnableKind::DocTest { test_id, .. } => format!("doctest {}", test_id),
|
||||
RunnableKind::Bin => "run binary".to_string(),
|
||||
};
|
||||
Ok(req::Runnable {
|
||||
Ok(lsp_ext::Runnable {
|
||||
range: to_proto::range(&line_index, runnable.range),
|
||||
label,
|
||||
bin: "cargo".to_string(),
|
||||
|
@ -10,7 +10,7 @@ use ra_syntax::{SyntaxKind, TextRange, TextSize};
|
||||
use ra_text_edit::{Indel, TextEdit};
|
||||
use ra_vfs::LineEndings;
|
||||
|
||||
use crate::{req, semantic_tokens, world::WorldSnapshot, Result};
|
||||
use crate::{lsp_ext, semantic_tokens, world::WorldSnapshot, Result};
|
||||
|
||||
pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> lsp_types::Position {
|
||||
let line_col = line_index.line_col(offset);
|
||||
@ -215,14 +215,14 @@ pub(crate) fn signature_information(
|
||||
lsp_types::SignatureInformation { label, documentation, parameters: Some(parameters) }
|
||||
}
|
||||
|
||||
pub(crate) fn inlay_int(line_index: &LineIndex, inlay_hint: InlayHint) -> req::InlayHint {
|
||||
req::InlayHint {
|
||||
pub(crate) fn inlay_int(line_index: &LineIndex, inlay_hint: InlayHint) -> lsp_ext::InlayHint {
|
||||
lsp_ext::InlayHint {
|
||||
label: inlay_hint.label.to_string(),
|
||||
range: range(line_index, inlay_hint.range),
|
||||
kind: match inlay_hint.kind {
|
||||
InlayKind::ParameterHint => req::InlayKind::ParameterHint,
|
||||
InlayKind::TypeHint => req::InlayKind::TypeHint,
|
||||
InlayKind::ChainingHint => req::InlayKind::ChainingHint,
|
||||
InlayKind::ParameterHint => lsp_ext::InlayKind::ParameterHint,
|
||||
InlayKind::TypeHint => lsp_ext::InlayKind::TypeHint,
|
||||
InlayKind::ChainingHint => lsp_ext::InlayKind::ChainingHint,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -478,7 +478,7 @@ pub(crate) fn resource_op(
|
||||
pub(crate) fn source_change(
|
||||
world: &WorldSnapshot,
|
||||
source_change: SourceChange,
|
||||
) -> Result<req::SourceChange> {
|
||||
) -> Result<lsp_ext::SourceChange> {
|
||||
let cursor_position = match source_change.cursor_position {
|
||||
None => None,
|
||||
Some(pos) => {
|
||||
@ -513,7 +513,7 @@ pub(crate) fn source_change(
|
||||
changes: None,
|
||||
document_changes: Some(lsp_types::DocumentChanges::Operations(document_changes)),
|
||||
};
|
||||
Ok(req::SourceChange { label: source_change.label, workspace_edit, cursor_position })
|
||||
Ok(lsp_ext::SourceChange { label: source_change.label, workspace_edit, cursor_position })
|
||||
}
|
||||
|
||||
pub fn call_hierarchy_item(
|
||||
|
@ -3,15 +3,16 @@ mod support;
|
||||
use std::{collections::HashMap, path::PathBuf, time::Instant};
|
||||
|
||||
use lsp_types::{
|
||||
CodeActionContext, DidOpenTextDocumentParams, DocumentFormattingParams, FormattingOptions,
|
||||
GotoDefinitionParams, HoverParams, PartialResultParams, Position, Range, TextDocumentItem,
|
||||
TextDocumentPositionParams, WorkDoneProgressParams,
|
||||
};
|
||||
use rust_analyzer::req::{
|
||||
CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument,
|
||||
Formatting, GotoDefinition, GotoTypeDefinition, HoverRequest, OnEnter, Runnables,
|
||||
RunnablesParams,
|
||||
notification::DidOpenTextDocument,
|
||||
request::{
|
||||
CodeActionRequest, Completion, Formatting, GotoDefinition, GotoTypeDefinition, HoverRequest,
|
||||
},
|
||||
CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
|
||||
DocumentFormattingParams, FormattingOptions, GotoDefinitionParams, HoverParams,
|
||||
PartialResultParams, Position, Range, TextDocumentItem, TextDocumentPositionParams,
|
||||
WorkDoneProgressParams,
|
||||
};
|
||||
use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams};
|
||||
use serde_json::json;
|
||||
use tempfile::TempDir;
|
||||
use test_utils::skip_slow_tests;
|
||||
|
@ -13,15 +13,15 @@ use lsp_types::{
|
||||
request::Shutdown,
|
||||
DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url, WorkDoneProgress,
|
||||
};
|
||||
use lsp_types::{ProgressParams, ProgressParamsValue};
|
||||
use serde::Serialize;
|
||||
use serde_json::{to_string_pretty, Value};
|
||||
use tempfile::TempDir;
|
||||
use test_utils::{find_mismatch, parse_fixture};
|
||||
|
||||
use req::{ProgressParams, ProgressParamsValue};
|
||||
use rust_analyzer::{
|
||||
config::{ClientCapsConfig, Config},
|
||||
main_loop, req,
|
||||
main_loop,
|
||||
};
|
||||
|
||||
pub struct Project<'a> {
|
||||
@ -206,7 +206,7 @@ impl Server {
|
||||
Message::Notification(n) if n.method == "$/progress" => {
|
||||
match n.clone().extract::<ProgressParams>("$/progress").unwrap() {
|
||||
ProgressParams {
|
||||
token: req::ProgressToken::String(ref token),
|
||||
token: lsp_types::ProgressToken::String(ref token),
|
||||
value: ProgressParamsValue::WorkDone(WorkDoneProgress::End(_)),
|
||||
} if token == "rustAnalyzer/startup" => true,
|
||||
_ => false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user