mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Merge #1334
1334: check for cancellation during macro expansion r=matklad a=matklad closes #1331 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
b2bf41b2ba
4 changed files with 87 additions and 1 deletions
|
@ -61,6 +61,7 @@ impl HirFileId {
|
||||||
db: &impl DefDatabase,
|
db: &impl DefDatabase,
|
||||||
file_id: HirFileId,
|
file_id: HirFileId,
|
||||||
) -> Option<TreeArc<SyntaxNode>> {
|
) -> Option<TreeArc<SyntaxNode>> {
|
||||||
|
db.check_canceled();
|
||||||
let _p = profile("parse_or_expand_query");
|
let _p = profile("parse_or_expand_query");
|
||||||
match file_id.0 {
|
match file_id.0 {
|
||||||
HirFileIdRepr::File(file_id) => Some(db.parse(file_id).syntax().to_owned()),
|
HirFileIdRepr::File(file_id) => Some(db.parse(file_id).syntax().to_owned()),
|
||||||
|
|
|
@ -156,6 +156,10 @@ impl RootDatabase {
|
||||||
pub(crate) fn apply_change(&mut self, change: AnalysisChange) {
|
pub(crate) fn apply_change(&mut self, change: AnalysisChange) {
|
||||||
let _p = profile("RootDatabase::apply_change");
|
let _p = profile("RootDatabase::apply_change");
|
||||||
log::info!("apply_change {:?}", change);
|
log::info!("apply_change {:?}", change);
|
||||||
|
{
|
||||||
|
let _p = profile("RootDatabase::apply_change/cancellation");
|
||||||
|
self.salsa_runtime().next_revision();
|
||||||
|
}
|
||||||
if !change.new_roots.is_empty() {
|
if !change.new_roots.is_empty() {
|
||||||
let mut local_roots = Vec::clone(&self.local_roots());
|
let mut local_roots = Vec::clone(&self.local_roots());
|
||||||
for (root_id, is_local) in change.new_roots {
|
for (root_id, is_local) in change.new_roots {
|
||||||
|
|
|
@ -6,10 +6,11 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
CodeActionContext, DocumentFormattingParams, FormattingOptions, Position, Range,
|
CodeActionContext, DocumentFormattingParams, FormattingOptions, Position, Range, DidOpenTextDocumentParams, TextDocumentItem, TextDocumentPositionParams
|
||||||
};
|
};
|
||||||
use ra_lsp_server::req::{
|
use ra_lsp_server::req::{
|
||||||
CodeActionParams, CodeActionRequest, Formatting, Runnables, RunnablesParams, CompletionParams, Completion,
|
CodeActionParams, CodeActionRequest, Formatting, Runnables, RunnablesParams, CompletionParams, Completion,
|
||||||
|
DidOpenTextDocument, OnEnter,
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
@ -17,6 +18,7 @@ use tempfile::TempDir;
|
||||||
use crate::support::{project, Project};
|
use crate::support::{project, Project};
|
||||||
|
|
||||||
const LOG: &'static str = "";
|
const LOG: &'static str = "";
|
||||||
|
const PROFILE: &'static str = "*@3>100";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_items_from_standard_library() {
|
fn completes_items_from_standard_library() {
|
||||||
|
@ -341,3 +343,68 @@ fn main() {{}}
|
||||||
json!([]),
|
json!([]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn diagnostics_dont_block_typing() {
|
||||||
|
let librs: String = (0..10).map(|i| format!("mod m{};", i)).collect();
|
||||||
|
let libs: String = (0..10).map(|i| format!("//- src/m{}.rs\nfn foo() {{}}\n\n", i)).collect();
|
||||||
|
let server = project(&format!(
|
||||||
|
r#"
|
||||||
|
//- Cargo.toml
|
||||||
|
[package]
|
||||||
|
name = "foo"
|
||||||
|
version = "0.0.0"
|
||||||
|
|
||||||
|
//- src/lib.rs
|
||||||
|
{}
|
||||||
|
|
||||||
|
{}
|
||||||
|
|
||||||
|
fn main() {{}}
|
||||||
|
"#,
|
||||||
|
librs, libs
|
||||||
|
));
|
||||||
|
server.wait_until_workspace_is_loaded();
|
||||||
|
for i in 0..10 {
|
||||||
|
server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams {
|
||||||
|
text_document: TextDocumentItem {
|
||||||
|
uri: server.doc_id(&format!("src/m{}.rs", i)).uri,
|
||||||
|
language_id: "rust".to_string(),
|
||||||
|
version: 0,
|
||||||
|
text: "/// Docs\nfn foo() {}".to_string(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let start = std::time::Instant::now();
|
||||||
|
server.request::<OnEnter>(
|
||||||
|
TextDocumentPositionParams {
|
||||||
|
text_document: server.doc_id("src/m0.rs"),
|
||||||
|
position: Position { line: 0, character: 5 },
|
||||||
|
},
|
||||||
|
json!({
|
||||||
|
"cursorPosition": {
|
||||||
|
"position": { "character": 4, "line": 1 },
|
||||||
|
"textDocument": { "uri": "file:///[..]src/m0.rs" }
|
||||||
|
},
|
||||||
|
"label": "on enter",
|
||||||
|
"workspaceEdit": {
|
||||||
|
"documentChanges": [
|
||||||
|
{
|
||||||
|
"edits": [
|
||||||
|
{
|
||||||
|
"newText": "\n/// ",
|
||||||
|
"range": {
|
||||||
|
"end": { "character": 5, "line": 0 },
|
||||||
|
"start": { "character": 5, "line": 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"textDocument": { "uri": "file:///[..]src/m0.rs", "version": null }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
let elapsed = start.elapsed();
|
||||||
|
assert!(elapsed.as_millis() < 2000, "typing enter took {:?}", elapsed);
|
||||||
|
}
|
||||||
|
|
|
@ -52,6 +52,11 @@ impl<'a> Project<'a> {
|
||||||
static INIT: Once = Once::new();
|
static INIT: Once = Once::new();
|
||||||
INIT.call_once(|| {
|
INIT.call_once(|| {
|
||||||
let _ = Logger::with_env_or_str(crate::LOG).start().unwrap();
|
let _ = Logger::with_env_or_str(crate::LOG).start().unwrap();
|
||||||
|
ra_prof::set_filter(if crate::PROFILE.is_empty() {
|
||||||
|
ra_prof::Filter::disabled()
|
||||||
|
} else {
|
||||||
|
ra_prof::Filter::from_spec(&crate::PROFILE)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut paths = vec![];
|
let mut paths = vec![];
|
||||||
|
@ -121,6 +126,15 @@ impl Server {
|
||||||
TextDocumentIdentifier { uri: Url::from_file_path(path).unwrap() }
|
TextDocumentIdentifier { uri: Url::from_file_path(path).unwrap() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn notification<N>(&self, params: N::Params)
|
||||||
|
where
|
||||||
|
N: Notification,
|
||||||
|
N::Params: Serialize,
|
||||||
|
{
|
||||||
|
let r = RawNotification::new::<N>(¶ms);
|
||||||
|
self.send_notification(r)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn request<R>(&self, params: R::Params, expected_resp: Value)
|
pub fn request<R>(&self, params: R::Params, expected_resp: Value)
|
||||||
where
|
where
|
||||||
R: Request,
|
R: Request,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue