diff options
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 15 | ||||
-rw-r--r-- | editors/code/src/client.ts | 10 |
3 files changed, 18 insertions, 9 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 0e592ac1b..658a50d15 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -73,6 +73,7 @@ pub(crate) struct GlobalState { | |||
73 | pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>, | 73 | pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>, |
74 | pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>, | 74 | pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>, |
75 | pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, | 75 | pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, |
76 | pub(crate) shutdown_requested: bool, | ||
76 | pub(crate) status: Status, | 77 | pub(crate) status: Status, |
77 | pub(crate) source_root_config: SourceRootConfig, | 78 | pub(crate) source_root_config: SourceRootConfig, |
78 | pub(crate) proc_macro_client: ProcMacroClient, | 79 | pub(crate) proc_macro_client: ProcMacroClient, |
@@ -124,6 +125,7 @@ impl GlobalState { | |||
124 | mem_docs: FxHashMap::default(), | 125 | mem_docs: FxHashMap::default(), |
125 | semantic_tokens_cache: Arc::new(Default::default()), | 126 | semantic_tokens_cache: Arc::new(Default::default()), |
126 | vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))), | 127 | vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))), |
128 | shutdown_requested: false, | ||
127 | status: Status::default(), | 129 | status: Status::default(), |
128 | source_root_config: SourceRootConfig::default(), | 130 | source_root_config: SourceRootConfig::default(), |
129 | proc_macro_client: ProcMacroClient::dummy(), | 131 | proc_macro_client: ProcMacroClient::dummy(), |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 0ac6434dd..e6cf46df2 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -337,6 +337,16 @@ impl GlobalState { | |||
337 | fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> { | 337 | fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> { |
338 | self.register_request(&req, request_received); | 338 | self.register_request(&req, request_received); |
339 | 339 | ||
340 | if self.shutdown_requested { | ||
341 | self.respond(Response::new_err( | ||
342 | req.id, | ||
343 | lsp_server::ErrorCode::InvalidRequest as i32, | ||
344 | "Shutdown already requested.".to_owned(), | ||
345 | )); | ||
346 | |||
347 | return Ok(()); | ||
348 | } | ||
349 | |||
340 | if self.status == Status::Loading && req.method != "shutdown" { | 350 | if self.status == Status::Loading && req.method != "shutdown" { |
341 | self.respond(lsp_server::Response::new_err( | 351 | self.respond(lsp_server::Response::new_err( |
342 | req.id, | 352 | req.id, |
@@ -351,7 +361,10 @@ impl GlobalState { | |||
351 | .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.fetch_workspaces()))? | 361 | .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.fetch_workspaces()))? |
352 | .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))? | 362 | .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))? |
353 | .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))? | 363 | .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))? |
354 | .on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))? | 364 | .on_sync::<lsp_types::request::Shutdown>(|s, ()| { |
365 | s.shutdown_requested = true; | ||
366 | Ok(()) | ||
367 | })? | ||
355 | .on_sync::<lsp_types::request::SelectionRangeRequest>(|s, p| { | 368 | .on_sync::<lsp_types::request::SelectionRangeRequest>(|s, p| { |
356 | handlers::handle_selection_range(s.snapshot(), p) | 369 | handlers::handle_selection_range(s.snapshot(), p) |
357 | })? | 370 | })? |
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 18948cb3c..f5db55b8c 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts | |||
@@ -4,7 +4,7 @@ import * as ra from '../src/lsp_ext'; | |||
4 | import * as Is from 'vscode-languageclient/lib/utils/is'; | 4 | import * as Is from 'vscode-languageclient/lib/utils/is'; |
5 | 5 | ||
6 | import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed'; | 6 | import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed'; |
7 | import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed'; | 7 | import { SemanticTokensFeature } from 'vscode-languageclient/lib/semanticTokens.proposed'; |
8 | import { assert } from './util'; | 8 | import { assert } from './util'; |
9 | 9 | ||
10 | function renderCommand(cmd: ra.CommandLink) { | 10 | function renderCommand(cmd: ra.CommandLink) { |
@@ -44,12 +44,6 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient | |||
44 | diagnosticCollectionName: "rustc", | 44 | diagnosticCollectionName: "rustc", |
45 | traceOutputChannel, | 45 | traceOutputChannel, |
46 | middleware: { | 46 | middleware: { |
47 | // Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576 | ||
48 | async provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken, next: DocumentSemanticsTokensSignature) { | ||
49 | const res = await next(document, token); | ||
50 | if (res === undefined) throw new Error('busy'); | ||
51 | return res; | ||
52 | }, | ||
53 | async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, _next: lc.ProvideHoverSignature) { | 47 | async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, _next: lc.ProvideHoverSignature) { |
54 | return client.sendRequest(lc.HoverRequest.type, client.code2ProtocolConverter.asTextDocumentPositionParams(document, position), token).then( | 48 | return client.sendRequest(lc.HoverRequest.type, client.code2ProtocolConverter.asTextDocumentPositionParams(document, position), token).then( |
55 | (result) => { | 49 | (result) => { |
@@ -135,7 +129,7 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient | |||
135 | ); | 129 | ); |
136 | } | 130 | } |
137 | 131 | ||
138 | } as any | 132 | } |
139 | }; | 133 | }; |
140 | 134 | ||
141 | const client = new lc.LanguageClient( | 135 | const client = new lc.LanguageClient( |