mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Reformat all
This commit is contained in:
parent
857c1650ef
commit
6be50f7d5d
35 changed files with 423 additions and 367 deletions
|
@ -1,8 +1,8 @@
|
|||
use languageserver_types::{
|
||||
CodeActionProviderCapability, CompletionOptions, DocumentOnTypeFormattingOptions,
|
||||
ExecuteCommandOptions, FoldingRangeProviderCapability, ServerCapabilities,
|
||||
SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind,
|
||||
TextDocumentSyncOptions, RenameProviderCapability, RenameOptions
|
||||
ExecuteCommandOptions, FoldingRangeProviderCapability, RenameOptions, RenameProviderCapability,
|
||||
ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind,
|
||||
TextDocumentSyncOptions,
|
||||
};
|
||||
|
||||
pub fn server_capabilities() -> ServerCapabilities {
|
||||
|
@ -40,8 +40,8 @@ pub fn server_capabilities() -> ServerCapabilities {
|
|||
more_trigger_character: None,
|
||||
}),
|
||||
folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)),
|
||||
rename_provider: Some(RenameProviderCapability::Options(RenameOptions{
|
||||
prepare_provider: Some(true)
|
||||
rename_provider: Some(RenameProviderCapability::Options(RenameOptions {
|
||||
prepare_provider: Some(true),
|
||||
})),
|
||||
color_provider: None,
|
||||
execute_command_provider: Some(ExecuteCommandOptions {
|
||||
|
|
|
@ -192,7 +192,8 @@ impl TryConvWith for SourceChange {
|
|||
.map(|it| it.edits.as_slice())
|
||||
.unwrap_or(&[]);
|
||||
let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits);
|
||||
let position = Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col)));
|
||||
let position =
|
||||
Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col)));
|
||||
Some(TextDocumentPositionParams {
|
||||
text_document: TextDocumentIdentifier::new(pos.file_id.try_conv_with(world)?),
|
||||
position,
|
||||
|
|
|
@ -36,4 +36,4 @@ pub mod thread_watcher;
|
|||
mod vfs;
|
||||
|
||||
pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
|
||||
pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError};
|
||||
pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError};
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
use gen_lsp_server::ErrorCode;
|
||||
use languageserver_types::{
|
||||
CodeActionResponse, Command, CompletionItem, CompletionItemKind, Diagnostic,
|
||||
DiagnosticSeverity, DocumentSymbol, FoldingRange, FoldingRangeKind, FoldingRangeParams,
|
||||
InsertTextFormat, Location, Position, SymbolInformation, TextDocumentIdentifier, TextEdit,
|
||||
RenameParams, WorkspaceEdit, PrepareRenameResponse, Documentation, MarkupContent, MarkupKind
|
||||
DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind,
|
||||
FoldingRangeParams, InsertTextFormat, Location, MarkupContent, MarkupKind, Position,
|
||||
PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit,
|
||||
WorkspaceEdit,
|
||||
};
|
||||
use gen_lsp_server::ErrorCode;
|
||||
use ra_analysis::{FileId, FoldKind, Query, RunnableKind};
|
||||
use ra_syntax::text_utils::contains_offset_nonstrict;
|
||||
use rustc_hash::FxHashMap;
|
||||
use serde_json::to_value;
|
||||
|
||||
use crate::{
|
||||
|
@ -17,13 +18,10 @@ use crate::{
|
|||
project_model::TargetKind,
|
||||
req::{self, Decoration},
|
||||
server_world::ServerWorld,
|
||||
Result, LspError
|
||||
LspError, Result,
|
||||
};
|
||||
|
||||
pub fn handle_syntax_tree(
|
||||
world: ServerWorld,
|
||||
params: req::SyntaxTreeParams,
|
||||
) -> Result<String> {
|
||||
pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result<String> {
|
||||
let id = params.text_document.try_conv_with(&world)?;
|
||||
let res = world.analysis().syntax_tree(id);
|
||||
Ok(res)
|
||||
|
@ -182,10 +180,7 @@ pub fn handle_workspace_symbol(
|
|||
|
||||
return Ok(Some(res));
|
||||
|
||||
fn exec_query(
|
||||
world: &ServerWorld,
|
||||
query: Query,
|
||||
) -> Result<Vec<SymbolInformation>> {
|
||||
fn exec_query(world: &ServerWorld, query: Query) -> Result<Vec<SymbolInformation>> {
|
||||
let mut res = Vec::new();
|
||||
for (file_id, symbol) in world.analysis().symbol_search(query)? {
|
||||
let line_index = world.analysis().file_line_index(file_id);
|
||||
|
@ -290,7 +285,11 @@ pub fn handle_runnables(
|
|||
});
|
||||
return Ok(res);
|
||||
|
||||
fn runnable_args(world: &ServerWorld, file_id: FileId, kind: &RunnableKind) -> Result<Vec<String>> {
|
||||
fn runnable_args(
|
||||
world: &ServerWorld,
|
||||
file_id: FileId,
|
||||
kind: &RunnableKind,
|
||||
) -> Result<Vec<String>> {
|
||||
let spec = CargoTargetSpec::for_file(world, file_id)?;
|
||||
let mut res = Vec::new();
|
||||
match kind {
|
||||
|
@ -327,18 +326,15 @@ pub fn handle_runnables(
|
|||
};
|
||||
let file_id = world.analysis().crate_root(crate_id)?;
|
||||
let path = world.path_map.get_path(file_id);
|
||||
let res = world
|
||||
.workspaces
|
||||
.iter()
|
||||
.find_map(|ws| {
|
||||
let tgt = ws.target_by_root(path)?;
|
||||
let res = CargoTargetSpec {
|
||||
package: tgt.package(ws).name(ws).to_string(),
|
||||
target: tgt.name(ws).to_string(),
|
||||
target_kind: tgt.kind(ws),
|
||||
};
|
||||
Some(res)
|
||||
});
|
||||
let res = world.workspaces.iter().find_map(|ws| {
|
||||
let tgt = ws.target_by_root(path)?;
|
||||
let res = CargoTargetSpec {
|
||||
package: tgt.package(ws).name(ws).to_string(),
|
||||
target: tgt.name(ws).to_string(),
|
||||
target_kind: tgt.kind(ws),
|
||||
};
|
||||
Some(res)
|
||||
});
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
|
@ -367,7 +363,6 @@ pub fn handle_runnables(
|
|||
}
|
||||
TargetKind::Other => (),
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -453,9 +448,7 @@ pub fn handle_signature_help(
|
|||
let line_index = world.analysis().file_line_index(file_id);
|
||||
let offset = params.position.conv_with(&line_index);
|
||||
|
||||
if let Some((descriptor, active_param)) =
|
||||
world.analysis().resolve_callable(file_id, offset)?
|
||||
{
|
||||
if let Some((descriptor, active_param)) = world.analysis().resolve_callable(file_id, offset)? {
|
||||
let parameters: Vec<ParameterInformation> = descriptor
|
||||
.params
|
||||
.iter()
|
||||
|
@ -468,7 +461,7 @@ pub fn handle_signature_help(
|
|||
let documentation = if let Some(doc) = descriptor.doc {
|
||||
Some(Documentation::MarkupContent(MarkupContent {
|
||||
kind: MarkupKind::Markdown,
|
||||
value: doc
|
||||
value: doc,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
|
@ -511,16 +504,17 @@ pub fn handle_prepare_rename(
|
|||
Ok(Some(PrepareRenameResponse::Range(loc.range)))
|
||||
}
|
||||
|
||||
pub fn handle_rename(
|
||||
world: ServerWorld,
|
||||
params: RenameParams,
|
||||
) -> Result<Option<WorkspaceEdit>> {
|
||||
pub fn handle_rename(world: ServerWorld, params: RenameParams) -> Result<Option<WorkspaceEdit>> {
|
||||
let file_id = params.text_document.try_conv_with(&world)?;
|
||||
let line_index = world.analysis().file_line_index(file_id);
|
||||
let offset = params.position.conv_with(&line_index);
|
||||
|
||||
if params.new_name.is_empty() {
|
||||
return Err(LspError::new(ErrorCode::InvalidParams as i32, "New Name cannot be empty".into()).into());
|
||||
return Err(LspError::new(
|
||||
ErrorCode::InvalidParams as i32,
|
||||
"New Name cannot be empty".into(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
let refs = world.analysis().find_all_refs(file_id, offset)?;
|
||||
|
@ -531,11 +525,10 @@ pub fn handle_rename(
|
|||
let mut changes = HashMap::new();
|
||||
for r in refs {
|
||||
if let Ok(loc) = to_location(r.0, r.1, &world, &line_index) {
|
||||
changes.entry(loc.uri).or_insert(Vec::new()).push(
|
||||
TextEdit {
|
||||
range: loc.range,
|
||||
new_text: params.new_name.clone()
|
||||
});
|
||||
changes.entry(loc.uri).or_insert(Vec::new()).push(TextEdit {
|
||||
range: loc.range,
|
||||
new_text: params.new_name.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -543,7 +536,7 @@ pub fn handle_rename(
|
|||
changes: Some(changes),
|
||||
|
||||
// TODO: return this instead if client/server support it. See #144
|
||||
document_changes : None,
|
||||
document_changes: None,
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -557,9 +550,11 @@ pub fn handle_references(
|
|||
|
||||
let refs = world.analysis().find_all_refs(file_id, offset)?;
|
||||
|
||||
Ok(Some(refs.into_iter()
|
||||
.filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok())
|
||||
.collect()))
|
||||
Ok(Some(
|
||||
refs.into_iter()
|
||||
.filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok())
|
||||
.collect(),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn handle_code_action(
|
||||
|
|
|
@ -24,7 +24,10 @@ use crate::{
|
|||
};
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
#[fail(display = "Language Server request failed with {}. ({})", code, message)]
|
||||
#[fail(
|
||||
display = "Language Server request failed with {}. ({})",
|
||||
code, message
|
||||
)]
|
||||
pub struct LspError {
|
||||
pub code: i32,
|
||||
pub message: String,
|
||||
|
@ -32,7 +35,7 @@ pub struct LspError {
|
|||
|
||||
impl LspError {
|
||||
pub fn new(code: i32, message: String) -> LspError {
|
||||
LspError {code, message}
|
||||
LspError { code, message }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,11 +217,7 @@ fn main_loop_inner(
|
|||
}
|
||||
}
|
||||
|
||||
fn on_task(
|
||||
task: Task,
|
||||
msg_sender: &Sender<RawMessage>,
|
||||
pending_requests: &mut FxHashSet<u64>,
|
||||
) {
|
||||
fn on_task(task: Task, msg_sender: &Sender<RawMessage>, pending_requests: &mut FxHashSet<u64>) {
|
||||
match task {
|
||||
Task::Respond(response) => {
|
||||
if pending_requests.remove(&response.id) {
|
||||
|
@ -373,12 +372,16 @@ impl<'a> PoolDispatcher<'a> {
|
|||
self.pool.spawn(move || {
|
||||
let resp = match f(world, params) {
|
||||
Ok(resp) => RawResponse::ok::<R>(id, &resp),
|
||||
Err(e) => {
|
||||
match e.downcast::<LspError>() {
|
||||
Ok(lsp_error) => RawResponse::err(id, lsp_error.code, lsp_error.message),
|
||||
Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, format!("{}\n{}", e, e.backtrace()))
|
||||
Err(e) => match e.downcast::<LspError>() {
|
||||
Ok(lsp_error) => {
|
||||
RawResponse::err(id, lsp_error.code, lsp_error.message)
|
||||
}
|
||||
}
|
||||
Err(e) => RawResponse::err(
|
||||
id,
|
||||
ErrorCode::InternalError as i32,
|
||||
format!("{}\n{}", e, e.backtrace()),
|
||||
),
|
||||
},
|
||||
};
|
||||
let task = Task::Respond(resp);
|
||||
sender.send(task);
|
||||
|
@ -412,7 +415,7 @@ fn update_file_notifications_on_threadpool(
|
|||
if !is_canceled(&e) {
|
||||
error!("failed to compute diagnostics: {:?}", e);
|
||||
}
|
||||
},
|
||||
}
|
||||
Ok(params) => {
|
||||
let not = RawNotification::new::<req::PublishDiagnostics>(¶ms);
|
||||
sender.send(Task::Notify(not));
|
||||
|
@ -423,7 +426,7 @@ fn update_file_notifications_on_threadpool(
|
|||
if !is_canceled(&e) {
|
||||
error!("failed to compute decorations: {:?}", e);
|
||||
}
|
||||
},
|
||||
}
|
||||
Ok(params) => {
|
||||
let not = RawNotification::new::<req::PublishDecorations>(¶ms);
|
||||
sender.send(Task::Notify(not))
|
||||
|
|
|
@ -33,7 +33,8 @@ impl PathMap {
|
|||
}
|
||||
pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> (bool, FileId) {
|
||||
let mut inserted = false;
|
||||
let file_id = self.path2id
|
||||
let file_id = self
|
||||
.path2id
|
||||
.get(path.as_path())
|
||||
.map(|&id| id)
|
||||
.unwrap_or_else(|| {
|
||||
|
|
|
@ -6,8 +6,8 @@ pub use languageserver_types::{
|
|||
notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CompletionParams,
|
||||
CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams,
|
||||
DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult,
|
||||
PublishDiagnosticsParams, SignatureHelp, TextDocumentEdit, TextDocumentPositionParams,
|
||||
TextEdit, WorkspaceSymbolParams, ReferenceParams,
|
||||
PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit,
|
||||
TextDocumentPositionParams, TextEdit, WorkspaceSymbolParams,
|
||||
};
|
||||
|
||||
pub enum SyntaxTree {}
|
||||
|
|
|
@ -5,7 +5,9 @@ use std::{
|
|||
};
|
||||
|
||||
use languageserver_types::Url;
|
||||
use ra_analysis::{Analysis, AnalysisHost, AnalysisChange, CrateGraph, FileId, FileResolver, LibraryData};
|
||||
use ra_analysis::{
|
||||
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FileResolver, LibraryData,
|
||||
};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::{
|
||||
|
@ -65,9 +67,7 @@ impl ServerWorldState {
|
|||
Some((file_id, text))
|
||||
}
|
||||
})
|
||||
.for_each(|(file_id, text)| {
|
||||
change.add_file(file_id, text)
|
||||
});
|
||||
.for_each(|(file_id, text)| change.add_file(file_id, text));
|
||||
}
|
||||
if inserted {
|
||||
change.set_file_resolver(Arc::new(self.path_map.clone()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue